MySQL Forums
Forum List  »  PHP

PHP mysql query UPDATE not updating records when $POST is used
Posted by: Abby Cadag
Date: May 21, 2015 11:57PM

Hello! This is just an intern project but I need it to prove myself to the company. I appreciate all kinds of help. If you need the whole code, I am willing to post/give it to you.

I have a code creating a dropdown menu of statuses corresponding to a proj_id.
The dropdown menu
a. gets options from database
b. when selected updates the database

HOWEVER, the number of database records are NOT CONSTANT.This is why I used an array to get the current number of rows. Here's a snippet:

//gets all records of proj_id and places it inside an array
$sql_id = "SELECT proj_id FROM status_tab";
$result_id = mysql_query($sql_id);
$id_array = array();

//gets the records
while($id = mysql_fetch_array($result_id))
{

$id_array = $id['proj_id'];


THE PROBLEM IS THE UPDATE PART, I pass this $id_array to another php page through form using:
<input type='hidden' name=proj value='$id_array'>

AND it's working fine when I print it this way:
echo $_POST['proj'];

Or do it this way:
$fp = $_POST['proj'];
echo $fp;

BUT when I place it in a query:

$ins = mysql_query('UPDATE status_tab SET status="$name" where proj_id="($_POST[proj])"', $connection);

OR

$ins = mysql_query('UPDATE status_tab SET status="$name" where proj_id="$fp"', $connection);

The record DOES NOT UPDATE!

And I've checked if the query works using this:

$fp = 'fp1';
$ins = mysql_query('UPDATE status_tab SET status="$name" where proj_id="$fp"', $connection);

IT DOES!

And now I'm stuck to why it won't update the record. mysql_error() does not report any error. Please help me if my logic/syntax is wrong. :(

Options: ReplyQuote


Subject
Written By
Posted
PHP mysql query UPDATE not updating records when $POST is used
May 21, 2015 11:57PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.