Help with PHP problem
Moderator: General Moderators
Help with PHP problem
Recently I switched server host sites. All my scripts were running fine on the first site. Now they aren't. Any script with the if command doesn't work.
Example
if ($check_cd[money] >= $keys[value]) {
$check_item = mysql_fetch_array(mysql_query("select * from stockkey where itemIdent ='Key_$key'"));
if ($check_item[stockNumber] > 0) {
$new_item_delete = "update stockkey set stockNumber = stockNumber - 1 where itemIdent ='Key_$key'";
mysql_query($new_item_delete);
$new_item_delete2 = "update critter_bank set money = money - $keys[value] where user_name='$user'";
mysql_query($new_item_delete2);
For some reason the if command isn't being implemented at all. Can anybody help me out with this?
Example
if ($check_cd[money] >= $keys[value]) {
$check_item = mysql_fetch_array(mysql_query("select * from stockkey where itemIdent ='Key_$key'"));
if ($check_item[stockNumber] > 0) {
$new_item_delete = "update stockkey set stockNumber = stockNumber - 1 where itemIdent ='Key_$key'";
mysql_query($new_item_delete);
$new_item_delete2 = "update critter_bank set money = money - $keys[value] where user_name='$user'";
mysql_query($new_item_delete2);
For some reason the if command isn't being implemented at all. Can anybody help me out with this?
Thanks
I'm not a serious expert on PHP code unfortunately other than writing a few scripts. Yes, an idiot like me actually bought her own domain and is trying to run it..hrmmm. And tearing my hair out too. I know the host site supports PHP 4 and that's about it. I didn't post the whole script since I figured that would waste space here.
Full Code
I'm doing a google search too, to try to learn about turning on the global register.
Code: Select all
<?php
ob_start();
session_start();
include ('dbconn2.php');
$keys = mysql_fetch_array(mysql_query("select * from store_1 where name='Key $key'"));
if ($keys[name] == "") {
$key="";
}
?>
<html>
<head>
<title><?php echo $keys[name]; ?></title>
<style type=text/css>
A{COLOR:#FF0018;FONT-FAMILY:verdana,arial,helvetica;FONT-SIZE:10pt;TEXT-DECORATION:none}
TD,P,body{FONT-FAMILY:verdana,arial,helvetica;FONT-SIZE:10pt;}
A:hover{COLOR:#555555;}
</style></head>
<body bgcolor=#ffffff marginwidth=0 marginheight=0 leftmargin=0 topmargin=0>
<?php
if ($key) {
?>
<center><img src="/images/keys/key<?php echo $key; ?>.gif" width=50 height=50><p>
<b>Name</b>: <?php echo $keys[name]; ?><br>
<b>Store</b>: <?php echo $keys[store]; ?><br>
<b>Value</b>: <?php echo $keys[value]; ?> CD<br>
<b>Use</b>: <?php echo $keys[used]; ?></center></p>
<?php
if ($buy == "yes") {
$user = $HTTP_SESSION_VARS['critter_user'];
$check_cd = mysql_fetch_array(mysql_query("select * from critter_bank where user_name='$user'"));
if ($check_cd[money] >= $keys[value]) {
$check_item = mysql_fetch_array(mysql_query("select * from stockkey where itemIdent ='Key_$key'"));
if ($check_item[stockNumber] > 0) {
$new_item_delete = "update stockkey set stockNumber = stockNumber - 1 where itemIdent ='Key_$key'";
mysql_query($new_item_delete);
$new_item_delete2 = "update critter_bank set money = money - $keys[value] where user_name='$user'";
mysql_query($new_item_delete2);
$check_userBag = mysql_fetch_array(mysql_query("select count(*) as checks from userBag where user_name='$user'"));
if ($check_userBag[checks] == "0" || $check_userBag[checks] == "") {
$new_item_insert = "INSERT INTO userBag(user_name, key{$key}) VALUES('$user', '1')";
mysql_query($new_item_insert);
} else {
$new_item_update = "update userBag set key{$key} = key{$key} + 1 where user_name='$user'";
mysql_query($new_item_update);
}
print "<p align='center'>Key has been bought successfully!</p>";
} else {
print "<p align='center'>That item is out of stock!</p>";
}
} else {
print "<p align='center'>You don't have enough CD for that.</p>";
}
} else {
?>
<center>Sure you want to buy this?</font><p>
<table align=center border=0 cellpadding=4>
<tr><td align=center valign=center>
<?php
echo "<form action='keyindex.php?buy=yes&key=$key' method='post'><input type='submit' value='Yes'>
</form>\n";
?>
<form action="/store.php?items=keys" method="post">
<input type="submit" value="No">
</form>
<p>
<?php
}
}
?>
<p><center><a href="/store.php?items=keys">Back to Store</a></center><p>
</body>
</html>
<?php
ob_end_flush();
?>Page Submitting to prior code
Code: Select all
<?php
include 'user_check.php';
?>
<?
include("header.php");
?>
<?
include("message.php");
?>
<P></P>
<center><font size="5"><b>Key Store</b></font></center>
<p>
<form name='refreshform' method='get'><input type='hidden' name='type' value='store'><input type='hidden' name='obj_type' value='1'></form><center><a href='store.php?items=keys'><img src='images/keyfairy.gif' width=150 height=150 alt= "Arilia Keykeeper" border=0></a><p>
<table align=center border=0 width=615 cellpadding=1 cellspacing=0>
The store restocks everyday at noon. To buy an item, click on the image.<p>
<table align=center cellpadding=2 border=0><tr>
<?php
include("dbconn.php");
$query = "select imagePic, itemName, itemCost, stockNumber from stockkey LIMIT 0,1";
$result = mysql_query($query) or
die(mysql_error());
while (list ($imagePic, $itemName, $itemCost, $stockNumber) =mysql_fetch_array($result))
{
echo "<td width=120 align=center valign=top>\n";
echo "<a href='http://www.bysable.com/Critteropia/keyindex.php?key=1'>\n";
echo "<img src='http://www.bysable.com/Critteropia/images/\n";
echo $imagePic . ".gif' width=100 height=100 border=0 alt='\n";
echo $itemName . "'></a><br><b>\n";
echo $itemName . "</b><br>\n";
echo $itemCost . " CD<br>\n";
echo $stockNumber . " available</td>\n";
}
$query = "select imagePic, itemName, itemCost, stockNumber from stockkey LIMIT 1,1";
$result = mysql_query($query) or
die(mysql_error());
while (list ($imagePic, $itemName, $itemCost, $stockNumber) =mysql_fetch_array($result))
{
echo "<td width=120 align=center valign=top>\n";
echo "<a href='http://www.bysable.com/Critteropia/keyindex.php?key=2'>\n";
echo "<img src='http://www.bysable.com/Critteropia/images/\n";
echo $imagePic . ".gif' width=100 height=100 border=0 alt='\n";
echo $itemName . "'></a><br><b>\n";
echo $itemName . "</b><br>\n";
echo $itemCost . " CD<br>\n";
echo $stockNumber . " available</td>\n";
}
$query = "select imagePic, itemName, itemCost, stockNumber from stockkey LIMIT 2,1";
$result = mysql_query($query) or
die(mysql_error());
while (list ($imagePic, $itemName, $itemCost, $stockNumber) =mysql_fetch_array($result))
{
echo "<td width=120 align=center valign=top>\n";
echo "<a href='http://www.bysable.com/Critteropia/keyindex.php?key=3'>\n";
echo "<img src='http://www.bysable.com/Critteropia/images/\n";
echo $imagePic . ".gif' width=100 height=100 border=0 alt='\n";
echo $itemName . "'></a><br><b>\n";
echo $itemName . "</b><br>\n";
echo $itemCost . " CD<br>\n";
echo $stockNumber . " available</td>\n";
}
$query = "select imagePic, itemName, itemCost, stockNumber from stockkey LIMIT 3,1";
$result = mysql_query($query) or
die(mysql_error());
while (list ($imagePic, $itemName, $itemCost, $stockNumber) =mysql_fetch_array($result))
{
echo "<td width=120 align=center valign=top>\n";
echo "<a href='http://www.bysable.com/Critteropia/keyindex.php?key=4'>\n";
echo "<img src='http://www.bysable.com/Critteropia/images/\n";
echo $imagePic . ".gif' width=100 height=100 border=0 alt='\n";
echo $itemName . "'></a><br><b>\n";
echo $itemName . "</b><br>\n";
echo $itemCost . " CD<br>\n";
echo $stockNumber . " available</td>\n";
}
$query = "select imagePic, itemName, itemCost, stockNumber from stockkey LIMIT 4,1";
$result = mysql_query($query) or
die(mysql_error());
while (list ($imagePic, $itemName, $itemCost, $stockNumber) =mysql_fetch_array($result))
{
echo "<td width=120 align=center valign=top>\n";
echo "<a href='http://www.bysable.com/Critteropia/keyindex.php?key=5'>\n";
echo "<img src='http://www.bysable.com/Critteropia/images/\n";
echo $imagePic . ".gif' width=100 height=100 border=0 alt='\n";
echo $itemName . "'></a><br><b>\n";
echo $itemName . "</b><br>\n";
echo $itemCost . " CD<br>\n";
echo $stockNumber . " available</td></tr>\n";
}
$query = "select imagePic, itemName, itemCost, stockNumber from stockkey LIMIT 5,1";
$result = mysql_query($query) or
die(mysql_error());
while (list ($imagePic, $itemName, $itemCost, $stockNumber) =mysql_fetch_array($result))
{
echo "<td width=120 align=center valign=top>\n";
echo "<a href='http://www.bysable.com/Critteropia/keyindex.php?key=6'>\n";
echo "<img src='http://www.bysable.com/Critteropia/images/\n";
echo $imagePic . ".gif' width=100 height=100 border=0 alt='\n";
echo $itemName . "'></a><br><b>\n";
echo $itemName . "</b><br>\n";
echo $itemCost . " CD<br>\n";
echo $stockNumber . " available</td>\n";
}
$query = "select imagePic, itemName, itemCost, stockNumber from stockkey LIMIT 6,1";
$result = mysql_query($query) or
die(mysql_error());
while (list ($imagePic, $itemName, $itemCost, $stockNumber) =mysql_fetch_array($result))
{
echo "<td width=120 align=center valign=top>\n";
echo "<a href='http://www.bysable.com/Critteropia/keyindex.php?key=7'>\n";
echo "<img src='http://www.bysable.com/Critteropia/images/\n";
echo $imagePic . ".gif' width=100 height=100 border=0 alt='\n";
echo $itemName . "'></a><br><b>\n";
echo $itemName . "</b><br>\n";
echo $itemCost . " CD<br>\n";
echo $stockNumber . " available</td>\n";
}
$query = "select imagePic, itemName, itemCost, stockNumber from stockkey LIMIT 7,1";
$result = mysql_query($query) or
die(mysql_error());
while (list ($imagePic, $itemName, $itemCost, $stockNumber) =mysql_fetch_array($result))
{
echo "<td width=120 align=center valign=top>\n";
echo "<a href='http://www.bysable.com/Critteropia/keyindex.php?key=8'>\n";
echo "<img src='http://www.bysable.com/Critteropia/images/\n";
echo $imagePic . ".gif' width=100 height=100 border=0 alt='\n";
echo $itemName . "'></a><br><b>\n";
echo $itemName . "</b><br>\n";
echo $itemCost . " CD<br>\n";
echo $stockNumber . " available</td></tr></table>\n";
}
?>
<?
include("footer.php");
?>how do I fix my problem? Half my scripts don't work on my site. I've tweaked some of my problems but this one I can't figure out and I've torn the scripts apart and tried to rewrite for the last 2 weeks. I can't get that if command to work for nothing. I managed to get some of my problems working if I only have one if command by using:
if($_GET['change'] == 'yes') {
$bla = true;
}
But if there is more than one if command and the script won't process at all.
if($_GET['change'] == 'yes') {
$bla = true;
}
But if there is more than one if command and the script won't process at all.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
that said, add the following to the ~top of your error'd code:
furthermore, your submitting code can be simplified to (at least):
edit: this was meant in reply to my previous post, as bysable posted inbetween my writing them
Code: Select all
$key = (isset($_GETї'key']) ? intval($_GETї'key']) : '');Code: Select all
<?php
include 'user_check.php';
include("header.php");
include("message.php");
?>
<P></P>
<center><font size="5"><b>Key Store</b></font></center>
<p>
<form name='refreshform' method='get'><input type='hidden' name='type' value='store'><input type='hidden' name='obj_type' value='1'></form><center><a href='store.php?items=keys'><img src='images/keyfairy.gif' width=150 height=150 alt= "Arilia Keykeeper" border=0></a><p>
<table align=center border=0 width=615 cellpadding=1 cellspacing=0>
The store restocks everyday at noon. To buy an item, click on the image.<p>
<table align=center cellpadding=2 border=0><tr>
<?php
include("dbconn.php");
$query = "select imagePic, itemName, itemCost, stockNumber from stockkey LIMIT 7";
$result = mysql_query($query) or
die(mysql_error());
$counter = 1;
while ($row =mysql_fetch_array($result))
{
list ($imagePic, $itemName, $itemCost, $stockNumber) = $row;
echo "<td width=120 align=center valign=top>\n";
echo "<a href='http://www.bysable.com/Critteropia/keyindex.php?key={$counter}'>\n";
echo "<img src='http://www.bysable.com/Critteropia/images/\n";
echo $imagePic . ".gif' width=100 height=100 border=0 alt='\n";
echo $itemName . "'></a><br><b>\n";
echo $itemName . "</b><br>\n";
echo $itemCost . " CD<br>\n";
echo $stockNumber . " available</td>\n";
$counter++;
}
include("footer.php");
?>edit: this was meant in reply to my previous post, as bysable posted inbetween my writing them
You can tell a not so expert wrote my scripts...meaning me, so I appreciate the help on simplifying. I learned php by tearing apart other scripts, obviously don't know it all. Since I need to leave for work, I'll implement the changes when I get home in the morning and I appreciate you taking the time to help me out with this one.
Implemented code
I put in the code you gave me and wonderfully all the information now shows up as it should. There is still a problem though since the code after buy=yes isn't being recognized. When I clicked on the buy button to process the script it goes to keyindex.php?buy=yes&key=4 (as an example) just as it should but the rest of the code doesn't work. It doesn't take CD from the user's account or put the appropriate key in the user shopping bag.