Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Increasing a value on mysql database

mysql

  • Please log in to reply
1 reply to this topic

#1 Korlando

Korlando

    CC Regular

  • Member
  • PipPipPip
  • 44 posts
  • Programming Language:PHP, (Visual) Basic, Visual Basic .NET
  • Learning:Java, NXT-G

Posted 05 September 2012 - 01:33 PM

I am trying to increase a value. I made a project and this code works. The difference is that this time I have one factor more. And this is my main problem. Each time I am ready to increase the value an error appears:
Unknown column 'Garcia' in 'where clause' -------> Garcia is the surname of the player

I have not idea what does clause means. I know that I never used such a name.

This feuture uses 2 php pages. The first one opens the popup.
<script type="text/javascript">
<!--
var stile = "top=50, left=50, width=600, height=200 status=no, menubar=no, toolbar=no scrollbar=no";
function Popup(apri) {	
window.open(apri, "", stile);	 }
	 //-->
		 </script><a href="javascript:Popup('attpopup.php?UID=<?=$UID?>&Enme=<?php echo $row['Name']?>&ATS=<?php echo $row['att']?>&Skill=<?php $Skill='Att'?><?=$Skill?>')"><img src="Add-icon.png" width="16" height="16" />
The second one IS the pop-up page:
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]">
<html xmlns="[url="http://www.w3.org/1999/xhtml"]http://www.w3.org/1999/xhtml[/url]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<SCRIPT language="Javascript">
function buttonYes() {
<?php
if (isset($_POST['Submit1'])) {
$PlayerID = $_SESSION['myusername'];
$UID = $_SESSION['UID'];
mysql_connect("localhost", "root", "") or die(mysql_error());
 
 
 mysql_select_db("lightleague") or die(mysql_error());
$result = mysql_query("Update players set att='$att' where UID=$UID & Ename=$Enme" ) or die(mysql_error()); 
$row1 = mysql_fetch_array($result);
}
?>
}
</SCRIPT>
</head>
<body>
<?php
$UID = $_SESSION['UID'];
$att = $_GET['ATS'];
$Enme = $_GET['Enme'];
//$Skill = $_GET['ATS=/!!l'];
$att = $att+1;
//$Money =
if (isset($_POST['update'])) {
  /*$PlayerID = $_SESSION['myusername'];
  $UID = $_SESSION['UID'];*/
  
  mysql_connect("localhost", "root", "") or die(mysql_error());
  
  
   
   mysql_select_db("lightleague") or die(mysql_error());
   $result1 = mysql_query("select * from uplayer where UID='$UID'" );
   $row1 = mysql_fetch_array($result1);
  //$Money = $row1['Money'];
  if  ($row1['Money']>49) {
   
   mysql_query("Update players set att='$att' where UID=$UID & Ename=$Enme" ) or die(mysql_error()); 
   $result2 = mysql_query("select * from uplayer where UID='$UID'" );
   $row2 = mysql_fetch_array($result2);
   $CMoney = $row2['Money'] - 50;
   mysql_query("Update uplayer set Money='$CMoney' where UID=$UID" ) or die(mysql_error()); 
   echo "Succesful Update";
   
   }
  else //If  ($row1['Money'])>99
   {
	echo "Not enough money";
   }
  }
else
{?>
<p>Do you want to spend 50$ to increase this skill?</p>
<table width="200" border="1">
  <tr>
    <td width="64"><form id="form1" name="form1" method="post" action="attpopup.php?UID=<?=$UID?>&Enme=<?php echo $Enme?>&att=<?=$att?><?php $Skill='att'?><?=$Skill?>&ATS=<?php echo $att?>">
	  <p>
	    <input type="submit" name="button" id="button" value="Yes" />
	    <input type="hidden" name="update" value="yes" id="hiddenField" />
	  </p>
    </form></td>
    <td width="89"><form id="form2" name="form2" method="post" action="">
	  <input type="submit" name="button2" id="button2" value="No" />
    </form></td>
    <td width="25">&nbsp;</td>
  </tr>
</table>
<?php }
?>
</body>
</html>

  • 0

#2 Colanth

Colanth

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 165 posts
  • Location:Fayetteville, NC, USA
  • Programming Language:PHP, (Visual) Basic, JavaScript, Visual Basic .NET, Pascal, Logo, Assembly, VBScript, Others

Posted 22 September 2012 - 08:12 PM

First:

A where clause uses

where a = b and c = d

and, not &.

Second, text has to be quoted:

$result = mysql_query("Update players set att='$att' where UID=$UID and Ename='$Enme'" ) or die(mysql_error());

(Assuming that UID is a numeric field and Ename is a text field.)

Try those changes and see if you have other errors.

(If you use FirePHP, you can send the queries to the browser so you can see exactly what they look like. Alternatively you can echo them then exit for testing purposes.)
  • 1





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download