Jump to content

My query wont insert into a single coloum in my phpmyadmin?


Recommended Posts

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";
 
 
 
 
 
?>

post-148657-0-27191200-1367443959_thumb.jpg

  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

  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 

  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?

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.

  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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.