insert

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

insert

Post by radium35 »

want to insert into db with if statement into pre existing table for a particular user_id.... Getting error for mysql syntax


if ($_POST['status']==APPROVED)

$db = mysql_connect( "xxxx", "xxxxx", "xxxxx", "xxxxxxx" ) or die ("not able to connect.");

mysql_select_db( "xxxxxx", $db );

$query = "INSERT INTO attendees (
payment_status,
)
VALUES (
'PAID',
)";
mysql_query($query) or die(mysql_error());
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: insert

Post by requinix »

You have some extra commas.
mrkezi
Forum Newbie
Posts: 2
Joined: Sun Nov 30, 2008 4:02 am

Re: insert

Post by mrkezi »

TRY THIS:
Avoid commas and open the if body and close it accordingly.
Make sure the database exists and the table attendees is in that database with the same spelling and cases(upper/lowwer).
I suggest you include the else clause to handle the else part of the 'if', supposing the status is not the same as APPROVED
TEST THIS BELOW

if ($_POST['status']=='APPROVED'){

$db = mysql_connect( "xxxx", "xxxxx", "xxxxx", "xxxxxxx" ) or die ("not able to connect.");

mysql_select_db( "xxxxxx", $db );

$query = "INSERT INTO attendees (payment_status)VALUES ('PAID')";
mysql_query($query) or die(mysql_error());
echo "inserted";
}
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: insert

Post by radium35 »

mrkezi wrote:TRY THIS:
Avoid commas and open the if body and close it accordingly.
Make sure the database exists and the table attendees is in that database with the same spelling and cases(upper/lowwer).
I suggest you include the else clause to handle the else part of the 'if', supposing the status is not the same as APPROVED
TEST THIS BELOW

if ($_POST['status']=='APPROVED'){

$db = mysql_connect( "xxxx", "xxxxx", "xxxxx", "xxxxxxx" ) or die ("not able to connect.");

mysql_select_db( "xxxxxx", $db );

$query = "INSERT INTO attendees (payment_status)VALUES ('PAID')";
mysql_query($query) or die(mysql_error());
echo "inserted";
}
This did insert "PAID" into the desired table but the id auto increments and it makes a whole new row. I want the $_POST[id] that I have on the page to be the row that i insert "PAID" into.
Post Reply