Update inside if/else if/else statement?
Posted: Sat Feb 06, 2010 5:18 pm
Hello,
I'm working on a small homework assignment which requires selecting a radio button and sending a name from a text field in a html form to a database. I need said name to be put inside a specific row and field in my database depending on which radio button was selected.
I have a series of if/else statements(right word? I'm new to PHP) which detect which radio button was pressed, as well as sending the "name" to the database using INSERT TO, but it just queues up in the order put the name(s) down in. I read about the UPDATE statement, but I do not know how to write the syntax correctly inside my If/Else If statement.
Can anyone provide some help? I'm brand new to PHP and have until Monday to get this working. I feel like i'm close but I'm not sure how to tackle writing the syntax.
Here is the code I have so far.
Thanks for reading.
I'm working on a small homework assignment which requires selecting a radio button and sending a name from a text field in a html form to a database. I need said name to be put inside a specific row and field in my database depending on which radio button was selected.
I have a series of if/else statements(right word? I'm new to PHP) which detect which radio button was pressed, as well as sending the "name" to the database using INSERT TO, but it just queues up in the order put the name(s) down in. I read about the UPDATE statement, but I do not know how to write the syntax correctly inside my If/Else If statement.
Can anyone provide some help? I'm brand new to PHP and have until Monday to get this working. I feel like i'm close but I'm not sure how to tackle writing the syntax.
Here is the code I have so far.
Code: Select all
<?php
//Start connecting to database
$con=mysql_connect("localhost","Sam","root");
if (!$con)
{
die('could not connect:'. mysql_error());
}
//End connecting to database
mysql_select_db("week5", $con);
//Update field depending on which radio button was checked
$photographer = $_POST['photographer'];
$updatefield = $_POST['radiobutton'];
if ($updatefield == "feb11th"){
echo $_POST["photographer"];
echo ',<br/>';
echo 'You have been marked down for the 11th, good luck shooting!';
update photographerdatabase set photographer='$_POST["photographer"]' where id=1;
}
else if ($updatefield == "feb16th"){
echo $_POST["photographer"];
echo ',<br/>';
echo 'You have been marked down for the 16th, good luck shooting!';
}
else if ($updatefield == "feb23rd"){
echo $_POST["photographer"];
echo ',<br/>';
echo 'You have been marked down for the 23rd, good luck shooting!';
}
else if ($updatefield == "feb18th"){
echo $_POST["photographer"];
echo ',<br/>';
echo 'You have been marked down for the 18th, good luck shooting!';
}
//End updating field
$sql="INSERT INTO photographerdatabase (photographer)
VALUES
('$_POST[photographer]')";
if(!mysql_query($sql,$con))
{
die('Error: '.mysql_error());
}
echo "<br>";
echo "<a href='display.php'>Back to Table</a>";
mysql_close($con);
?>