phppup Posted May 10, 2018 Share Posted May 10, 2018 My form is not posting data to table. I removed all validation to simplification purposes, yet onSubmit only provides a blank page. I have used a script and verified connectivity to the db, and feel as if there is something wrong with my INSERT statement. Here is my code: my_form.php <table width="300" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td><form name="form1" method="POST" action="insert_file.php"> <table width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td colspan="3"><strong>Insert Data Into mySQL Database </strong></td> </tr> <tr> <td width="71">Name</td> <td width="6">:</td> <td width="301"><input name="name" type="text" id="name"></td> </tr> <tr> <td>Lastname</td> <td>:</td> <td><input name="lastname" type="text" id="lastname"></td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="email" type="text" id="email"></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form> </td> </tr> </table> insert_file.php <?php $host="localhost"; // Host name $username="provided"; // Mysql username $password="provided"; // Mysql password $db_name="provided"; // Database name $tbl_name="provided"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $name=$_POST['name']; $lastname=$_POST['lastname']; $email=$_POST['email']; // Insert data into mysql $sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; } else { echo "ERROR"; } // close connection mysql_close(); ?> Do you see something that I've missed?? Quote Link to comment Share on other sites More sharing options...
requinix Posted May 10, 2018 Share Posted May 10, 2018 Find your php.ini and set error_reporting = -1 display_errors = onThen restart your web server and try the form again. Quote Link to comment Share on other sites More sharing options...
phppup Posted May 10, 2018 Author Share Posted May 10, 2018 I added this immedately after my <? but got nothing. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 10, 2018 Share Posted May 10, 2018 Not the same thing. Gotta put it in php.ini. Quote Link to comment Share on other sites More sharing options...
phppup Posted May 11, 2018 Author Share Posted May 11, 2018 I'm lost. Please be more specific with detailed instructions, if you would. Quote Link to comment Share on other sites More sharing options...
phppup Posted May 11, 2018 Author Share Posted May 11, 2018 Note: My hosting service has said the server is fine and the problem is within my code. Does anyone see an issue or have any suggestions? Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted May 11, 2018 Share Posted May 11, 2018 I'm lost. Please be more specific with detailed instructions, if you would. http://php.net/manual/en/configuration.file.php This is where you change how you wish PHP to react to various events. requinix (and so do I) recommends when developing that you set it up to blatantly tell you why you are getting errors. Some of these settings must be set up in this file, yet others can also be set up on the fly. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 11, 2018 Share Posted May 11, 2018 Note: My hosting service has said the server is fine and the problem is within my code. Does anyone see an issue or have any suggestions?Besides what I said? Not yet. Your hosting provider should have given you some way to change PHP settings that doesn't involve code. Maybe it's with a .htaccess. Maybe it is in fact a php.ini file. Maybe it's something else. Find it and make the changes I said. Quote Link to comment Share on other sites More sharing options...
dodgeitorelse3 Posted May 11, 2018 Share Posted May 11, 2018 should mysql_connect really have quotes around variables? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 11, 2018 Share Posted May 11, 2018 Should the OP even be USING the MySQL interface to his db? That said - does the content of '$tbl_name' contain a space char? YOu didn't wrap that in "" so that may be a problem. And if you are going to use the MySQL functions, look up how to use the MySQL_error (?) function when trapping the results of your query call. Read The Manual - it is a great way to understand what you are doing and learn. Quote Link to comment Share on other sites More sharing options...
irkevin Posted May 11, 2018 Share Posted May 11, 2018 I believe it must be a typo somewhere in the declared variables. Either way, it will be hard to help without actually having a proper error message being displayed. That being said, add the code below just after the opening PHP tag, and try submitting the form again error_reporting(E_ALL); ini_set('display_errors', '1'); Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 11, 2018 Share Posted May 11, 2018 Do what Irkevin says to turn on error checking since there doesn't seem to be any fatal errors stopping your script. Then add some echo statements to display your script's progress. Show the input values; show the query statement also and be sure it is EXACTLY what you are expecting. Quote Link to comment Share on other sites More sharing options...
phppup Posted May 12, 2018 Author Share Posted May 12, 2018 Got it working. Thanks for all the support. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.