berry05 Posted December 17, 2008 Share Posted December 17, 2008 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!? Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/ Share on other sites More sharing options...
dennismonsewicz Posted December 17, 2008 Share Posted December 17, 2008 i would check ALL instances of the var $username Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718131 Share on other sites More sharing options...
berry05 Posted December 17, 2008 Author Share Posted December 17, 2008 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718132 Share on other sites More sharing options...
dennismonsewicz Posted December 17, 2008 Share Posted December 17, 2008 i would rename your $Username to something else cause you are already using $username which becomes confusing. possibly something like $gamer or something like that Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718136 Share on other sites More sharing options...
berry05 Posted December 17, 2008 Author Share Posted December 17, 2008 alright i'll try it! i'll get back to ya...and thxs! Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718139 Share on other sites More sharing options...
redarrow Posted December 17, 2008 Share Posted December 17, 2008 Your not posting username when varable username = session there mate. $Username = $_SESSION['Username']; <<<, where the post off username? Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718141 Share on other sites More sharing options...
berry05 Posted December 17, 2008 Author Share Posted December 17, 2008 dennismonsewicz your thing didnt work..redarrow ill try your idea..if i can figure out what you mean... ??? Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718144 Share on other sites More sharing options...
dennismonsewicz Posted December 17, 2008 Share Posted December 17, 2008 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" /> Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718148 Share on other sites More sharing options...
berry05 Posted December 17, 2008 Author Share Posted December 17, 2008 it then says username is not set..do you know what redarrow is trying to say? Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718157 Share on other sites More sharing options...
dennismonsewicz Posted December 17, 2008 Share Posted December 17, 2008 you have to set what session['Username'] is so change this if(isset($_SESSION['Username'])) { to $_SESSION['Username'] = $_POST['Username']; if(isset($_SESSION['Username'])) { Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718165 Share on other sites More sharing options...
berry05 Posted December 17, 2008 Author Share Posted December 17, 2008 idk my whole script is messed up..ive been messing around with it to much and now when i buy a hoe nothing shows up and doesn't add anything to the table.. Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718228 Share on other sites More sharing options...
berry05 Posted December 17, 2008 Author Share Posted December 17, 2008 i fixed it but somehow that code you sent me messes up my script...i got rid of it and now im still stuck on the problem I've been having.. Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718240 Share on other sites More sharing options...
premiso Posted December 17, 2008 Share Posted December 17, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718246 Share on other sites More sharing options...
dennismonsewicz Posted December 17, 2008 Share Posted December 17, 2008 yeah what ^he^ said Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718249 Share on other sites More sharing options...
berry05 Posted December 17, 2008 Author Share Posted December 17, 2008 lawl! such a frustrating couple of hours....thxs gusy! Quote Link to comment https://forums.phpfreaks.com/topic/137429-solved-weird-php-error/#findComment-718253 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.