hello every one i have one small doubt i have the following code
i want the user to enter the coupon code which has been randomly generated and saved in database now i want that when user enter the coupon code it is cross checked from database i.e entered coupon exist or not
// html form
<form method="post" action="ted.php">
Enter The Coupon Code:<br />
<input name="code" type="text" size="10" />
<br />
<input type="submit" name="submit" value="submit" onclick="coupval =this.form.coupcode.value; ChkCoup();" />
</form>
//php script
<?php
$db=new mysqli('localhost','root','','shop');
if(mysqli_connect_errno()){
echo 'Could not connect to database:Plz try After Some time..';
exit;
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
if(isset($_POST['submit'])){
$code=isset($_POST['code']);
if($code!=""){
$qry="select code from code";
$result=$db->query($qry);
$row=array();
while ($row[]=mysqli_fetch_array($result))
{
if($code==$row['code']) {
echo "sucess,discount granted";
}
else echo "fail";
}
// Free result set
mysqli_free_result($result);
}
}
?>
plz help me with this....