Cetanu Posted August 28, 2009 Share Posted August 28, 2009 I've been tinkering with this forever and haven't seen any errors, but the page goes white (aka fatal error ) Here, I think I need a fresh set of eyes. <?php if(isset($_SESSION['username']=="Admin" || $_SESSION['user_id']=="Cetanu" || $_SESSION['user_id']=="Chris P")){ echo "<form action='shop.php' method='post'> Adding an Item<br/> Name: <input type='text' maxlength='30' name='name'/><br/> Description:<br/> <textarea rows='50' cols='50' name='description'>Be sure to remember the +attack, -attack, etc.</textarea><br/> Quantity: <input type='text' name='quant'/><br/> Price: <input type='text' name='price'/> <br/> <select name='species'> <option value='Predator'>Predator</option> <option value='Alien'>Alien</option> <option value='Marine'>Marine</option> </select><br/> <input type='submit' name='add' value='Confirm Add'/> | <input type='reset' value='Reset'/> </form> "; if(isset($_POST['add'])){ mysql_query("INSERT INTO shop (`item_name`, `item_description`, `price`, `quantity`, `species`) VALUES('{$_POST['name']}', '{$_POST['description']}', '{$_POST['price']}', '{$_POST['quant']}', '{$_POST['species']}'"); echo "<script>alert('Item Added');</script>"; } } ?> It works if I take away the if statments/brackets....but not if I leave them. O_o Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted August 28, 2009 Share Posted August 28, 2009 It's not blank because you have an error. It's blank because you're not telling it to echo anything iof the first if condition isn't set. And unless you use session_start() before trying to access session variables, then it never will be set Quote Link to comment Share on other sites More sharing options...
Cetanu Posted August 28, 2009 Author Share Posted August 28, 2009 Complete Code (which works without the erroneous part ^ ) <?php session_start(); ?> <html> <head> <title> <?php include "db.php"; $result=mysql_query("SELECT * FROM rpg WHERE player='{$_SESSION['username']}'") or die(mysql_error()); while($row=mysql_fetch_array($result)){ echo $row['species']; } ?> Shop </title> <style type="text/css"> body{ background-color: #000; font-family: Arial, Tahoma; font-size: .78em; } fieldset{ padding: 10px; margin: 10px; border: 1px solid #57626B; width: 60%; float: left; } legend{ background-color: #6A8CA5; border: 1px solid #000; padding: 5px; } input{ font-style: italic; } #tester{ background-color: #333; margin: 0 auto; padding: 10px; width: 70%; height: 99%; } #stats{ float: left; width: 25%; font-style: italic; color: #000; padding: 5px; border: 1px dashed #999; } table{ width: 98%; border: 2px solid #000; text-align: center; } </style> </head> <body> <div id="tester"> <?php //Shop script designed by Cetanu of http://mythscape.freezoka.com and http://tehfreerpg.proboards.com //This script is licensed by the Creative Commons for: Sharing, Attribution, Non-derivative, and non-commercial. //You MUST leave these notices in for LEGAL use of this script. YOU MAY NOT EDIT THIS SCRIPT LEGALLY. //For more: http://creativecommons.org/licenses/by-nc-nd/3.0/us/ include "db.php"; $result=mysql_query("SELECT * FROM rpg WHERE player='{$_SESSION['username']}'") or die(mysql_error()); while($row=mysql_fetch_array($result)){ if($row['species']=="Alien"){ echo "Welcome to the <strong>Alien Shop</strong>, ".$row['name'].". You currently have ".$row['money']." in money!<div style='text-align: right; font-weight: bold;'> <a href='cpanel.php'>Control Panel</a></div><br/> "; echo "<table><tr><td><strong>Item Name</strong></td> <td> <strong>Item Description</strong> </td><td> <strong>Quantity</strong></td><td><strong>Price</strong></td><td><strong> BUY!</strong></tr>"; include "db.php"; $result_shop=mysql_query("SELECT * FROM shop WHERE species='Alien'") or die(mysql_error()); while($row_shop=mysql_fetch_array($result_shop)){ echo "<tr><td style='background-color: rgb(22, 36, 45);'>".$row_shop['item_name']."</td><td style='background-color: #57626B;'>".$row_shop['item_description']."</td> <td style='background-color: rgb(22, 36, 45);'>".$row_shop['quantity']."</td><td style='background-color: #57626B;'>".$row_shop['price']."</td><td style='background-color: rgb(22, 36, 45);'> <form action='shop.php' method='post'> <input type='radio' name='BuyA' value='".$row_shop['item_name']."'/></td></tr>"; } echo "</table>"; echo "<br/><input type='submit' name='buyA' value='Confirm'/> </form>"; if($_POST['buyA'] && $_POST['BuyA']){ include "db.php"; $result_shop=mysql_query("SELECT * FROM shop WHERE species='Alien'") or die(mysql_error()); while($row_shop=mysql_fetch_array($result_shop)){ if($row_shop['item_name']=='Acidic Frenzy'){ $i=$row['money']; $w=$row_shop['price']; if($i < $w){ echo "You cannot buy this item! You do not have enough money!!!"; } if($row_shop['quantity']=='0'){ echo "Sorry, we're out of ".$row_shop['item_name']." please wait for us to re-stock the shop."; } if($i >= $w){ $purchased='Acidic Frenzy'; $money=$row['money']-1000; mysql_query("UPDATE rpg SET purchased='{$purchased}' , money='{$money}' WHERE player='{$_SESSION['username']}'"); mysql_query("UPDATE shop SET quantity='{$quant}' WHERE item_name='{$row_shop['item_name']}'"); echo $row_shop['item_name']." Purchased."; } //acidic frenzy close } //$row shop close } //if post buy } //predator } //player row if($row['species']=="Predator"){ echo "Welcome to the <strong>Predator Shop</strong>, ".$row['name'].". You currently have ".$row['money']." in money!<div style='text-align: right; font-weight: bold;'> <a href='cpanel.php'>Control Panel</a></div><br/> "; echo "<table><tr><td><strong>Item Name</strong></td> <td> <strong>Item Description</strong> </td><td> <strong>Quantity</strong></td><td><strong>Price</strong></td><td><strong> BUY!</strong></tr>"; include "db.php"; $result_shop=mysql_query("SELECT * FROM shop WHERE species='Predator'") or die(mysql_error()); while($row_shop=mysql_fetch_array($result_shop)){ echo "<tr><td style='background-color: rgb(22, 36, 45);'>".$row_shop['item_name']."</td><td style='background-color: #57626B;'>".$row_shop['item_description']."</td> <td style='background-color: rgb(22, 36, 45);'>".$row_shop['quantity']."</td><td style='background-color: #57626B;'>".$row_shop['price']."</td><td style='background-color: rgb(22, 36, 45);'> <form action='shop.php' method='post'> <input type='radio' name='Buy' value='".$row_shop['item_name']."'/></td></tr>"; } echo "</table>"; echo "<br/><input type='submit' name='buyP' value='Confirm'/> </form>"; if($_POST['buyP'] && $_POST['Buy']){ include "db.php"; $result_shop=mysql_query("SELECT * FROM shop WHERE species='Predator'") or die(mysql_error()); while($row_shop=mysql_fetch_array($result_shop)){ if($row_shop['item_name']=='Extended Wristblades'){ $i=$row['money']; $w=$row_shop['price']; if($i < $w){ echo "You cannot buy this item! You do not have enough money!!!"; } if($row_shop['quantity']=='0'){ echo "Sorry, we're out of ".$row_shop['item_name']." please wait for us to re-stock the shop."; } if($i >= $w){ $attack=$row['attack']+5; $money=$row['money']-450; $quant=$row_shop['quantity']-1; mysql_query("UPDATE rpg SET attack='{$attack}' , money='{$money}' WHERE player='{$_SESSION['username']}'"); mysql_query("UPDATE shop SET quantity='{$quant}' WHERE item_name='{$row_shop['item_name']}'"); echo $row_shop['item_name']." Purchased."; } //wristblades close if($row_shop['item_name']=='Plasmacaster'){ $i=$row['money']; $w=$row_shop['price']; if($i < $w){ echo "You cannot buy this item! You do not have enough money!!!"; } if($row_shop['quantity']=='0'){ echo "Sorry, we're out of ".$row_shop['item_name']." please wait for us to re-stock the shop."; } if($i >= $w){ $attack=$row['attack']+20; $money=$row['money']-2500; $quant=$row_shop['quantity']-1; mysql_query("UPDATE rpg SET attack='{$attack}' , money='{$money}' WHERE player='{$_SESSION['username']}'"); mysql_query("UPDATE shop SET quantity='{$quant}' WHERE item_name='{$row_shop['item_name']}'"); echo $row_shop['item_name']." Purchased."; } //plasmacaster close } //$row shop close } //if post buy } //predator } //player row } //mysterious & required if($row['species']=="Marine"){ echo "Welcome to the <strong>Marine Shop</strong>, ".$row['name'].". You currently have ".$row['money']." in money!<div style='text-align: right; font-weight: bold;'> <a href='cpanel.php'>Control Panel</a></div><br/> "; echo "<table><tr><td><strong>Item Name</strong></td> <td> <strong>Item Description</strong> </td><td> <strong>Quantity</strong></td><td><strong>Price</strong></td><td><strong> BUY!</strong></tr>"; include "db.php"; $result_shop=mysql_query("SELECT * FROM shop WHERE species='Marine'") or die(mysql_error()); while($row_shop=mysql_fetch_array($result_shop)){ echo "<tr><td style='background-color: rgb(22, 36, 45);'>".$row_shop['item_name']."</td><td style='background-color: #57626B;'>".$row_shop['item_description']."</td> <td style='background-color: rgb(22, 36, 45);'>".$row_shop['quantity']."</td><td style='background-color: #57626B;'>".$row_shop['price']."</td><td style='background-color: rgb(22, 36, 45);'> <form action='shop.php' method='post'> <input type='radio' name='BuyM' value='".$row_shop['item_name']."'/></td></tr>"; } echo "</table>"; echo "<br/><input type='submit' name='buyM' value='Confirm'/> </form>"; if($_POST['buyM'] && $_POST['BuyM']){ include "db.php"; $result_shop=mysql_query("SELECT * FROM shop WHERE species='Marine'") or die(mysql_error()); while($row_shop=mysql_fetch_array($result_shop)){ if($row_shop['item_name']=='Rocket Launcher'){ $i=$row['money']; $w=$row_shop['price']; if($i < $w){ echo "You cannot buy this item! You do not have enough money!!!"; } if($row_shop['quantity']=='0'){ echo "Sorry, we're out of ".$row_shop['item_name']." please wait for us to re-stock the shop."; } if($i >= $w){ $attack=$row['attack']+5; $money=$row['money']-450; $quant=$row_shop['quantity']-1; mysql_query("UPDATE rpg SET attack='{$attack}' , money='{$money}' WHERE player='{$_SESSION['username']}'"); mysql_query("UPDATE shop SET quantity='{$quant}' WHERE item_name='{$row_shop['item_name']}'"); echo $row_shop['item_name']." Purchased."; if(isset($_SESSION['username']=="Admin" || $_SESSION['user_id']=="Cetanu" || $_SESSION['user_id']=="Chris P")){ echo "<form action='shop.php' method='post'> Adding an Item<br/> Name: <input type='text' maxlength='30' name='name'/><br/> Description:<br/> <textarea rows='50' cols='50' name='description'>Be sure to remember the +attack, -attack, etc.</textarea><br/> Quantity: <input type='text' name='quant'/><br/> Price: <input type='text' name='price'/> <br/> <select name='species'> <option value='Predator'>Predator</option> <option value='Alien'>Alien</option> <option value='Marine'>Marine</option> </select><br/> <input type='submit' name='add' value='Confirm Add'/> | <input type='reset' value='Reset'/> </form> "; if(isset($_POST['add'])){ mysql_query("INSERT INTO shop (`item_name`, `item_description`, `price`, `quantity`, `species`) VALUES('{$_POST['name']}', '{$_POST['description']}', '{$_POST['price']}', '{$_POST['quant']}', '{$_POST['species']}'"); echo "<script>alert('Item Added');</script>"; } } } //rpg close } //$row shop close } //if post buy } //predator } //player row } //mysterious & required ?> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted August 28, 2009 Share Posted August 28, 2009 if (isset($_SESSION['username']) && ($_SESSION['username'] == "Admin" || $_SESSION['user_id'] == "Cetanu" || $_SESSION['user_id'] == "Chris P")) { ... } Quote Link to comment Share on other sites More sharing options...
Cetanu Posted August 28, 2009 Author Share Posted August 28, 2009 Still nothing. Quote Link to comment Share on other sites More sharing options...
ReKoNiZe Posted August 28, 2009 Share Posted August 28, 2009 Try putting parens around everything in your if statement. Like so: if(isset(($_SESSION['username']=="Admin") || ($_SESSION['user_id']=="Cetanu") || ($_SESSION['user_id']=="Chris P"))){ Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted August 28, 2009 Share Posted August 28, 2009 Should $_SESSION['user_id'] be $_SESSION['username'] Quote Link to comment Share on other sites More sharing options...
Cetanu Posted August 28, 2009 Author Share Posted August 28, 2009 @Mark no, because I am designing this script for someone else. They user user_id and I user username, so I can test it in my database and then give it to them. I've already tried to get rid of the user_id statements, but it still doesn't work. Quote Link to comment Share on other sites More sharing options...
ReKoNiZe Posted August 28, 2009 Share Posted August 28, 2009 Try seperating everything in parenthesis. That is usually the issue with longer if statements like that. Quote Link to comment Share on other sites More sharing options...
Cetanu Posted August 28, 2009 Author Share Posted August 28, 2009 Okay I'll let you know how that goes... Quote Link to comment Share on other sites More sharing options...
Cetanu Posted August 28, 2009 Author Share Posted August 28, 2009 UPDATE: Didn't work. Quote Link to comment Share on other sites More sharing options...
ReKoNiZe Posted August 28, 2009 Share Posted August 28, 2009 Did you try any of them by themselves? Example: if(isset($_SESSION['username'] == "Admin")) And try each one individually to see if its working at all. Quote Link to comment Share on other sites More sharing options...
Cetanu Posted August 28, 2009 Author Share Posted August 28, 2009 I did try them individually to see, it didn't. I think the error is in the if statement that contains the INSERT. Quote Link to comment Share on other sites More sharing options...
ReKoNiZe Posted August 28, 2009 Share Posted August 28, 2009 Must be an issue with the session then if none of them work. Quote Link to comment Share on other sites More sharing options...
Cetanu Posted August 28, 2009 Author Share Posted August 28, 2009 There's nothing wrong with my syntax anywhere?! Quote Link to comment Share on other sites More sharing options...
ReKoNiZe Posted August 28, 2009 Share Posted August 28, 2009 Have it echo the session username to you to see what the current username is then. Quote Link to comment Share on other sites More sharing options...
Cetanu Posted August 28, 2009 Author Share Posted August 28, 2009 Well I know that it's the right session, but look at the page: http://mythscape.freezoka.com/chrisrpg/shop.php It's nothingness, and that only happens when there's an error in my code. Quote Link to comment Share on other sites More sharing options...
Cetanu Posted August 28, 2009 Author Share Posted August 28, 2009 I got it! Fixed. It was an issue with using isset() with $_SESSION I guess. Quote Link to comment 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.