I am having one table which is having 7days mon,tue...sun i am inserting some records to these fields..if i i select/enter monday or any exisiting day in drop down or text field it should say day alredy exist else开发者_JS百科 it should insert...i am using following code getting some problem with this whenever i insert values its saying day exist if i enter other day which is not existing its coming day exist..can anyone check the below code thank in advance
$dexist=$_POST['ext'];
$res=mysql_query("select Day from mess where Day='".$dexist."' ");
while($row=mysql_fetch_array($res))
{
$dy=$row['Day'];
}
if($dy==$dexist)
{
echo"<SCRIPT LANGUAGE='JavaScript'>window.alert('Day exist')</SCRIPT>";
}
else
{
mysql_query("insert into mess (Date,Day,Breakfast,StartTimeb,EndTimeb,Lunch,StartTimel,EndTimel,Dinner,StartTimed,EndTimed) values('".$date."','".$day."','".$bre."','".$bres."','".$bree."','".$lun."','".$luns."','".$lune."','".$dinn."','".$dins."','".$dine."')");
}
mysql_close($con);
Try this:
$dexist=$_POST['ext'];
$res=mysql_query("select Day from mess where Day='".$dexist."' ");
$exists = false;
while($row=mysql_fetch_array($res))
{
$dy=$row['Day'];
if($dy==$dexist)
{
$exists = true;
break;
} else {
mysql_query("insert into mess (Date,Day,Breakfast,StartTimeb,EndTimeb,Lunch,StartTimel,EndTimel,Dinner,StartTimed,EndTimed) values('".$date."','".$day."','".$bre."','".$bres."','".$bree."','".$lun."','".$luns."','".$lune."','".$dinn."','".$dins."','".$dine."')");
break;
}
}
if ( $exists ) {
echo"<SCRIPT LANGUAGE='JavaScript'>window.alert('Day exist')</SCRIPT>";
}
mysql_close($con);
Have fun..
精彩评论