Question

I m trying to get username ID from users database the data that I have from session is username so I have code to select username id and store it into veriable

the code I have is that it stores image string that is uploaded but only logged in users are allowed to upload image. While image is loaded I want to store userID in photo table with string to know which user added the photo

  //setting veriables
  $imagestring = $_FILES["file"]["name"];
  $filetype = $_FILES["file"]["type"];
  $sessionusername = $_SESSION['Username'];
  $description = $_POST['desc'];
  //getting user id
  $myquery = mysql_query("select UserID from users where Username = '$sessionusername'");
  $row = mysql_fetch_array($query);
  // putting data into database
  mysql_connect("$host", "$username", "$password")or die("cannot connect");
  mysql_select_db("$db_name")or die("cannot select DB");

  $sql='INSERT INTO '.$tbl_name.' (photographerID, photoDesc, PhotoString) VALUES ('$row', '$description', "k00138899.atspace.eu/photoalbum/upload/'.$imagestring.'.'.$filetype.'")';
  $result=mysql_query($sql);
Was it helpful?

Solution

You could have forgotten dots:

$sql='INSERT INTO '.$tbl_name.' (photographerID, photoDesc, PhotoString) VALUES ('$row', '$description', "k00138899.atspace.eu/photoalbum/upload/'.$imagestring.'.'.$filetype.'")';

Probably should be:

$sql='INSERT INTO '.$tbl_name.' (photographerID, photoDesc, PhotoString) VALUES ("'.$row.'", "'.$description.'", "k00138899.atspace.eu/photoalbum/upload/'.$imagestring.'.'.$filetype.'")';

OTHER TIPS

Please use mysqli interface, mysql is deprecated. And about your problem,

You have a mulformed query string, try this:

  $sql='INSERT INTO '
      .$tbl_name
      ." (photographerID, photoDesc, PhotoString) VALUES ('$row', '$description', "
      ."'k00138899.atspace.eu/photoalbum/upload/$imagestring.$filetype')";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top