Hi. I am trying to retrieve data from database and update it
in a single page. I can retrieve data, but when I press a button
to update, it gives me error. I know the error but I don't know
how I can fix it. I tried to separate them in two page, but
didn't work either.
Here is my code.
if($_GET['appid']){ //if AppID is set
require_once('../mysql_connect.php'); //DB connection
$appid = escape_data($_GET['appid']);
$query = "SELECT * FROM table1, table2, table3, table4 ";
$query .= " WHERE blah blah blah condition";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_NUM);
//I didn't post the form section that will display the result
of this query. But I have it in the same page, which work
perfectly.
}elseif($POST){ //When the Update button is pressed
require_once('../mysql_connect.php'); //DB connection
if($POST['status'] != ''){
$status = escape_data ($_POST['status']) ;
}else{
$message = '<p>You have not changed status of this applicant yet.</p>';
}
if($status){ //if $status is OK
$query = "UPDATE table_status SET Status = $status WHERE AppId = ' " . $appid . " ' ";
$result = mysql_query($query); //run the query
if(mysql_affected_rows() == 1){ //If it runs OK
$conf = '<p>Updated.<p>';
include('footer2.inc'); //include footer page
exit();
}else{
$message .= '<p>Could not be updated .</p>';
}
mysql_close(); //close db connection
//End of $status condition
}else{
$message .= '<br/>Please try again.';
}
}//End of update button condition
else{
$message = '<p> error occured. ' . mysql_error() . '</p>';
}
"if($_GET['appid']) " will check if app ID was passed from the
previous page or not. This part is working.
After "else if", I have a problem. After displaying a form that
is populated with the data from database, I change one field
value and click submit. After cliking Submit button, the value of
$appid disappears and I cannot update table. I tried to assign
the value to $_SESSION, but didn't work.
Could anybody give me suggestion? I desperately need help!