experience30 Posted May 1, 2012 Share Posted May 1, 2012 My database has a Product field which will change from holding a single product, to multiple products. How can i amend the product check in the attached code so it checks if the product is in the string? The product in the database appears as 1001, however in the new database it will appear with multiple products such as 1001,1002,1003,1004 <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="pass"; // Mysql password $db_name="sales"; // Database name $tbl_name="orders"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $CustomerEmail=$_POST['CustomerEmail']; $IsPaid="-1"; $Product="1001"; // To protect MySQL injection (more detail about MySQL injection) $CustomerEmail = stripslashes($CustomerEmail); $IsPaid = stripslashes($IsPaid); $Product = stripslashes($Product); $CustomerEmail = mysql_real_escape_string($CustomerEmail); $IsPaid = mysql_real_escape_string($IsPaid); $Product = mysql_real_escape_string($Product); $sql="SELECT * FROM $tbl_name WHERE CustomerEmail='$CustomerEmail' and IsPaid='$IsPaid' and Product='$Product'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $CustomerEmail, table row must be 1 row Link to comment https://forums.phpfreaks.com/topic/261923-how-do-i-amend-this/ Share on other sites More sharing options...
litebearer Posted May 1, 2012 Share Posted May 1, 2012 Not a good idea to have multiple values in one field; however, if you insist on using that method look into LIKE http://www.freewebmasterhelp.com/tutorials/phpmysql/8 Link to comment https://forums.phpfreaks.com/topic/261923-how-do-i-amend-this/#findComment-1342145 Share on other sites More sharing options...
experience30 Posted May 1, 2012 Author Share Posted May 1, 2012 Thank you that did the job $sql="SELECT * FROM $tbl_name WHERE CustomerEmail='$CustomerEmail' and IsPaid='$IsPaid' and Product LIKE'%$Product%'"; Link to comment https://forums.phpfreaks.com/topic/261923-how-do-i-amend-this/#findComment-1342153 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.