dongxun1244 2012-10-04 20:28
浏览 52
已采纳

mysqli存储php变量不值

This is driving me nuts. I am using the jQuery image upload and crop from http://www.webmotionuk.co.uk/php-jquery-image-upload-and-crop/

I am using a modified version of the suggestion on here to store the file location in a MySQL database. The mod is that I use INSERT on a table it works great except one thing, the 'owner' variable $id is being stored as $id and not as the value of $id. I can echo the value if $id on each $_POST so I know it's there.

I am pretty sure my syntax is correct but I don't understand why it is doing this.

    $cropped = resizeThumbnailImage($thumb_image_location, $large_image_location,$w,$h,$x1,$y1,$scale);
    //connect to the database
    include 'config.php';
    // check connection
    if (mysqli_connect_errno()) {
        exit('Connect failed: '. mysqli_connect_error());
    } 
    $sql = "INSERT INTO `photos` (`id`,`owner`,`url`) VALUES ('id','".$id."','".$thumb_image_location."')";
    // Performs the $sql query on the server to insert the values
    if ($conn->query($sql) === TRUE) {
        $conn->close();}
//Reload the page again to view the thumbnail
header("location:".$_SERVER["PHP_SELF"]);
exit();

The first line is 246 and the last 3 are the orginal 247-250.

Thanks for any help you can provide.

Ok, I don't know if this is my brain fart or an issue with PHP or a bit of both. I have $id assigned from the _SESSION variable in the header of each page AND (having forgotten that) I was passing $id as _POST data (same value). Once I cut out the _POST data passing and just pulled the _SESSION variable it works fine. But assigning a variable multiple times shouldn't be an issue, should it?

  • 写回答

1条回答 默认 最新

  • dongsha1544 2012-10-04 20:37
    关注

    the query line needs to be like this:

    $sql = "INSERT INTO `photos` (`id`,`owner`,`url`) VALUES ('id','$id','$thumb_image_location')";
    

    your syntax works fine too, as seen here

    this is how my syntax works, here

    Note: both work the same, so still trying to figure out what's wrong in OP's code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错