Reputation: 23
yesterday i was doing work in php mysql i wrote a query
mysql_query("INSERT INTO `first` (`firstName`, `lastName`, `address1`, `city`, `state`, `zip`, `country`, `amount`, `date`) VALUES ('$firstName','$lastName','$address1','$city','$state','$zip','$country','$amount','$date')")
it did not work for me and then my boss wrote below query
mysql_query("INSERT INTO `first` (`firstName`, `lastName`, `address1`, `city`, `state`, `zip`, `country`, `amount`, `date`) VALUES ('".$firstName."','".$lastName."','".htmlentities($address1)."','".$city."','".$state."','".$zip."','".$country."','".$amount."','".$date."')");
and it works!!
is there anything wrong in first query..please help me out..
Upvotes: 0
Views: 109
Reputation: 2596
First query should work, but you got probably quotes in the content of your variables. Also, always use atleast mysql_real_escape_string. https://www.php.net/mysql_real_escape_string
Or even better, use PDO http://php.net/manual/en/book.pdo.php
Upvotes: 3
Reputation: 2493
This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.
Upvotes: 0