-1

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);
AdamL
  • 12,421
  • 5
  • 50
  • 74
corkalom
  • 3
  • 1
  • 5
  • If you newbie in php try to use some IDE with syntax checker, it will help in first time. – Narek Mar 21 '13 at 10:01

2 Answers2

1

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.'")';
Voitcus
  • 4,463
  • 4
  • 24
  • 40
1

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')";
Volkan
  • 2,212
  • 1
  • 14
  • 14
  • 1
    I cant get a username from session information from 1st page that I log in and choose the image. How to link veriables to another page? – corkalom Mar 21 '13 at 10:07
  • First try diagnosing your $_GET or $_POST (depending on the method you used on your page) via var_dump function... If you can not figure out what is going on, post it as another question into Stack overflow... – Volkan Mar 21 '13 at 10:42