cancel
Showing results for 
Search instead for 
Did you mean: 

Inserting data into database doesnt happen.

N/A

Inserting data into database doesnt happen.

Hi, i have a page that gets user input from a form and then attempts to write it into the database. I echo the sql and it looks perfectly fine, but it doesnt enter it into the database. Any help would be greatly appreciated.

This is my SQL statement:

insert into Error (Error_Code, Product_Name, Error_Problem, Operating_System) values (4 4455677, 'Virtual Keyboard V1.0', 'Test to try web input', 'Windows 2000 Professional');Failed Query of insert into Error (Error_Code, Product_Name, Error_Problem, Operating_System) values (44455677, 'Virtual Keyboard V1.0', 'Test to try web input', 'Windows 2000 Professional');

this is my code

$db_host = "humbug";
$username = "srscaife";
$password = "**************";
$DB_name = "srscaife_f9";

// The variables to hold the form data

$Error_Code = $_POST[Error_Code];
$Product_Name = $_POST[selSoftware];
$Error_Problem = $_POST[Error_Problem];
$OS = $_POST[OS];

$chan = mysql_connect ($db_host, $username, $password)
or die("Connection Failure to Database");

mysql_select_db ($DB_name, $chan) or die ($DB_name . " Database not found." . $username);


$mainsection="Error"; //The name of the table where the lists of errors are stored

$query1="insert into " . $mainsection . " (Error_Code, Product_Name, Error_Problem, Operating_System) values (" . $Error_Code . ", '" . $Product_Name . "', '" . $Error_Problem . "', '" . $OS . "');";
echo "$query1";
mysql_db_query($DB_name, $query1) or die("Failed Query of " . $query1);

echo "<table align='center' width='90%' border='1'>";
echo "<tr><td colspan='4' align='center'>You have entered the following into the database</td></tr>";
echo "<tr>";
echo "<td><b>Error Code</b></td><td><b>Product Name</b></td><td><b>Error Problem</b></td><td><b>Operating System</b></td>";
echo "</tr>";
echo "<tr><td>$Error_Code</td><td>$Product_Name</td><td>$Error_Problem</td><td>$OS</td>";

mysql_close($chan);

?>

[Moderator's note (by csogilvie): Removed mySQL Password from the post to the fourm]
1 REPLY
N/A

Inserting data into database doesnt happen.

Why don't you try echoing mysql_error when theres an error - that way you will see what the problem is.