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"; ?> Link to comment https://forums.phpfreaks.com/topic/277518-my-query-wont-insert-into-a-single-coloum-in-my-phpmyadmin/ 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. Link to comment https://forums.phpfreaks.com/topic/277518-my-query-wont-insert-into-a-single-coloum-in-my-phpmyadmin/#findComment-1427634 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 Link to comment https://forums.phpfreaks.com/topic/277518-my-query-wont-insert-into-a-single-coloum-in-my-phpmyadmin/#findComment-1427647 Share on other sites More sharing options...
joshstevens19 Posted May 1, 2013 Author Share Posted May 1, 2013 On 5/1/2013 at 9:46 PM, Q695 said: 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 Link to comment https://forums.phpfreaks.com/topic/277518-my-query-wont-insert-into-a-single-coloum-in-my-phpmyadmin/#findComment-1427648 Share on other sites More sharing options...
joshstevens19 Posted May 1, 2013 Author Share Posted May 1, 2013 On 5/1/2013 at 10:12 PM, Barand said: 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 Link to comment https://forums.phpfreaks.com/topic/277518-my-query-wont-insert-into-a-single-coloum-in-my-phpmyadmin/#findComment-1427649 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? Link to comment https://forums.phpfreaks.com/topic/277518-my-query-wont-insert-into-a-single-coloum-in-my-phpmyadmin/#findComment-1427650 Share on other sites More sharing options...
joshstevens19 Posted May 1, 2013 Author Share Posted May 1, 2013 On 5/1/2013 at 10:16 PM, Barand said: 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? Link to comment https://forums.phpfreaks.com/topic/277518-my-query-wont-insert-into-a-single-coloum-in-my-phpmyadmin/#findComment-1427657 Share on other sites More sharing options...
Barand Posted May 1, 2013 Share Posted May 1, 2013 You were told in the other topic to remove the WHERE from an an insert new record query On 5/1/2013 at 2:17 PM, InoBB said: 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 On 5/1/2013 at 2:30 PM, InoBB said: 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. Link to comment https://forums.phpfreaks.com/topic/277518-my-query-wont-insert-into-a-single-coloum-in-my-phpmyadmin/#findComment-1427660 Share on other sites More sharing options...
joshstevens19 Posted May 1, 2013 Author Share Posted May 1, 2013 On 5/1/2013 at 11:12 PM, Barand said: 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? Link to comment https://forums.phpfreaks.com/topic/277518-my-query-wont-insert-into-a-single-coloum-in-my-phpmyadmin/#findComment-1427663 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 Link to comment https://forums.phpfreaks.com/topic/277518-my-query-wont-insert-into-a-single-coloum-in-my-phpmyadmin/#findComment-1427668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.