My data is not being sent to database?

My code is below, the data just isnt being sent, I really do not know why, there is no errors, just … doesnt send it. Help me out please.

[php]

<?php error_reporting(1); $mysql_server = 'localhost'; $mysql_username = 'root'; $mysql_password = 'root'; $mysql_database = 'ce1002'; $mysql_table = 'orders'; $success_page = 'YESSS'; $error_message = 'NOOOO'; if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['form_name'] == 'signupform') { $fullname = $_POST['fullname']; $matriculation = $_POST['matriculation']; $bread = $_POST['bread']; $chips = $_POST['chips']; $cakes = $_POST['cakes']; $cars = $_POST['cars']; if (empty($error_message)) { $db = mysql_connect($mysql_server, $mysql_username, $mysql_password); if (!$db) { die('Failed to connect to database server!
'.mysql_error()); } mysql_select_db($mysql_database, $db) or die('Failed to select database
'.mysql_error()); $sql = "SELECT fullname FROM ".$mysql_table." WHERE fullname = '".$fullname."'"; $result = mysql_query($sql, $db); } if ($data = mysql_fetch_array($result)) { $error_message = 'Username already used. Please select another username.'; } if (empty($error_message)) { $fullname = mysql_real_escape_string($fullname); $sql = "INSERT `".$mysql_table."` (`matriculation`, `bread`, `chips`, 'cakes', 'cars') VALUES ('$matriculation', '$bread', '$chips', '$cakes', '$cars')"; $result = mysql_query($sql, $db); mysql_close($db); exit; } } ?>[/php]

I do see problems with your insert query. You are missing ‘INTO’ and you have some single quotes on ‘cakes’ and ‘cars’ that should be backticks cakes, cars

[php]
$sql = “INSERT INTO ".$mysql_table." (matriculation, bread, chips, cakes, cars) VALUES (’$matriculation’, ‘$bread’, ‘$chips’, ‘$cakes’, ‘$cars’)”;
[/php]

Also, you have error reporting on mysql_connect and mysql_select_db but why not use it on mysql_query as well?

[php]$result = mysql_query($sql, $db)or die(mysql_error());[/php]

Thanks M@tt, i have a new problem though, hope u can help.

Appreciate the help here, its tough starting computing.

i have a new problem though, hope u can help.

what is that new problem?

let us know we might be able to help.

I made a new topic about it here, Im still facing a small problem on it:

http://www.phphelp.com/forum/index.php?topic=18584.0

Sponsor our Newsletter | Privacy Policy | Terms of Service