Jump to content

[SOLVED] posting data


sanchez77

Recommended Posts

so I am query one table for a value, and then i want to use that value as part of where clause to update a record in another table. but for some reason that i  :facewall:

 

what i am doing wrong?

 


//setting value

$masterid =  mysql_query("SELECT masterid FROM lockers WHERE lockerno = '01' LIMIT 0, 30");

//update table with equal value

mysql_query("UPDATE lockersmaster SET timeout = '$timeout', dateout = '$dateout', storetimeout = '$storetimeout' WHERE id = '$masterid'");

Link to comment
Share on other sites

mysql_query() doesn't return a usable value. The code should be:

 

<?php
$results =  mysql_query("SELECT masterid FROM lockers WHERE lockerno = '01' LIMIT 0, 30");
while($values = mysql_fetch_array($results)){ //results from mysql are put in an array and each row is looped
     //set $timeout, $dateout and $storetimeout
     $resultsU = mysql_query("UPDATE lockersmaster SET timeout = '$timeout', dateout = '$dateout', storetimeout = '$storetimeout' WHERE id=" . $values['id']);
?>

Link to comment
Share on other sites

That is exactly correct, it should be..

 

<?php
$results =  mysql_query("SELECT masterid FROM lockers WHERE lockerno = '01' LIMIT 0, 30");
while($values = mysql_fetch_array($results)){ //results from mysql are put in an array and each row is looped
     //set $timeout, $dateout and $storetimeout
     $resultsU = mysql_query("UPDATE lockersmaster SET timeout = '$timeout', dateout = '$dateout', storetimeout = '$storetimeout' WHERE id=" . $values['masterid']);
?>

Link to comment
Share on other sites

Try adding this to your code..

 

ini_set('display_errors', 1);

error_reporting(E_ALL);

 

This will show you any errors in your script when executing the page.

 

If it doesn't work just check thoroughly through your code for syntax and try outputting variables before the UPDATE query to see if they are coming through the first query as expected.

 

IE echo $values['masterid']

Link to comment
Share on other sites

Or, just in a single query:

UPDATE table1 join table2 on table1.id=table2.id SET table1.some_val = table2.value

 

Which when applied should look something like (untested of course):

UPDATE lockersmaster JOIN lockers ON lockersmaster.id=lockers.masterid SET lockersmaster.timeout = '$timeout', lockersmaster.dateout = '$dateout', lockersmaster.storetimeout = '$storetimeout'

Link to comment
Share on other sites

that worked. i used it like so:

 


mysql_query("UPDATE lockersmaster JOIN lockers ON lockersmaster.id=lockers.masterid SET lockersmaster.timeout = '$timeout', lockersmaster.dateout = '$dateout', lockersmaster.storetimeout = '$storetimeout'");

 

Cheers,

:D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.