dragon8002 2014-02-27 02:26
浏览 57
已采纳

检查表中是否存在结果时出错

So I am building a table session :

session:

session_name | *Text*
session_number | *auto_increment*

I want to check whether there is a session_name result already in the table and if there isn't add it with a unique session_number then create a session with that number and if there is add the session_number to a session:

attempt:

session_start();
ob_start();

if(isset($_POST['enter'])){
    if($_POST['name'] != ""){
        $_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
    }
}
$name = ucwords(strtolower($_SESSION['name']));

$method = "SELECT * FROM session WHERE session_name = '$name'";
$resulty = mysql_query($con, $method);
//where $con is the connection to my database
if(mysql_num_rows($resulty) == 0) {
    //not found
     $sql="INSERT INTO session (session_name)

     VALUES

     ('$name')";

}

$result = mysql_query("SELECT * FROM session WHERE session_name = '$name'");

$row = mysql_fetch_row($result);

echo $row[0]; 
echo $row[1]; // not sure which one is the session_number
mysqli_close($con);

First of all I am getting the errors

Warning: mysql_query() expects parameter 1 to be string, object given

Warning: mysql_num_rows() expects parameter 1 to be resource, null given 

How come?


And also how can I then store the session_number to another session?

  • 写回答

2条回答 默认 最新

  • doujiang6944 2014-04-29 14:16
    关注

    You have it reversed,the $query is the first parameter, the $con object is the second parameter

    $method = "SELECT * FROM session WHERE session_name = '$name'";
    $resulty = mysql_query($method, $con);
    

    please upgrade to mysqli_

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向