Jump to content
MakeWebGames

Recommended Posts

Posted

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();
?>
Posted (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 by Dominion
Edited out the rude parts, and kept the constructive parts.
Posted

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.

Posted (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 by lucky3809

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.   Paste as plain text instead

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