aznjay Posted September 15, 2008 Share Posted September 15, 2008 $msg = $_POST['message']; $date = $_POST['date']; $time = $_POST['time']; $head = $_POST['title']; $descri = $_POST['desp']; $whbase = $_POST['base']; $query = "INSERT INTO '$whbase' (title, time, date, desp, article) VALUES ('$head', '$time', '$date', '$descri', '$msg')"; mysql_query($query) or die('Error, insert query failed'); Is there something wrong with this? Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/ Share on other sites More sharing options...
genericnumber1 Posted September 15, 2008 Share Posted September 15, 2008 change 'Error, insert query failed' to mysql_error() I spot your error! do you? edit: I'll play nice, try removing the quotes around the table name. Also, your script is vulnerable to sql injection Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/#findComment-641733 Share on other sites More sharing options...
Garethp Posted September 15, 2008 Share Posted September 15, 2008 Looks alright, is it giving you any trouble? Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/#findComment-641735 Share on other sites More sharing options...
aznjay Posted September 15, 2008 Author Share Posted September 15, 2008 This is what i 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 ''' (title, time, date, desp, article) VALUES ('', '', '', '', '')' at line 1' I don't know how to fix it Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/#findComment-641739 Share on other sites More sharing options...
genericnumber1 Posted September 15, 2008 Share Posted September 15, 2008 but backticks around your field names, because ones like date and time are mysql functions. INSERT INTO $whbase (`title`, `time`, `date`, `desp`, `article`) VALUES ('$head', '$time', '$date', '$descri', '$msg') Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/#findComment-641740 Share on other sites More sharing options...
aznjay Posted September 15, 2008 Author Share Posted September 15, 2008 <? include 'database.php'; $msg = $_POST['message']; $date = $_POST['date']; $time = $_POST['time']; $head = $_POST['title']; $descri = $_POST['desp']; $whbase = $_POST['base']; $query = "INSERT INTO "'$whbase'" (title, time, date, desp, article) VALUES ('$head', '$time', '$date', '$descri', '$msg')"; mysql_query($query) or die(mysql_error()); ?> Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/jayjay/public_html/phpentrytut.php on line 10 That is what i got...can somebody fix this please..i'm a noob.. Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/#findComment-641741 Share on other sites More sharing options...
Garethp Posted September 15, 2008 Share Posted September 15, 2008 I dunno if this will help, but use this instead mysql_query("INSERT INTO $whbase (title, time, date, desp, article) VALUES ('$head', '$time', '$date', '$descri', '$msg')") or die('Error, insert query failed'); Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/#findComment-641742 Share on other sites More sharing options...
aznjay Posted September 15, 2008 Author Share Posted September 15, 2008 but backticks around your field names, because ones like date and time are mysql functions. INSERT INTO $whbase (`title`, `time`, `date`, `desp`, `article`) VALUES ('$head', '$time', '$date', '$descri', '$msg') THERE is no problem with that I can gaurantee you that..the one i'm having problem to is the $whbase Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/#findComment-641744 Share on other sites More sharing options...
genericnumber1 Posted September 15, 2008 Share Posted September 15, 2008 but backticks around your field names, because ones like date and time are mysql functions. INSERT INTO $whbase (`title`, `time`, `date`, `desp`, `article`) VALUES ('$head', '$time', '$date', '$descri', '$msg') THERE is no problem with that I can gaurantee you that..the one i'm having problem to is the $whbase I guarantee you. do $query = "INSERT INTO $whbase (`title`, `time`, `date`, `desp`, `article`) VALUES ('$head', '$time', '$date', '$descri', '$msg')"; Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/#findComment-641745 Share on other sites More sharing options...
aznjay Posted September 15, 2008 Author Share Posted September 15, 2008 I dunno if this will help, but use this instead mysql_query("INSERT INTO $whbase (title, time, date, desp, article) VALUES ('$head', '$time', '$date', '$descri', '$msg')") or die('Error, insert query failed'); I did do that Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/#findComment-641747 Share on other sites More sharing options...
aznjay Posted September 15, 2008 Author Share Posted September 15, 2008 I still get that 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 '(title, time, date, desp, article) VALUES ('', '', '', '', '')' at line 1 Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/#findComment-641748 Share on other sites More sharing options...
genericnumber1 Posted September 15, 2008 Share Posted September 15, 2008 From that error, I can see that you did not do $query = "INSERT INTO $whbase (`title`, `time`, `date`, `desp`, `article`) VALUES ('$head', '$time', '$date', '$descri', '$msg')"; let me explain, you must remove the quotes from the database because that's not good syntax. You must put backticks around the time and date fields because they are mysql functions (DATE() AND TIME()) and they confuse the parser. The other backticks are for consistency. Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/#findComment-641749 Share on other sites More sharing options...
aznjay Posted September 15, 2008 Author Share Posted September 15, 2008 nvm figured it out...i jst seperated it into two pages thnx Link to comment https://forums.phpfreaks.com/topic/124275-quick-diagnosis/#findComment-641750 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.