joshstevens19 Posted May 1, 2013 Share Posted May 1, 2013 hey guys rite i have created a website and i am trying to insert a indivual piece of data into 1 column of my phpmyadmin page table. But i am doing a TV show website and just creating a easy and basic forumn.. i am trying to insert a reply code which when you enter the details in the reply box and sumit it insert it into ID number 1 of column reply.. at the moment all it does it insert it into the end of another ID which it is creating automatically can anyone help me .. i have attached my table on to this message so you can see what the table is like!! here is my code? <?php if (isset($_POST['submitted'])) { $posttopic = $_POST['POSTTOPIC']; $postdeatils =$_POST['POSTDEATILS']; $postauthor=$_POST['POSTAUTHOR']; $sqlinsert = "INSERT INTO forumposts (`POSTTOPIC`, `POSTDEATILS`, `POSTAUTHOR`) VALUES('$posttopic', '$postdeatils', '$postauthor')"; $query = mysql_query($sqlinsert); if (!$query) { echo "error inserting new record" . mysql_error(); } } // end of mani if statment //$newrecord ="1 record added to the database"; ?> Quote Link to comment Share on other sites More sharing options...
Q695 Posted May 1, 2013 Share Posted May 1, 2013 try echo $sqlinsert; you forgot the e-mail variable on the insert. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 1, 2013 Share Posted May 1, 2013 How is your table defined? SHOW CREATE TABLE forumposts Quote Link to comment Share on other sites More sharing options...
joshstevens19 Posted May 1, 2013 Author Share Posted May 1, 2013 try echo $sqlinsert; you forgot the e-mail variable on the insert. oh sorry i posted in wrong code that code works perfectly: have a look at this one please if (isset($_POST['submitted'])) { $name = $_POST['entername']; $usernameorguest =$_POST['usernameorguest']; $reply =$_POST['reply']; $sqlinsert = "UPDATE `forumposts`(`REPLY`) VALUES('$reply') WHERE `POSTID`=1"; $query = mysql_query($sqlinsert); if (!$query) { echo "error inserting new record" . mysql_error(); } } // end of mani if statment //$newrecord ="1 record added to the database"; ?> i know i have missed a couple of vaiables out but i am just testing it to make sure it works first? any ideas Quote Link to comment Share on other sites More sharing options...
joshstevens19 Posted May 1, 2013 Author Share Posted May 1, 2013 How is your table defined? SHOW CREATE TABLE forumposts oh sorry i posted in wrong code that code works perfectly: have a look at this one please if (isset($_POST['submitted'])) { $name = $_POST['entername']; $usernameorguest =$_POST['usernameorguest']; $reply =$_POST['reply']; $sqlinsert = "UPDATE `forumposts`(`REPLY`) VALUES('$reply') WHERE `POSTID`=1"; $query = mysql_query($sqlinsert); if (!$query) { echo "error inserting new record" . mysql_error(); } } // end of mani if statment //$newrecord ="1 record added to the database"; my table is defined all correctly not posted the connection code as i didnt think that was relevant Quote Link to comment Share on other sites More sharing options...
Barand Posted May 1, 2013 Share Posted May 1, 2013 This question is covered in your other topic http://forums.phpfreaks.com/topic/277493-using-query-does-not-insert-into-the-phpmyadmin-table/?do=findComment&comment=1427501 so why have you started another topic with the same problem? Quote Link to comment Share on other sites More sharing options...
joshstevens19 Posted May 1, 2013 Author Share Posted May 1, 2013 This question is covered in your other topic http://forums.phpfreaks.com/topic/277493-using-query-does-not-insert-into-the-phpmyadmin-table/?do=findComment&comment=1427501 so why have you started another topic with the same problem? it not covered as i didnt get the answer i wanted? Quote Link to comment Share on other sites More sharing options...
Barand Posted May 1, 2013 Share Posted May 1, 2013 (edited) You were told in the other topic to remove the WHERE from an an insert new record query Are you trying to INSERT into a row that already exists? If is the case, you need to switch to an UPDATE query or, if it is a new row, remove the WHERE ok theres progress, simply change your SQL syntax to UPDATE: $sqlinsert = "UPDATE `forumposts` SET `REPLY` = $reply WHERE `POSTID` = 1"; And you were given the syntax for an UPDATE query Yet you still persist and complain about syntax errors It isn't that you did not get the answer you wanted, it is more that you chose to ignore the answers. Edited May 1, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
joshstevens19 Posted May 1, 2013 Author Share Posted May 1, 2013 You were told in the other topic to remove the WHERE from an an insert new record query And you were given the syntax for an UPDATE query Yet you still persist and complain about syntax errors It isn't that you did not get the answer you wanted, it is more that you chose to ignore the answers. okay that did help me mix my code up but now im getting this error?? error inserting new recordUnknown column 'TEST' in 'field list' this happens when i enter information and press enter? Quote Link to comment Share on other sites More sharing options...
Barand Posted May 1, 2013 Share Posted May 1, 2013 If you post the query that is giving the problem we stand a better chance of giving the answer you want Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.