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

Link to comment
Share on other sites

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
Share on other sites

 

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
Share on other sites

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 by Barand
Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.