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