Avalanche Posted April 20, 2003 Share Posted April 20, 2003 [php:1:9d2978653a]<?php $dynobucks = \"1000\"; $username = \"Avalanche\"; /* connecting to the database */ $db = mysql_connect(localhost,burnttoa_neomast,<passwoyd>); mysql_select_db (burnttoa_neoships) or die (\"Cannot connect to database\"); /* center!!! */ echo \"<center>\"; /* here we\'ll select and count the info from the items table. we\'ll make sure that it belongs in the current shop, is there, and we\'ll draw the ID we\'re selecting from the URL */ $query_count = \"SELECT * FROM items WHERE id=\'$_GET[id]\' and amount>=\'1\'\"; // Sets what we want to pull from the database $result_count = mysql_query($query_count); // Pulls what we want from the database $totalrows = mysql_num_rows($result_count); // This counts the number of users /* once again, if there are no items, display an error message */ if ($totalrows == 0) { echo \"That item is not in the inventory, <b>knucklehead</b>!nn\"; exit(); /* that last exit there quits the rest of the page */ } /* now let\'s move on to haggling */ /* another mysql loop thingy... */ while($r=mysql_fetch_array($result_count)) { /* turning data into variables */ $itemid=$r[\"id\"]; $itemshopname=$r[\"shopname\"]; $itemname=$r[\"name\"]; $itemdescription=$r[\"description\"]; $itemimage=$r[\"image\"]; $itemprice=$r[\"price\"]; $itemamount=$r[\"amount\"]; /* we\'re going to need to get the shops id for the return link, so let\'s select it! */ $query_shops = \"SELECT * FROM shops WHERE name=\'$itemshopname\'\"; $query_shops2 = mysql_query($query_shops); while($r=mysql_fetch_array($query_shops2)) { $shopid=$r[\"id\"]; } /* we need a title, of course... */ echo \"<title>DynoPets - $itemshopname</title>nn\"; /* let\'s check to see if they\'re haggle amount is more than %5 of the original price */ $checkamount = $_POST[price] * .05; $checkamount2 = $itemprice - $checkamount; /* if their amount is less than 5% of the original price, call \'em a knucklehead! */ if ($_POST[price] < $checkamount2) { echo \"\"No deal, <b>knucklehead</b>! You\'re too cheap!\"<p>nn\"; echo \"<a href=\'shop.php?id=$shopid\'>Return To Shop</a>nn\"; exit(); } /* if it is more than or equal to 5% of the original price, let \'em have it! */ elseif ($_POST[price] >= $checkamount2) { /* but first, make sure they have the dynobucks to do so! */ /* here is if they don\'t have enough */ if ($dynobucks < $_POST[price]) { echo \"You don\'t got \'nuff DynoBucks to purchase that, <b>knucklehead</b><p>nn\"; echo \"<a href=\'shop.php?id=$shopid\'>Return To Shop</a>nn\"; exit(); } /* and here is if they do have enough */ elseif ($dynobucks >= $_POST[price]) { /* here is the new amount of dynobucks */ $newbucks = $dynobucks - $_POST[price]; /* now we\'re updating! */ $bucksquery = \"UPDATE users SET dynobucks=\'$newbucks\' WHERE username=\'$username\'\"; mysql_query($bucksquery); echo \"You bought <b>$itemname</b> for <b>$_POST[price]</b> DynoBucks!<br> You now have <b>$newbucks</b> DynoBucks.<p>nn\"; echo \"<a href=\'shop.php?id=$shopid\'>Return To Shop</a>nn<p>\"; } /* something would have to go horribly wrong to get this message... */ else { echo \"Woah, crap, <b>knucklehead</b>, there was an error! Make sure that you use numbers, not letters! cough<b>knucklehead</b>cough...\"; } /* now let\'s remove one from the shop! */ /* here is, of course, the new amount */ $newamount = $itemamount - 1; /* here we\'ll get rid of the item if the new amount is 0 */ if ($newamount == 0) { $deletequery = \"DELETE from \'items\' WHERE id=\'$itemid\'\"; mysql_query($deletequery); } /* here we\'ll simply update the amount if it is 1 or more */ elseif ($newamount >= 1) { $updatequery = \"UPDATE \'items\' SET \'amount\'=\'$newamount\' WHERE \'id\'=\'$itemid\'\"; mysql_query($updatequery); } } /* something would have to go horribly wrong to get this message... */ else { echo \"Woah, crap, <b>knucklehead</b>, there was an error! Make sure that you use numbers, not letters! cough<b>knucklehead</b>cough...\"; } } /* no center!!!! */ echo \"</center>\"; ?>[/php:1:9d2978653a] For some reason it won\'t update the item\'s amount... Everything else (all the math and echos and loops and things) work correctly, but for some reason it just won\'t update the tables! I tried echoing $newamount and it comes out like it should. Quote Link to comment https://forums.phpfreaks.com/topic/369-why-wont-it-update-argh/ Share on other sites More sharing options...
metalblend Posted April 20, 2003 Share Posted April 20, 2003 Check what happened.. if you got any errors. Take this:[php:1:4e2b4dbcbf]/* here is the new amount of dynobucks */ $newbucks = $dynobucks - $_POST[price]; /* now we\'re updating! */ $bucksquery = \"UPDATE users SET dynobucks=\'$newbucks\' WHERE username=\'$username\'\"; mysql_query($bucksquery); echo \"You bought <b>$itemname</b> for <b>$_POST[price]</b> DynoBucks!<br> You now have <b>$newbucks</b> DynoBucks.<p>nn\"; echo \"<a href=\'shop.php?id=$shopid\'>Return To Shop</a>nn<p>\";[/php:1:4e2b4dbcbf] And replace with this:[php:1:4e2b4dbcbf]/* here is the new amount of dynobucks */ $newbucks = $dynobucks - $_POST[price]; /* now we\'re updating! */ $bucksquery = \"UPDATE users SET dynobucks=\'$newbucks\' WHERE username=\'$username\'\"; $bucksreslt = mysql_query($bucksquery); if ($bucksreslt==FALSE) { echo \"<code><b>ERROR :</b> UPDATE FAILED<br><i>\".mysql_error().\"</i></code>\"; echo \"<a href=\'shop.php?id=$shopid\'>Return To Shop</a>nn<p>\"; } else { echo \"You bought <b>$itemname</b> for <b>$_POST[price]</b> DynoBucks!<br>You now have <b>$newbucks</b> DynoBucks.<p>nn\"; echo \"<a href=\'shop.php?id=$shopid\'>Return To Shop</a>nn<p>\"; }[/php:1:4e2b4dbcbf] If the update encounters an error you\'ll see it now.. of course when you figure out the problem you\'ll probably want to rid of the error report. Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/369-why-wont-it-update-argh/#findComment-1234 Share on other sites More sharing options...
Avalanche Posted April 20, 2003 Author Share Posted April 20, 2003 Oh, sorry, the DynoBucks updating works, but the inventory updating doesn\'t. Quote Link to comment https://forums.phpfreaks.com/topic/369-why-wont-it-update-argh/#findComment-1242 Share on other sites More sharing options...
metalblend Posted April 20, 2003 Share Posted April 20, 2003 ah sorry i misunderstood.. output some text to see if you get to that part of the loop to update. take this:[php:1:cd392f2d6e]* here we\'ll simply update the amount if it is 1 or more */ elseif ($newamount >= 1) { $updatequery = \"UPDATE \'items\' SET \'amount\'=\'$newamount\' WHERE \'id\'=\'$itemid\'\"; mysql_query($updatequery); }[/php:1:cd392f2d6e] and use this:[php:1:cd392f2d6e]* here we\'ll simply update the amount if it is 1 or more */ elseif ($newamount >= 1) { $updatequery = \"UPDATE \'items\' SET \'amount\'=\'$newamount\' WHERE \'id\'=\'$itemid\'\"; $result = mysql_query($updatequery); print \"we\'re in the UPDATE loop..<br>\"; if ($result==FALSE) { print \"<b>ERROR :</b> QUERY FAILED<br>\".mysql_error(); } }[/php:1:cd392f2d6e] Quote Link to comment https://forums.phpfreaks.com/topic/369-why-wont-it-update-argh/#findComment-1245 Share on other sites More sharing options...
Avalanche Posted April 20, 2003 Author Share Posted April 20, 2003 I got this: we\'re in the UPDATE loop.. ERROR : QUERY FAILED You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near \'\'items\' SET \'amount\'=\'2\' WHERE \'id\'=\'5\'\' at line 1 And since when did my errors get so descriptive? :? Quote Link to comment https://forums.phpfreaks.com/topic/369-why-wont-it-update-argh/#findComment-1246 Share on other sites More sharing options...
metalblend Posted April 20, 2003 Share Posted April 20, 2003 aha! i\'m surprised i missed that. [php:1:ccb7fabe76]$updatequery = \"UPDATE \'items\' SET \'amount\'=\'$newamount\' WHERE \'id\'=\'$itemid\'\";[/php:1:ccb7fabe76]should be:[php:1:ccb7fabe76]$updatequery = \"UPDATE items SET \'amount\'=\'$newamount\' WHERE \'id\'=\'$itemid\'\";[/php:1:ccb7fabe76] no quotes around the table name. and about the errors, that\'s mysql_error() you use it to output the last error generated by mysql from your script Quote Link to comment https://forums.phpfreaks.com/topic/369-why-wont-it-update-argh/#findComment-1248 Share on other sites More sharing options...
Avalanche Posted April 21, 2003 Author Share Posted April 21, 2003 Okay, thanks. I also had to get rid the the \' \' around the field name (just not the new data). That\'ll teach me to use a PHPMyAdmin query... Quote Link to comment https://forums.phpfreaks.com/topic/369-why-wont-it-update-argh/#findComment-1259 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.