dongshie8450 2015-12-02 09:25
浏览 31
已采纳

获取单个数据会返回错误

I'm trying to fetch couple of single data in my server database but this is throwing some errors. The incoming data is correct. The search function just don't get completed.

Here's the code:

<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
define('HOST','xxxxxxxxxxx');
define('USER','xxxxxxxxxxxx');
define('PASS','xxxxxxxxx');
define('DB','xxxxxxxxxx');
 $con = mysqli_connect(HOST,USER,PASS,DB);

 $post_id = $_POST['id'];
 $buyer_mobile = $_POST['mobile'];
 $buyer_name = $_POST['name'];

$sql = "select mobile from flatowner where id='$post_id'";
$res = mysqli_query($con,$sql);
$owner_mobile = $row['mobile'];



$sql = "select name from user where mobile='$owner_mobile'";
$r = mysqli_query($con,$sql);
$owner_name = $row['name'];
$sql = "INSERT INTO flat_booking         (post_id,owner_mobile,owner_name,buyer_mobile,buyer_name) VALUES         ('$post_id','$owner_mobile','$owner_name','$buyer_mobile','$buyer_name')";
if(mysqli_query($con,$sql)){
 echo "Success";
 }
 else{
 echo "error";
 }
mysqli_close($con);
}else{
echo 'error1';
}    

What am I doing wrong here? Maybe this:

$owner_mobile = $row['mobile'];

Thanks in advance!

  • 写回答

2条回答 默认 最新

  • doumou5109 2015-12-02 09:31
    关注

    Your problem is this line:

    $owner_mobile = $row['mobile'];
    

    You have not created the $row variable. For this you would need to do something such as:

    Do this first:

    <?php
    $row = array();
    while ($result = mysqli_fetch_assoc($res))
    {
        $row[] = $result;
    }
    ?>
    

    This allows you to do this:

    <?php
    foreach ($row as $r)
    {
        var_dump($r); print "<br />"; // One row from the DB per var dump
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。