Jump to content

FORM not posting - help me, please

Recommended Posts

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:



<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<td><form name="form1" method="POST" action="insert_file.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<td colspan="3"><strong>Insert Data Into mySQL Database </strong></td>
<td width="71">Name</td>
<td width="6">:</td>
<td width="301"><input name="name" type="text" id="name"></td>
<td><input name="lastname" type="text" id="lastname"></td>
<td><input name="email" type="text" id="email"></td>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>



$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

// Insert data into mysql
$sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";

// if successfully insert data into database, displays message "Successful".
echo "Successful";


else {
echo "ERROR";

// close connection


Do you see something that I've missed??


Link to post
Share on other sites

I'm lost. Please be more specific with detailed instructions, if you would.



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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

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

ini_set('display_errors', '1');
Link to post
Share on other sites

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.

Link to post
Share on other sites
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.