lmninfo Posted March 5, 2009 Share Posted March 5, 2009 I'm having a problem with the following code: <labor.php> <?php include 'connect.php'; session_start(); ?> <?php if (isset($_SESSION['player'])) { $player=$_SESSION['player']; $userstats="SELECT * from km_users where playername='$player'"; $userstats2=mysql_query($userstats) or die("Could not get user stats"); $userstats3=mysql_fetch_array($userstats2); print "Basic Skilled Labor<br>"; print "<br>"; print "Manpower: 2<br>"; print "Research: 1<br>"; print "<br>"; print "Food: 5<br>"; print "Peasants: 1<br>"; print "<form action='peasant2labor.php' method='post'>"; print "<input type='text' name='peasant2labor' size='5'><br>"; print "<input type='submit' name='submit' value='Change'></form>"; } and <peasant2labor.php> <?php include 'connect.php'; session_start(); ?> <link rel="stylesheet" href="style.css" type="text/css"> <?php if (isset($_SESSION['player'])) { $player=$_SESSION['player']; $userstats="SELECT * from km_users where playername='$player'"; $userstats2=mysql_query($userstats) or die("Could not get user stats"); $userstats3=mysql_fetch_array($userstats2); if(isset($_POST['submit'])) { $peasant2labor=$_POST['peasant2labor']; $peasant2labor=strip_tags($peasant2labor); $update="update km_users set peasants=peasants-'$peasant2labor', labor=labor+'$peasant2labor', manpower='$peasant2labor'*2, playerturns=playerturns-1 where ID='$userstats3[iD]'"; mysql_query($update) or die("Error"); print "You have $userstats3[peasants] peasants $userstats3[labor] labor and $userstats3[manpower] manpower! go back to <A href='index.php'>Main</a>."; } print "</td></tr></table>"; } else { print "Sorry, not logged in please <A href='login.php'>Login</a><br>"; } ?> When i run labor.php and post something into the box the screen goes to the peasant2labor.php and I receive the error .. I've gone over the code and cannot figure what is going wrong. The SQL database has the following to for each player file: ID playername password email turns pturns food manpower civilians morale homeless wrkeff health tents peasants labor The SQL database won't update .. Thanks for your help Link to comment https://forums.phpfreaks.com/topic/148090-mysql_query-error/ Share on other sites More sharing options...
revraz Posted March 5, 2009 Share Posted March 5, 2009 Receive what error? Link to comment https://forums.phpfreaks.com/topic/148090-mysql_query-error/#findComment-777325 Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 mysql_error() will give you all your answers...instead of this: $userstats2=mysql_query($userstats) or die("Could not get user stats"); use $userstats2=mysql_query($userstats) or die("Could not get user stats: ".mysql_error()); Link to comment https://forums.phpfreaks.com/topic/148090-mysql_query-error/#findComment-777326 Share on other sites More sharing options...
lmninfo Posted March 5, 2009 Author Share Posted March 5, 2009 I believe the error is coming from the line that follows the mysql_query($update) or die("Error"); <?php include 'connect.php'; session_start(); ?> <link rel="stylesheet" href="style.css" type="text/css"> <?php if (isset($_SESSION['player'])) { $player=$_SESSION['player']; $userstats="SELECT * from km_users where playername='$player'"; $userstats2=mysql_query($userstats) or die("Could not get user stats"); $userstats3=mysql_fetch_array($userstats2); if(isset($_POST['submit'])) { $peasant2labor=$_POST['peasant2labor']; $peasant2labor=strip_tags($peasant2labor); $update="update km_users set peasants=peasants-'$peasant2labor', labor=labor+'$peasant2labor', manpower='$peasant2labor'*2, playerturns=playerturns-1 where ID='$userstats3[iD]'"; mysql_query($update) or die("Error"); print "You have $userstats3[peasants] peasants $userstats3[labor] labor and $userstats3[manpower] manpower! go back to <A href='index.php'>Main</a>."; } print "</td></tr></table>"; } else { print "Sorry, not logged in please <A href='login.php'>Login</a><br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/148090-mysql_query-error/#findComment-777331 Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 then add a mysql_error() to that die() statement and see what it says Link to comment https://forums.phpfreaks.com/topic/148090-mysql_query-error/#findComment-777343 Share on other sites More sharing options...
apw Posted March 5, 2009 Share Posted March 5, 2009 The error message was the following: could not get user stats: near 'where id='16'' at line 1 Link to comment https://forums.phpfreaks.com/topic/148090-mysql_query-error/#findComment-777360 Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 in that query, should $userstats3[iD] be $userstats3[id] maybe? right before that line, put: print_r($userstats3) and see what the key for the array is. remember array keys are case sensitive Link to comment https://forums.phpfreaks.com/topic/148090-mysql_query-error/#findComment-777386 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.