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());
insert
Moderator: General Moderators
Re: insert
You have some extra commas.
Re: insert
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";
}
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";
}
Re: insert
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.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";
}