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!!!!

Recommended Answers

All 3 Replies

You forgot a part, in short:

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

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];

many thanks guys absolute legend!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.