Page 1 of 1
insert
Posted: Sat Nov 29, 2008 10:19 pm
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());
Re: insert
Posted: Sat Nov 29, 2008 11:25 pm
by requinix
You have some extra commas.
Re: insert
Posted: Sun Nov 30, 2008 4:19 am
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";
}
Re: insert
Posted: Sun Nov 30, 2008 10:22 am
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.