Saving to a MySQL database - Post ID...

User 2081066 Photo


Registered User
2 posts

Issue with mySQL on XAMPP setup I let the form create the database and table the first record writes to the database everything is perfect. When a second form is submitted the form goes blank and nothing is written to the database. I check the fb_error.log this is the information.

Sat, 22 Nov 2014 15:34:32 +0000: Failed to execute query on table: Profile(CREATE TABLE `Profile`(_rowid_ int(11) NOT NULL AUTO_INCREMENT,`req800nub` varchar(255) NOT NULL DEFAULT '',`name` varchar(255) NOT NULL DEFAULT '',`phone` varchar(255) NOT NULL DEFAULT '',`email39` varchar(255) NOT NULL DEFAULT '',`lastname` varchar(255) NOT NULL DEFAULT '',`firstname` varchar(255) NOT NULL DEFAULT '',`department` varchar(255) NOT NULL DEFAULT '',`emp_800` varchar(255) NOT NULL DEFAULT '',`transfer` varchar(255) NOT NULL DEFAULT '',`startdate` date NOT NULL DEFAULT '0000-00-00',`jobtitle` varchar(255) NOT NULL DEFAULT '',`badgenub` varchar(255) NOT NULL DEFAULT '',`setuplike` varchar(255) NOT NULL DEFAULT '',`system` varchar(255) NOT NULL DEFAULT '',`internet` text(10000) NOT NULL DEFAULT '',`other` text(10000) NOT NULL DEFAULT '',`completed` varchar(255) NOT NULL DEFAULT '',`completed2` varchar(255) NOT NULL DEFAULT '',`_submitted_` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',`_fromaddress_` varchar(128) NOT NULL DEFAULT '0.0.0',`_flags_` int(11) NOT NULL DEFAULT '0',`_transactid_` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY ( _rowid_ ) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 [0] 42S01 [1] 1050 [2] Table 'profile' already exists
Sat, 22 Nov 2014 15:34:32 +0000: Failed to obtain lock on: C:/xampp/htdocs/profile/profile3/storage/csv/Request.csv
Sat, 22 Nov 2014 15:34:35 +0000: Couldn't open or read: C:/xampp/htdocs/profile/profile3.html
Sat, 22 Nov 2014 15:34:35 +0000: Failed to parse HTML form.

The scrip is trying to create the table a 2nd time after it created the record with the first entry. Any suggestions and yes I have deleted the database and ran again the first record is written but the second fails with an error.

User 450017 Photo


Registered User
4 posts

How do I use the form to update existing records in the MySQL database table? I am using this behind a user login/password so I know exactly which record needs to be updated, just not sure how I pass my key field to the form. Has anyone done this?
User 187934 Photo


Senior Advisor
20,181 posts
Online Now

You need to write your own script to handle updating existing data.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 450017 Photo


Registered User
4 posts

OK, and so how do I find out how to "write my own script"? Thanks
User 187934 Photo


Senior Advisor
20,181 posts
Online Now

You can Google it but here's one example covering the pdo mysql.
http://wiki.hashphp.org/PDO_Tutorial_fo … Developers
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 450017 Photo


Registered User
4 posts

Does anyone out there have PHP experience in modifying Coffee Cup scripts so that I can use the Web Form Builder to maintain existing MySQL records (as opposed to just simply adding new records)?
User 187934 Photo


Senior Advisor
20,181 posts
Online Now

I have found it easier to write my own scripts to do the updating. How many fields we talking.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 450017 Photo


Registered User
4 posts

Thanks for any input on this matter, Eric! I only need to pass 1 key field to retrieve and update a record (all records already exist, so the form wont be needed to create a new record at all). The form itself has 22 fields that can be modified.
User 114319 Photo


Registered User
7 posts

It would be nice to have a watch over your shoulder video tutorial by anyone who has had success at this.
Any Volunteers?
Thanks
User 187934 Photo


Senior Advisor
20,181 posts
Online Now

The easiest way to accomplish this without altering any of the form files would be to use the custom redirect option and use the $_SESSION variables that would still be active. All of the variables are retrievable by grabbing the $_SESSION['post'].
Small example
This would be your custom redirect page
mycustom-redirect.php
<?php
session_start();

// entire array of variables
$post = $_SESSION['post'];
//Grabbing only the input name first_name if it' exists
if(isset($post['first_name'])){

// do your mysql pdo insert here

// set a session variable
$_SESSION['data'] = $post['first_name'];
// redirect to another page
header('Location: http://mydomain.com/welcome-to-my-site.html');
exit();
}
?>

On the welcome-to-my-site-html place this where you want to echo their first name
<?php if(isset($_SESSION['data'])){
echo $_SESSION['data'];
}?>

On the welcome-to-my-site-html place this at the bottom to unset the session var.
<?php unset($_SESSION['data']); ?>

The welcome-to-my-site-html page code.
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My Site</title>

</head>
<body>
<h1>Welcome <?php if(isset($_SESSION['data'])){
echo $_SESSION['data'];
}?></h1>
</body>
</html>
<?php unset($_SESSION['data']); ?>
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.