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 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿