Jump to content

FORM not posting - help me, please


phppup

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:

 

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??

 

Link to comment
Share on other sites

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.

Link to comment
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 comment
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 comment
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

error_reporting(E_ALL);
ini_set('display_errors', '1');
Link to comment
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 comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.