Jump to content

[SOLVED] Simple querry question....


dewey_witt

Recommended Posts

Does anyone see whats wrong with this?

<?php
$rand = "SELECT * FROM `magic_cards` 
ORDER BY RAND() LIMIT 0,3;";
$card= mysql_query($rand, $connection) 
or die (mysql_error());
if (mysql_num_rows($card) > 0) {
while 
($row = mysql_fetch_array($card))  {
$card_name = stripslashes($row['card_name']);
$edition = $row['edition'];
$Rarity = $row['Rarity'];
$cond = $row['cond'];
$image = stripslashes($row['image_name']);
$ed .= mysql_query
("INSERT  INTO `qm_cards` (`Fname`, `Lname`, `Username`, `card_name`, 
`Rarity`, `Condition`, `Edition`)
VALUES 
( '".$_POST['Fname']."','".$_POST['Lname']."',
'".$_POST['Username']."', '$card_name', '$Rarity', '$cond', '$edition')", $connection) or die(mysql_error());	
}
}

?>

The error Im getting is:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's Tome', 'Rare', 'Near Mint', 'Tempest')' at line 1

Any help greatly appriciated...

Link to comment
Share on other sites

<?php
$rand = "SELECT * FROM `magic_cards` ORDER BY RAND() LIMIT 0,3";
$card= mysql_query($rand, $connection) or die (mysql_error());

while($row = mysql_fetch_array($card))  {
   $card_name = mysql_real_escape_string(stripslashes($row['card_name']));
   $edition = mysql_real_escape_string($row['edition']);
   $Rarity = mysql_real_escape_string($row['Rarity']);
   $cond = mysql_real_escape_string($row['cond']);
   $image = mysql_real_escape_string(stripslashes($row['image_name']));
   $ed = mysql_query("INSERT  INTO `qm_cards` (`Fname`, `Lname`, `Username`, `card_name`, `Rarity`, `Condition`, `Edition`) VALUES ( '".mysql_real_escape_string($_POST['Fname'])."','".mysql_real_escape_string($_POST['Lname'])."',
'".mysql_real_escape_string($_POST['Username'])."', '$card_name', '$Rarity', '$cond', '$edition')", $connection) or die(mysql_error());	
}
?>

 

Just a quick cleanup, try it.

Link to comment
Share on other sites

Please don't post twice right away. You could have updated your original post. Also, post MySQL related problems in the mysql area. I'm moving it there.

 

Use http://us2.php.net/manual/en/function.mysql-real-escape-string.php

 

on any input you receive from a form.

 

Help yourself debug this by displaying the query and looking at it and trying it outside of PHP.

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.