Jump to content

using query does not insert into the phpmyadmin table?


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 press reply 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 can anyone help me 

 

here is my code?

 

 

<?php
if (isset($_POST['submitted'])) {
    
    
    $name = $_POST['entername'];
    $usernameorguest =$_POST['usernameorguest'];
    $reply =$_POST['reply'];
    $sqlinsert = "INSERT INTO `forumposts` WHERE (`POSTID`=1) INTO (`REPLY`) VALUES('$reply')";
 
$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
Share on other sites

sorry guys i knew i wrote it wrong.. okay i have replaced the code and now it comes up with this error?

 

error inserting new recordYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `POSTID`=1' at line 1

 

what does this mean?? just want to insert the data in my valables into the result column in ID1 ? i dont understand why it will not work?

 

thanks a lot

josh

Link to comment
Share on other sites

your problem is your query string:

$sqlinsert = "INSERT INTO `forumposts` WHERE (`POSTID`=1) INTO (`REPLY`) VALUES('$reply')";

shoudl be:

$sqlinsert = "INSERT INTO `forumposts`(`REPLY`) VALUES('$reply')";

also, look into prepared statements http://php.net/manual/en/mysqli.prepare.php

 

 

I've never seen SQL like that before. What DB are you using?

MySQL (and every other SQL engine I've seen) would be: INSERT INTO `table` (column, column) VALUES (value, value)

 

 

 

sorry guys i knew i wrote it wrong.. okay i have replaced the code and now it comes up with this error?

 

error inserting new recordYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `POSTID`=1' at line 1

 

what does this mean?? just want to insert the data in my valables into the result column in ID1 ? i dont understand why it will not work?

 

thanks a lot

josh

Link to comment
Share on other sites

<?php
if (isset($_POST['submitted'])) {
    
    
    $name = $_POST['entername'];
    $usernameorguest =$_POST['usernameorguest'];
    $reply =$_POST['reply'];
    $sqlinsert = "INSERT INTO `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";
 
 
 
 
 
?>

 

 

this is my code now 

 

 

 

your problem is your query string:

$sqlinsert = "INSERT INTO `forumposts` WHERE (`POSTID`=1) INTO (`REPLY`) VALUES('$reply')";

shoudl be:

$sqlinsert = "INSERT INTO `forumposts`(`REPLY`) VALUES('$reply')";

also, look into prepared statements http://php.net/manual/en/mysqli.prepare.php

Link to comment
Share on other sites

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

 

it is a column that already exsists in my phpmyadmin table.. it is empty and this code should post it in to that column.. 

 

i change it to INSERT and it comes up with this error message

 

error inserting new recordYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO `forumposts`(`REPLY`) VALUES('test') WHERE `POSTID`=1' at line 1

 

saying the code is incorrect.. when i have ran it without the insert of POSTID it insert but not on the one i want it to it creates a new ID as that is on ai and posts it in that section??

 

any ideas??

 

thanks

josh

Link to comment
Share on other sites

I think you need to do some basic research on how the database works. What a column is, what a row is, what a table is, what phpMyAdmin is, what syntax goes with what query, etc. Cause none of what you're saying makes any sense.

 

You should not re-use IDs.

Edited by Jessica
Link to comment
Share on other sites

 

ok theres progress, simply change your SQL syntax to UPDATE: 

$sqlinsert = "UPDATE `forumposts` SET `REPLY` = $reply WHERE `POSTID` = 1";

i have done and it brings up this error ? 

 

error inserting new recordYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(`REPLY`) VALUES('pdijspdjf') WHERE `POSTID`=1' at line 1

Link to comment
Share on other sites

I think you need to do some basic research on how the database works. What a column is, what a row is, what a table is, what phpMyAdmin is, what syntax goes with what query, etc. Cause none of what you're saying makes any sense.

 

You should not re-use IDs.

 

Very true.

Josh, read over the manual about sql syntax for a better understanding of how it works. http://dev.mysql.com/doc/refman/5.5/en/handler.html

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.