Daron Posted July 4, 2011 Posted July 4, 2011 hey i was altering the travel time mod a bit, to make it so normal travel time is 30 minutes and decreases based off your agility by incremnents of 5. but i get this error QUERY ERROR: 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 'WHERE userid=1' at line 1 Query was UPDATE users SET location=11, traveltime= WHERE userid=1 here is code: <?php include "globals.php"; include "travellingglobals.php"; if($ir['agility']>=500) { $rantime = rand(30); } else if($ir['agility']>=1000) { $rantime = rand(25); } else if($ir['agility']>=1500) { $rantime = rand(20); } else if($ir['agility']>=2000) { $rantime = rand(15); } else if($ir['agility']>=2500) { $rantime = rand(10); } else if($ir['agility']>=3000) { $rantime = rand(5); } else if($ir['agility']>=5000) { $rantime = rand(0); } $_GET['to'] = abs((int) $_GET['to']); if(!$_GET['to']) { print "You set out to travel. Where are you travelling to? "; $q=$db->query("SELECT * FROM villages WHERE villageID != {$ir['location']} AND villageminlevel <= {$ir['level']}"); print "<table width=75% cellspacing=1 class='table'><tr style='background:gray'><th>Name</th><th>Description</th><th>Min Level</th><th> </th></tr>"; while($r=$db->fetch_row($q)) { print "<tr><td>{$r['villageNAME']}</td><td>{$r['villageDESC']}</td><td>{$r['villageminlevel']}</td><td><a href='travel.php?to={$r['villageID']}'>Go</a><br /></td></tr>"; } print "</table>"; } else if( ((int) $_GET['to']) != $_GET['to']) { print "Invalid city ID"; } else { $q=$db->query("SELECT * FROM villages WHERE villageID = {$_GET['to']} AND villageminlevel <= {$ir['level']}"); if(!$db->num_rows($q)) { print "Error, this city either does not exist or you cannot go there."; } else { $db->query("UPDATE users SET location={$_GET['to']}, traveltime=$rantime WHERE userid=$userid"); $r=$db->fetch_row($q); print "You are now travelling to {$r['villageNANE']} on foot! It will take $rantime minutes to arrive."; } } $h->endpage(); ?> Quote
US Vice Posted July 4, 2011 Posted July 4, 2011 Where you have used the rand function you have not defined a minimum and maximum arguement, so rand(10, 25); http://php.net/manual/en/function.rand.php Quote
Daron Posted July 4, 2011 Author Posted July 4, 2011 oh yea i forgot to remove that, i wont be using random times, the times will be absolute based off $ir['agility'] Quote
Danny696 Posted July 4, 2011 Posted July 4, 2011 (edited) What did you do wrong? Well, you thought that we would fix it for you, well no. Try reading the error, and you'll realise theres something wrong. not hard is it? QUERY ERROR: 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 'WHERE userid=1' at line 1 Query was UPDATE users SET location=11, traveltime= WHERE userid=1 Simple now: QUERY ERROR: = Oh, theres an error in the query you tried. You have an error in your SQL syntax = Something wrong with the santax for the right syntax to use near 'WHERE userid=1' at line 1 = Theres something wrong with either 'WHERE userid=1' or before that. Query was UPDATE users SET location=11, traveltime= WHERE userid=1 = Heres the query again, see if you can spot the error, then fix me. Edited July 4, 2011 by Dominion Edited out the rude parts, and kept the constructive parts. Quote
lucky3809 Posted July 4, 2011 Posted July 4, 2011 US has answered this error. Your rand () is not correctly done right. And as Danny mention look at the error given... traveltime= Has nothing after it, meaning that is the error,which in your script you have added $rantime in that query after traveltime= meaning you should look in your script and see where you screwed up which would be your if statements with $rantime = rand(); example you have... $rantime = rand(10); should be ... $rantime = rand(10,10); As like US said. and directed you to the website to show how the rand function works. Quote
lucky3809 Posted July 4, 2011 Posted July 4, 2011 (edited) well im sure he wouldn't need to even use rand, it was an example... he could just add $rantime= 10; if he wanted the time to be from 0-10 minutes then the rand should be rand(0,10) rand(10,10) is the same as $rantime =10; Edited July 5, 2011 by lucky3809 Quote
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.