保存到mysql数据库php的链接

时间:2017-05-11 15:48:02

标签: mysql sql hyperlink

我有一个html表单(对于blogposts),我想将所有内容保存在数据库表中。它工作正常,但是当我为图像添加一列时,也可以在同一个html表单中上传,那么它就不会保存任何内容。

以下是代码:

$imagepath = 'https://myurl.com/uploads/' . $_FILES['image']['name'];

  $db = new PDO($dsn, $dbuser, $dbpass);
  $query = $db->prepare(
    "INSERT INTO posts (author, title, text, date, image)
  VALUES(:author, :title, :text, NOW()), '$imagepath'");
  $query->execute(array("author" => $author, "title" => $title, "text" => $text));
  $db = null;

2 个答案:

答案 0 :(得分:0)

关闭括号错误放置

public String getGirlName(int year, int rank) { //year refers to Key
                                                //rank refers to other integer in value map 
  if (girls.containsKey(year) && girls.get(year).containsKey(rank)){ 
     //shouldn't this return the name 
     return girls.get(year).get(rank); //error here where it says I can't return an integer I have to return a string
     else return null; 
  }
}

应该是

  "INSERT INTO posts (author, title, text, date, image)
  VALUES(:author, :title, :text, NOW()), '$imagepath'");

答案 1 :(得分:0)

试试这个..

<?php

if(isset($_POST['Upload'])) // upload button press
{

$file_name = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$file_temp = $_FILES['file']['tmp_name'];

$folder = "uploads/";
$file_url="http://localhost/../../uploads/$file_name"; //file location

move_uploaded_file($file_temp,"Song_uploads/".$file_name);

$sql="INSERT INTO imagepost(file_NAME,file_URL,file_SIZE) VALUES(:file_name,:file_url,:file_size)";


    $stmt= $conn->prepare($sql);


    $stmt->bindParam(':file_name',$file_name);
    $stmt->bindParam(':file_url',$file_url);
    $stmt->bindParam(':file_size',$file_size);


    if($stmt->execute())
      {

    $message="<br/><h1> ---> "."[".$file_name."]"." File Has Been Uploaded !! </h1>";

      }
      else
      {
    $message="<br/> <h1> ---> "."[".$file_name."]"." File Not Be Uploaded !!  Please Try Again !! </h1>";
      }
}
?>