Jump to content

restock


Recommended Posts

I am trying to create a script that first sets stock to zero (which it does), and then randomly select ten items to restock. Here is my code:

 

<? include('includes/db.php'); 

if(isset($_POST['submit'])) {

$updateTack = "UPDATE tack SET stock='0'";
$Tackresult = mysql_query($updateTack) or die (mysql_error());

$updateFeed = "UPDATE feed SET stock='0'";
$Feedresult = mysql_query($updateFeed) or die (mysql_error());

$i = 1;
if($i < 11) { 
$tack = rand(1, 12);
$tackquery = "SELECT * FROM tack WHERE itemid='$tack'";
$tackresult = mysql_query($tackquery) or die (mysql_error());

while($tackrow = mysql_fetch_array($tackresult)) {
	$sql = "UPDATE tack SET
	stock='10' WHERE itemid='$tack'";
	if(mysql_query($sql)) { echo "<center>Successfully updated tack stock.</center>"; }
	else { echo'<p>Error: ' . mysql_error() . '</p>';  }
	$i++;
	}
}

$i = 1;
if($i < 11) {
$feed = rand(1, 12);
$feedquery = "SELECT * FROM feed WHERE itemid='$feed'";
$feedresult = mysql_query($feedquery) or die (mysql_error());

while($feedrow = mysql_fetch_array($feedresult)) {

	$sql2 = "UPDATE tack SET
	stock='10' WHERE itemid='$feed'";
	if(mysql_query($sql2)) { echo "<center>Successfully updated feed stock.</center>"; }
	else { echo'<p>Error: ' . mysql_error() . '</p>';  }
         $i++;
	}
}

}
echo "<form action='test29.php' method='post'> <input type='submit' value='Submit' name='submit'> </form>";

?>

 

The tack table restocks two items and the feed doesn't restock any.

Link to comment
https://forums.phpfreaks.com/topic/238577-restock/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.