Jump to content

How do i amend this?


experience30

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.