Jump to content

Recommended Posts

ok this is the piece of code giving me problems..

 $Result = mysql_query("SELECT gold FROM users WHERE username='$username'");
      $Row = mysql_fetch_array($Result );
if ($Row < 50) 
{
	echo "You dont have enough gold to purchase a hoe!!";
	die();
}
else
{

}

 

when i uncapitalize the $username and i buy a hoe with 20 gold it says user cannot buy gold...which is good..but when a user has enough gold it still says user doesnt have enough gold...and when i capitalize it...if the user has enough gold it will buy the hoe which is good but when the user has not enough money it still buys the hoe!!!

 

 

what the heck is this!?

Link to comment
https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/
Share on other sites

i did...its all good too...

 

check it out..

 

insert2.php

 

<?php
//ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="textgame"; // Database name
$tbl_name="users"; // Table name 
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$Username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : FALSE;
$password1 = (isset($_POST['password1'])) ? $_POST['password1'] : FALSE;
$password2 = (isset($_POST['password2'])) ? $_POST['password2'] : FALSE;
if(!$Username) die('username not set');
if(!$password1) die('Password1 not set');
else $password1 = md5($password1);
if(!$password2) die('Password2 not set');
else $password2 = md5($password2);
$query = "SELECT * FROM users WHERE username='$Username' AND password1='$password1' AND password2='$password2'";
$result = mysql_query($query) or die( mysql_error());
$count=mysql_num_rows($result);
if($count==1)
{
session_start();
//session_register("username");
$_SESSION['Username'] = $Username;
$queryy = "SELECT gold FROM users WHERE username='$Username'";
$result1 = mysql_query($queryy);
$row = mysql_fetch_assoc($result1);
$_SESSION['gold'] = $row['gold'];
//session_register("inventory");
$Query = "SELECT item FROM users_items WHERE username='$Username'";
$Result = mysql_query($Query);
$Row = mysql_fetch_array($Result);
$_SESSION['inventory'] = $Row['item'];
  

header("location:index2.php"); 
}
else {
echo "Wrong Username or Password";
}

?>

 

hoe.php

 

<?php
session_start();
if(isset($_SESSION['Username'])) {
?>


<p></p>
<p><a href="shop.php">Shop</a> </p>
<?php
$Username = $_SESSION['Username'];
   //connect
   mysql_connect("localhost", "root", "") or die(mysql_error());
   mysql_select_db("textgame") or die(mysql_error());
   
   //if else statement

$Result = mysql_query("SELECT gold FROM users WHERE username='$Username'");
      $Row = mysql_fetch_array($Result );
if ($Row < 50) 
{
	echo "You dont have enough gold to purchase a hoe!!";
	die();
}
else
{

}

$query = "SELECT * FROM users_items WHERE username='$Username' AND item = 'hoe'";
$result = mysql_query($query) or die( mysql_error());
if ($row = mysql_fetch_row($result)) 
{

	 echo "you have already bought a hoe!!";
	 die();
}
else
{

mysql_query("INSERT INTO users_items (username, item) VALUES('$Username', 'hoe' ) ") 
      or die(mysql_error());
  echo "You have purchased a hoe!!";
}
?>
<?php
//session_register("inventory");
$Query = "SELECT item FROM users_items WHERE username='$Username'";
$Result = mysql_query($Query);
$Row = mysql_fetch_array($Result);
$_SESSION['inventory'] = $Row['item'];
} //I added this bracket here


?>

 

i would change this line

 

$Username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : FALSE;

 

to

 

$Username = (isset($_POST['Username'])) ? mysql_real_escape_string($_POST['Username']) : FALSE;

 

But before doing this make sure your input field has a name of Username

 

<input type="text" name="Username" />

Scratch whateveryone has been feedin ya.

 

$Result = mysql_query("SELECT gold FROM users WHERE username='$username'");
      $Row = mysql_fetch_array($Result );
if ($Row['gold'] < 50)
{
      echo "You dont have enough gold to purchase a hoe!!";
      die();
}
else
{

}

 

You were never checking the actual column.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

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.