danp Posted December 12, 2009 Share Posted December 12, 2009 I've never been a whiz at HTML by any means, but this is ticking me off I'm trying to make a script where the user will "equip" an item called a trinket, based on if they have one or not, and put it on their character. This is done by a loop and pulling whatever they have from the database and showing an "Equip" button under the display. It's just been frustrating, and after validating the HTML, it seems ok (besides the errors from the escape characters.) Here's the code in case you'd rather not download the source: <html> <link href="style.css" rel="stylesheet" type="text/css"> </html> <?PHP session_start(); require "connect.php"; $user_name=$_SESSION['user_name']; //Declare User stuff... $char_query = "SELECT * FROM user_char WHERE name = '$user_name'"; $result = mysql_query($char_query) or die("Error connecting to user table!"); //They pressed the button.... $trinketequip = $_POST['trinketquip']; $name2 = $_POST['name']; $id2 = $_POST['id']; //If they want to equip a different trinket, do this! if ($trinketequip){ if ($row['trinket'] == '1') {echo "<br><br>You already have a trinket equipped, please take your current one off and try again! Click <a href=\"trinkets.php\">here</a> to return."; exit; } elseif ($row['trinket'] == '0') { mysql_query("UPDATE user_char SET trinket = '1' WHERE name = '$user_name'") OR die ("Error erroring."); mysql_query("UPDATE trinkets SET equipped = '1' WHERE name = '$name2' AND owner = '$user_name AND id = '$id2'") OR die ("Error erroring - Error 1."); if ($name == "Queen of &hearts's") {$boost_num = .05; $boost_type = "max_hp_boost";} elseif ($name == "Jack of &diams's") {$boost_num = .05; $boost_type = "dexterity_boost";} elseif ($name == "King of &clubs's") {$boost_num = .05; $boost_type = "constitution_boost";} elseif ($name == "Ace of &spades's") {$boost_num = .05; $boost_type = "strength_boost";} elseif ($name == "The Magician") {$boost_num = .05; $boost_type = "strength_boost";} elseif ($name == "The Hermit") {$boost_num = .05; $boost_type = "intelligence_boost";} mysql_query("UPDATE user_char SET $boost_type='$boost_type'+'$boost_num' WHERE name = '$user_name'") OR die ("Error erroring - Error 2."); } } while ($row = mysql_fetch_array($result)) { $atrinketisequipped = $row['trinket']; } echo "<br><br><center><h2>Under Construction</h2> Don't expect anything here to work!<br><br>"; //See if user has a trinket equipped already. $equipper = "SELECT name FROM trinkets WHERE owner = '$user_name' AND equipped = '1'"; $equippy = mysql_query($equipper) or die("Error connecting to user table! Are you logged in?"); $equipped = mysql_fetch_array($equippy); if(!isset($equipped[name])){ echo "Currently Equipped - Nothing"; } //If they *DO* , show what it is... else{ echo "Currently Equipped - "; echo ("$equipped[name]"); } $char_query = "SELECT * FROM trinkets WHERE owner = '$user_name'"; $result = mysql_query($char_query) or die("Error connecting to user table! Are you logged in?"); if(!isset($result)){echo "Nothing! "; exit;} else{ echo"<br><br>"; while ($row = mysql_fetch_array($result)) { $name = $row['name']; $id = $row['id']; print "<tr><td>$name</td><td><form action=\"trinkets.php\" method=\"post\"><input class=\"button\" type=\"submit\" name=\"trinketequip\" value=\"Equip\" /><input type=\"hidden\" value=\"$name\" name=\"name\" /><input type=\"hidden\" value=\"$id\" name=\"id\" /></form></td></tr>"; } } echo "<br><br>Go <a href=\"index.php\">back</a>!"; ?> The code isn't complete as it doesn't have the "unequip" feature, but I'd like to get one part done and working before moving on Can anyone offer advice? Thanks! -D [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/184847-_post-from-html-buttons-not-functional-in-script/ Share on other sites More sharing options...
dawsba Posted December 12, 2009 Share Posted December 12, 2009 1. your session start should come before any outputted code including html put it on line 1 just after your php tag 2. I would recommend using switch instead of elseifs 3. can u not use integers instead of ascii call if queen of &diam's etc 4. where is $name pulled from is it supposed to be $name2? 5. I would recommend using `` tags on your DB calls for tables and fields Link to comment https://forums.phpfreaks.com/topic/184847-_post-from-html-buttons-not-functional-in-script/#findComment-975803 Share on other sites More sharing options...
danp Posted December 12, 2009 Author Share Posted December 12, 2009 I actually had a switch instead of the elseif's $name is being pulled from the db and $name2 is grabbed from the POST name tried finding the integer equivalent for the hearts, diamonds etc but all I got was the &hearts etc., they show up fine from the database point of view though. I'm thinking maybe I should just re-do the script haha, or have a buddy help me rewrite it. Thank you, dawsba Link to comment https://forums.phpfreaks.com/topic/184847-_post-from-html-buttons-not-functional-in-script/#findComment-976065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.