如何验证表中的列

时间:2014-03-09 08:08:18

标签: php mysql

如何验证表格中的列 答案是肯定或否定

pica--> gallery -->
pic1             pic2                pic3        pic4       password_del
picture1.jpg picture2.jpg    picture3.jpg    picture4.jpg     1234567890

我想要

$con=mysqli_connect("localhost","user_name","password","pica");
// Check connection
if (mysqli_connect_errno($con))
  {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT count(*) as count FROM gallery WHERE id = 1 AND password_del = '1234567890";
$rs= $mysqli->query($sql); 
if ($rs > 0){
echo "find";
}
else{
echo 'not find';
}

如果密码存在与否,我不会收到任何通知 怎么了?

2 个答案:

答案 0 :(得分:0)

您正在使用面向对象的mysqli面向方法。如果你想使用$ mysql对象,那么你必须通过这种语法连接

$mysqli = new mysqli("localhost", "my_user", "my_password", "my_db");

回答你的问题

$con=mysqli_connect("localhost","user_name","password","pica");
// Check connection
if (mysqli_connect_errno($con))
{
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT count(*) as counter FROM gallery WHERE id = 1 AND password_del = '1234567890' ";

$rs= mysqli_query($con,$sql); 
$rows = mysqli_fetch_assoc($rs);
$row_count= $rows['counter'];

if (($row_count) > 0){
  echo "found";
}   
else{
  echo 'not found';
}

答案 1 :(得分:-1)

通过在倒置逗号之前添加'来纠正您的查询。

$mysqli= new mysqli("localhost","root","","test");
// Check connection
if (mysqli_connect_errno($mysqli))
  {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
 $sql = "SELECT count(*) as count FROM gallery WHERE id = 1 AND password_del = '1234567890'";
$rs =   $mysqli->query($sql);
$num_row = mysqli_fetch_assoc($rs);
$row_cnt = $num_row['count'];
if (($row_cnt) > 0){
echo "find";
}
else{
echo 'not find';
}

Reference