简体   繁体   English

MySQL:检查行是否确实不起作用

[英]MySQL: Check if row exists does not really work

I have encountered a genuine problem which cause is uknown to me. 我遇到了真正的问题,原因不明。 I am inserting datetime into database (and some other data). 我将datetime插入数据库(和其他一些数据)中。 Script works, it is adding new records and it's just swell. 脚本有效,它正在添加新记录,而且只是膨胀。 The genuine problem is about duplicating data. 真正的问题是关于复制数据。 Even though I have this if-condition, it does not work properly :x 即使我有这个if条件,它也无法正常工作:x

$data = $year."-".$month."-".$day." ".$godzina.":".$minuta;

$result = mysql_query("SELECT * from kolejka WHERE data LIKE '$data%'");
$exists = (mysql_num_rows($result))?TRUE:FALSE;
if($exists){
    header('Location: location');
    $_SESSION['msg'] = 'text';
}else{
 $sql = "INSERT INTO kolejka (pID, mID, data, odbyta) VALUES ('$id', '$mid', '$data', '0')";
}
if (!mysql_query($sql)){
    header('Location: 'location');
    $_SESSION['msg'] = 'error';
}

here's db: 这是数据库:

D b

It's got to be done by mysql_query :> Thanks in advance for any comments 它必须由mysql_query完成:>预先感谢您的任何评论

Your problem is that by concatenating the values like that, you're not padding the numbers, so they don't match. 您的问题是,通过串联这样的值,您不会填充数字,因此它们不匹配。 ( 9:00 != 09:00) You want to create a valid date format from your variables with mktime() : (9:00!= 09:00)您想使用mktime()从变量创建有效的日期格式:

 $data = date('Y-m-d H:i', mktime ($godzina, $minuta, 0, $month, $day, $year));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM