Jump to content

Re: MySQL Database – NOT SAVING USER DETAILS, AFTER FILLING A WEB-FORM


codex...

Recommended Posts

Hi Guys,

 

After a user fills out a form on a website, and clicks the submit button, the user details such as name, address and telephone numbers, should be sent to and saved on the database, but on checking the database - nothing at all is saved on the database.

 

Any possible suggestions, please help.

 

I can copy and paste the HTML Form code and MySQL if you want.

 

Thanks,

 

Codex...

Link to comment
Share on other sites

Hi,Thanks for your prompt reply, I have been a bit busy doing other stuff, sorry for my late reply.“A reminder of my main problem – On clicking the submit button, after a web-form has been filled looks O.K, but on checking the MySQL database, there is no data saved inside the database.”THIS IS THE HTML CODE I HAVE USED.<?php{  echo "<form name='registerform' method='post' action='insert.php' enctype='application/x-www-form-urlencoded'>          <p>First name: *</p>      <p><label for='firstname'></label><input type='text' name='firstname' maxlength='35' size='50' tabindex='1' /></p>          <p>Last name: *</p>      <p><label for='lastname'></label><input type='text' name='lastname' maxlength='35' size='50' tabindex='2' /></p>           <p>Email address: *</p>      <p><label for='email address'></label><input type='text' name='email' maxlength='35' size='50' tabindex='3' /></p>          <p>Passsword: *</p>      <p><label for='password'></label><input type='text' name='password' maxlength='35' size='50' tabindex='4' /></p>           <p>Confirm password: *</p>      <p><label for='confirmpassword'></label><input type='password' name='confirmpassword' id="confirmpassword" maxlength='35' size='50' tabindex='5' /></p>            <p><input type='submit' name="submit" value='Submit' /></p></form>”;}?>THIS IS THE MySQL CODE I HAVE USED. <?php$mysqli = new mysqli("host name", "xxxxxxxx", "xxxxxxxx", "xxxxxxxx");if ($mysqii->connect_error) {die('Connect Error (' . $mysqli->connect_errno . ') '  //CHECK CONNECTION.   . $mysqli->connect_error);}mysql_query("INSERT INTO ws_sessions (user_name, first_name, last_name, email, password, confirm_password) VALUES('$userName', '$firstName', '$lastName', '$email', '$password', '$confirmPassword')");$mysqli->close();?>I hope this is helpful, please feel free to ask me any questions.

Thanks!

Link to comment
Share on other sites

You're not getting the data from the form. The submitted data will be in $_POST. You also need to change your database code to use prepared statements instead of trying to directly put values in the SQL query.http://www.w3schools.com/php/php_forms.asphttp://www.w3schools.com/php/php_mysql_prepared_statements.asp

Link to comment
Share on other sites

Hi,

 

Thanks for your pointers, the links you sent me, they were very helpful. I have been trying out stuff changing my database code, using prepared statements as you’ve advised, but I get this error message, when I run the code.

 

After filling a web-form on clicking the submit button, I get this

 

Fatal error: Call to a member function bind_param() on a non-object in /homepages/18/d440109193/htdocs/welcome.php on line 22

 

I tried to fix the problem, but I keep getting the same error message, any suggestions to fix this error.

SEE BELOW THE CURRENT CODE.

<?phpsession_start();spl_autoload_extensions(".php");$servername = "localhost";$username = "username";$password = "password";$dbname = "myDB";// CREATE CONNECTION - LINK_IDENTIFIER, MYSQL CONNECTION$conn = new mysqli("xxxxxxxx", "xxxxxxxx", "xxxxxxxx", "xxxxxxxx");	// CHECK CONNECTIONif ($mysqli->connect_error) {	die('Connect Error (' . $mysqli->connect_errno . ') '	. $mysqli->connect_error);}//PREPARE AND BIND$stmt = $conn->prepare("INSERT INTO Users (username, firstname, lastname, email, password, confirmpassword) VALUES(?, ?, ?, ?, ?, ?)");$stmt->bind_param("ssssss", $username, $firstname, $lastname, $email, $password, $confirmpassword);//SET PARAMETERS AND EXECUTE$username = "";$firstname = "";$lastname = "";$email = "";$password = "";$confirmpassword = "";$stmt->execute();echo "New records created successfully";$stmt->close();$conn->close();?>

any suggestions to fix this,

 

Thanks!

 

 

 

 

Link to comment
Share on other sites

Hi Guys,

 

I appreciate your help and replies, please help with MySQL problem, my connection to the database is now O.K which I did not get previously, the error I get now on clicking the submit button of a web-form is as follows:

 

Fatal error: Call to a member function bind_param() on a non-object in /homepages/18/d440109193/htdocs/welcome.php on line 22

 

any suggestions or help is welcome, please feel free to ask me any questions,

 

Thanks!

Link to comment
Share on other sites

It sounds like there's a MySQL error.

You should check what it is by doing error checking:

$stmt = $conn->prepare("INSERT INTO Users (username, firstname, lastname, email, password, confirmpassword) VALUES(?, ?, ?, ?, ?, ?)");if(!$stmt) {    // Something wrong happened    echo 'MySQL error: ' . $conn->error;}
Link to comment
Share on other sites

Hi Guys, thanks for your help, I have tried this out, and this is the message I got, after I did the error checking...

 

 

MySQL error:

 

It did not really tell what the error is, I ran this code a few times and I got the same reply, any possible suggestions are welcome...

 

Thanx!

Link to comment
Share on other sites

Hi Guys, thanks once again for your efforts, mysql stuff is interesting - connection to my host server is now the problem, sometimes I get connected and sometimes I don't, there should be a solution to this I think... am not sure

 

See the browser output I get below:

 

Warning: Connect Error (2002) Can't connect to local MySQL server through socket '/tmp/mysqld.sock' (2)

 

this is the 'code' I am using now to connect - $mysqli = new mysqli("servername", "username", "password", "dbname");

 

your suggestions are welcome...

 

Thanx!

Link to comment
Share on other sites

I assume that you substituted the values "servername", "username", "password", and "dbname" with your database server information.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...