| Author |
Message |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2984 Location: Earth
|
Posted: Mon Dec 10, 2007 7:44 am Post subject: script that checks a field and does something |
|
|
I've done something here, which i cant find, no matter how much i look and test it
| Code: | if(isset($_POST['Submit3'])) {
$s_num2 = "SELECT * from cards where alttext = '".htmlspecialchars($_POST['3card1'])."' OR alttext = '".htmlspecialchars($_POST['3card2'])."' OR alttext = '".htmlspecialchars($_POST['3card3'])."' OR alttext = '".htmlspecialchars($_POST['3card4'])."' OR alttext = '".htmlspecialchars($_POST['3card5'])."'";
$r_num2 = mysql_query($s_num2);
while ($row = mysql_fetch_array($r_num2)) {
$alttext = $row['alttext'];
$de = "SELECT * from user_inventory where alttext = '".$alttext."'";
$deck = mysql_query($de);
while ($row = mysql_fetch_array($deck)) {
if($row['status'] == 'collecting') {
$sql = "SELECT * FROM `cards` WHERE alttext = '".$alttext."'";
$result4 = mysql_query($sql, $con);
if (!$result4) { echo( mysql_error()); }
while ($row = mysql_fetch_array($result4)) {
$update = "UPDATE user_inventory set url = '".$row['url']."' WHERE alttext = '".$alttext."' LIMIT 1";
$result = mysql_query($update);
if(!$result) { echo(mysql_error()); }
}
}
}
}
if(mysql_num_rows($deck) == 0) {
$sql1 = "SELECT * FROM `cards` WHERE alttext = '".$alttext."'";
$result1 = mysql_query($sql1, $con);
if (!$result1) { echo( mysql_error()); }
while ($row = mysql_fetch_array($result1)) {
$add = "INSERT INTO `desbrina_sw`.`user_inventory` (`ID` ,`name` ,`url` ,`alttext` ,`deck` ,`user_id` ,`card_id` ,`status` ,`worth` ,`amount` ,`type`) VALUES (NULL , '".$_COOKIE['dwtcg']['u']."', '".$row['url']."', '".$row['alttext']."', '".$row['deck']."', '".$_COOKIE['dwtcg']['i']."', '".$row['ID']."', 'undefined', '".$row['worth']."', '".$row['amount']."', '".$row['type']."')";
$result = mysql_query($add);
if(!$result) { echo(mysql_error()); }
}
}
echo "<br /><br />Cards added sucessfully";
//mysql_query("INSERT INTO `game` VALUES (NULL, 'doyouhave', '".$_COOKIE['dwtcg']['u']."', '" . $_SESSION['id'] . "')") or die(mysql_error());
} |
What its supposed to do is check to see if the card your getting is part of your collecting set, if it is, the update the existing card, if not, then it enters it as a new row
The problem is it does random things each time
Sometimes it updates, but not inserts, sometimes it doesn't insert, other times it doesn't do anything at all _________________ Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG |
|
| Back to top |
|
| |
jthomsonmain Ardent Poster

Joined: 11 Jan 2008 Posts: 80 Location: Albion, NY (USA)
|
Posted: Fri Jan 11, 2008 5:11 pm Post subject: Re: script that checks a field and does something |
|
|
| Desbrina wrote: | I've done something here, which i cant find, no matter how much i look and test it
| Code: | if(isset($_POST['Submit3'])) {
$s_num2 = "SELECT * from cards where alttext = '".htmlspecialchars($_POST['3card1'])."' OR alttext = '".htmlspecialchars($_POST['3card2'])."' OR alttext = '".htmlspecialchars($_POST['3card3'])."' OR alttext = '".htmlspecialchars($_POST['3card4'])."' OR alttext = '".htmlspecialchars($_POST['3card5'])."'";
$r_num2 = mysql_query($s_num2);
while ($row = mysql_fetch_array($r_num2)) {
$alttext = $row['alttext'];
$de = "SELECT * from user_inventory where alttext = '".$alttext."'";
$deck = mysql_query($de);
while ($row = mysql_fetch_array($deck)) {
if($row['status'] == 'collecting') {
$sql = "SELECT * FROM `cards` WHERE alttext = '".$alttext."'";
$result4 = mysql_query($sql, $con);
if (!$result4) { echo( mysql_error()); }
while ($row = mysql_fetch_array($result4)) {
$update = "UPDATE user_inventory set url = '".$row['url']."' WHERE alttext = '".$alttext."' LIMIT 1";
$result = mysql_query($update);
if(!$result) { echo(mysql_error()); }
}
}
}
}
if(mysql_num_rows($deck) == 0) {
$sql1 = "SELECT * FROM `cards` WHERE alttext = '".$alttext."'";
$result1 = mysql_query($sql1, $con);
if (!$result1) { echo( mysql_error()); }
while ($row = mysql_fetch_array($result1)) {
$add = "INSERT INTO `desbrina_sw`.`user_inventory` (`ID` ,`name` ,`url` ,`alttext` ,`deck` ,`user_id` ,`card_id` ,`status` ,`worth` ,`amount` ,`type`) VALUES (NULL , '".$_COOKIE['dwtcg']['u']."', '".$row['url']."', '".$row['alttext']."', '".$row['deck']."', '".$_COOKIE['dwtcg']['i']."', '".$row['ID']."', 'undefined', '".$row['worth']."', '".$row['amount']."', '".$row['type']."')";
$result = mysql_query($add);
if(!$result) { echo(mysql_error()); }
}
}
echo "<br /><br />Cards added sucessfully";
//mysql_query("INSERT INTO `game` VALUES (NULL, 'doyouhave', '".$_COOKIE['dwtcg']['u']."', '" . $_SESSION['id'] . "')") or die(mysql_error());
} |
What its supposed to do is check to see if the card your getting is part of your collecting set, if it is, the update the existing card, if not, then it enters it as a new row
The problem is it does random things each time
Sometimes it updates, but not inserts, sometimes it doesn't insert, other times it doesn't do anything at all |
Well, I dont know SQL, but the basic template for your program should be somthing like:
| Code: |
input variable
if variable = something
do....
|
and so on...
It sounds to me like your code may be misinterpreting the card value and doing something that you wanted it to do with a value that you didnt want to put in there. I dont know if SQL has different variable types (int, char, float...), but if you use the wrong type of variable with a command, it may try to convert and give you unexpected results. _________________ [img:8728bad64c]http://i212.photobucket.com/albums/cc118/jthomsonmain/l2psig.jpg[/img:8728bad64c] |
|
| Back to top |
|
| |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2984 Location: Earth
|
|
| Back to top |
|
| |
jthomsonmain Ardent Poster

Joined: 11 Jan 2008 Posts: 80 Location: Albion, NY (USA)
|
Posted: Mon Jan 14, 2008 3:15 pm Post subject: |
|
|
| Desbrina wrote: | | i decided i'd rewrite it, and in doing so i managed to do it in about 1/4 the amount of code |
Thats quite an accomplishment! I hope it works for you! _________________ [img:8728bad64c]http://i212.photobucket.com/albums/cc118/jthomsonmain/l2psig.jpg[/img:8728bad64c] |
|
| Back to top |
|
| |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2984 Location: Earth
|
|
| Back to top |
|
| |
|
|
|