Jump to content

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

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.