0

hi guys having a problem getting a single value from a mysql query getting all sorts of problems - heres my latest version below

mysql_connect($host,$user,$password) or die( "Unable to select database");
mysql_select_db("mydatabase"); // select database to use.
$user = 84;
$sql1="SELECT `order_id` FROM `table1` WHERE `user_id`= '$user'";
$array = mysql_fetch_array('$sql1'); 
$sqlres1 = $array[order_id];
echo $user;
$sql2="UPDATE `table2` Set `order_status` = 'C' WHERE `order_id` = '$sqlres1' And `order_status` = 'P'";
mysql_query($sql2);
echo $sql2;
mysql_close();
echo "Successfully completed";

basically i want to get the value returned from $sql1 and use it as part of $sql2 - i'm getting a Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource at the moment

can someone please help!!!!

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by cacoyle
0

You forgot a part, in short:

$result = mysql_query($sql1);
if ($result)
  $array = mysql_fetch_array($result);
0

I agree with pritaeas. Don't worry, I can stare at code and not realize I missed stuff out all the time!

This might be picky, but you should use single quotes round individual array designations (unless you're using a variable): $array not $array[order_id];

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.