Jump to content

mysql_query error


lmninfo

Recommended Posts

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

 

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

Archived

This topic is now archived and is closed to further replies.

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