ILYAS415 Posted April 22, 2007 Share Posted April 22, 2007 I am currently developing a game for someone but ive hit a dead end as im having strange trouble with one the the scripts. In this script I used the while command to echo multiple weapons inside a <select> tag. When i run the script everything works, apart from the mysql query which doesnt work how its supposed to... <?php $playerweapons= mysql_query("SELECT * FROM weapons WHERE owner='$fetch->username'"); $number= mysql_num_rows($playerweapons); if ($number == "0"){ echo "You have no bought weapons!"; exit(); }elseif ($number > "0"){ ?> <select name=weapon style="background-color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;"> <? while ($pw= mysql_fetch_object($playerweapons)){ ?> <option value="<? echo " $pw->name "; ?>"><? echo "$pw->name"; ?></option> <? } echo "</select>"; ?> <input type=submit style="background-color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;" name=equip value="Equip"> <? } ?> <br> You currently have a <? echo "$fetch->weapon"; ?> equipped!<br> <?php if (strip_tags($_POST['weapon']) && strip_tags($_POST['equip'])){ $wep=$_POST['weapon']; $weapon= mysql_query("SELECT * FROM weapons WHERE `name`='$wep' AND `owner`='$username'"); $wepnum= mysql_num_rows($weapon); $wp= mysql_fetch_object($weapon); if ($wep == "0" | $wep == $fetch->weapon){ echo "Either you have this weapon equipped already or you chose an invalid weapon"; exit(); } echo "Changes have succesfully been made! You are now wielding a $wep!<br>"; mysql_query("UPDATE users SET weapon='$wep' WHERE username='$username'"); } ?> The bit at the end doesnt work. mysql_query("UPDATE users SET weapon='$wep' WHERE username='$username'"); I didnt include the $username variable in the script but it is on the page though. The problem with the query is that when it runs the query, its sets the weapon to Nothing instead of the selected weapon name. Quote Link to comment https://forums.phpfreaks.com/topic/48110-solved-basic-php-mysql-question/ Share on other sites More sharing options...
Wo0tHigh Posted May 12, 2007 Share Posted May 12, 2007 <?php $playerweapons= mysql_query("SELECT * FROM weapons WHERE owner='$fetch->username'"); $number= mysql_num_rows($playerweapons); if ($number == "0"){ echo "You have no bought weapons!"; exit(); }elseif ($number > "0"){ echo"<select name=weapon style=\"background-color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;\">"; while ($pw= mysql_fetch_object($playerweapons)){ echo"<option value=\"$pw->name\">$pw->name</option>"; } echo "</select>"; ?> <input type=submit style="background-color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;" name=equip value="Equip"> <? } ?> You currently have a <? echo "$fetch->weapon"; ?> equipped! <?php if (strip_tags($_POST['weapon']) && strip_tags($_POST['equip'])){ $wep=$_POST['weapon']; $weapon= mysql_query("SELECT * FROM weapons WHERE `name`='$wep' AND `owner`='$username'"); $wepnum= mysql_num_rows($weapon); $wp= mysql_fetch_object($weapon); if ($wep == "0" | $wep == $fetch->weapon){ echo "Either you have this weapon equipped already or you chose an invalid weapon"; exit(); } echo "Changes have succesfully been made! You are now wielding a $wep! "; mysql_query("UPDATE users SET weapon='$wep' WHERE username='$username'"); } ?> Should work Quote Link to comment https://forums.phpfreaks.com/topic/48110-solved-basic-php-mysql-question/#findComment-251064 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.