Jump to content

[SOLVED] Simple Problem


Cetanu

Recommended Posts

I've been tinkering with this forever and haven't seen any errors, but the page goes white (aka fatal error :D )

 

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

Link to comment
Share on other sites

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> 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.