samoi Posted December 1, 2008 Share Posted December 1, 2008 I try to let this script work, but it doesn't what's its problem? <?php error_reporting(E_ALL & E_NOTICE); require_once('config.php'); if(!$_POST) { header('Location: insert.php'); } else { $event = clean($_POST['event']); $date = clean($_POST['date']); $insert = "INSERT INTO table (event, date) VALUES ('$event', '$date')"; $insertSQL = mysql_query($insert); echo 'The new event has been submitted <br> hit <a href="index.php"> this link </a> to view them'; } function clean($str) { return mysql_escape_string($str); } ?> Link to comment https://forums.phpfreaks.com/topic/135064-solved-this-code-drives-me-crazy-inserting-values-to-the-mysql-need-help/ Share on other sites More sharing options...
awpti Posted December 1, 2008 Share Posted December 1, 2008 I don't know! What's the error? A little information goes a long way. Link to comment https://forums.phpfreaks.com/topic/135064-solved-this-code-drives-me-crazy-inserting-values-to-the-mysql-need-help/#findComment-703486 Share on other sites More sharing options...
samoi Posted December 1, 2008 Author Share Posted December 1, 2008 it display no errors, but it doesn't insert them in the database! Strange, right? Link to comment https://forums.phpfreaks.com/topic/135064-solved-this-code-drives-me-crazy-inserting-values-to-the-mysql-need-help/#findComment-703487 Share on other sites More sharing options...
awpti Posted December 1, 2008 Share Posted December 1, 2008 Not necessarily. Check your error logs (error_log if on an Apache server) Link to comment https://forums.phpfreaks.com/topic/135064-solved-this-code-drives-me-crazy-inserting-values-to-the-mysql-need-help/#findComment-703489 Share on other sites More sharing options...
DarkWater Posted December 2, 2008 Share Posted December 2, 2008 You don't do any error checking on your query results. Check your query by changing the line to read: $insertSQL = mysql_query($insert) or die(mysql_error()); You should run error checks on every query. Link to comment https://forums.phpfreaks.com/topic/135064-solved-this-code-drives-me-crazy-inserting-values-to-the-mysql-need-help/#findComment-703540 Share on other sites More sharing options...
samoi Posted December 2, 2008 Author Share Posted December 2, 2008 You don't do any error checking on your query results. Check your query by changing the line to read: $insertSQL = mysql_query($insert) or die(mysql_error()); You should run error checks on every query. I've got You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table (event, date) VALUES ('ENG 102 delever', '12/05/2008')' at line 1 Link to comment https://forums.phpfreaks.com/topic/135064-solved-this-code-drives-me-crazy-inserting-values-to-the-mysql-need-help/#findComment-703570 Share on other sites More sharing options...
samoi Posted December 2, 2008 Author Share Posted December 2, 2008 Oh, I found that I cannot name a table `table` , not allowed in Mysql !! Thank you guys though Link to comment https://forums.phpfreaks.com/topic/135064-solved-this-code-drives-me-crazy-inserting-values-to-the-mysql-need-help/#findComment-703573 Share on other sites More sharing options...
revraz Posted December 2, 2008 Share Posted December 2, 2008 Because you can't use the word TABLE as your tablename. Rename it (or if you want to keep it, use `backtics`) Link to comment https://forums.phpfreaks.com/topic/135064-solved-this-code-drives-me-crazy-inserting-values-to-the-mysql-need-help/#findComment-703574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.