punky79 Posted March 4, 2008 Share Posted March 4, 2008 Error: Unknown column 'Jordan' in 'where clause' My code: $v=UPLOAD_DIR.$_SESSION['MM_Username'].'/'.$now.$_SESSION['MM_Username'].'-'.$file; //copy image to database $sql = "SELECT user_id FROM user WHERE username = ".$_SESSION['MM_Username'].""; $queryresult = mysql_query($sql) or die (mysql_error()); if (mysql_num_rows($queryresult) > 0) { $row=mysql_fetch_assoc($queryresult); $userid=$row['user_id']; } $resins=mysql_query("INSERT INTO gallery (user_id, image_name) VALUES ($userid,'$v'") or die("Error in INSERT: ".mysql_error()); The only place I can see it is getting the name 'Jordan' is from the session name .$_SESSION['MM_Username']. Can anyone help with this... If more of my code is need I can post the whole script. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 4, 2008 Share Posted March 4, 2008 Try this: $sql = "SELECT user_id FROM user WHERE `username` = '".$_SESSION['MM_Username']."'"; Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted March 4, 2008 Share Posted March 4, 2008 Pesky code!... Few errors! Try this: <?php $v=UPLOAD_DIR.$_SESSION['MM_Username'].'/'.$now.$_SESSION['MM_Username'].'-'.$file; //copy image to database $sql = "SELECT `user_id` FROM user WHERE `username` = '".$_SESSION['MM_Username']."'"; $queryresult = mysql_query($sql) or die (mysql_error()); if (mysql_num_rows($queryresult) > 0) { $row=mysql_fetch_assoc($queryresult); $userid=$row['user_id']; } $resins=mysql_query("INSERT INTO gallery ('user_id', 'image_name') VALUES ('$userid','$v'") or die("Error in INSERT: ".mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
punky79 Posted March 4, 2008 Author Share Posted March 4, 2008 Thanks little guy.... When i try yours I get this error "Error in INSERT: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1" Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 4, 2008 Share Posted March 4, 2008 you also may want to place the ` around user in the FROM statement. like this: $sql = "SELECT `user_id` FROM `user` WHERE `username` = '".$_SESSION['MM_Username']."'"; Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 4, 2008 Share Posted March 4, 2008 you are missing a closing paren in that insert: $resins=mysql_query("INSERT INTO gallery ('user_id', 'image_name') VALUES ('$userid','$v')") Quote Link to comment Share on other sites More sharing options...
punky79 Posted March 4, 2008 Author Share Posted March 4, 2008 Thanks N350CA When I try yours I get this error "Error in INSERT: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''user_id', 'image_name') VALUES ('5','C:\htdocs\PhotoABC\upload_test\Jordan/2008' at line 1" Quote Link to comment Share on other sites More sharing options...
punky79 Posted March 4, 2008 Author Share Posted March 4, 2008 Thanks The Little Guy I tried your 2 suggestions and got this error "Error in INSERT: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''user_id', 'image_name') VALUES ('5','C:\htdocs\PhotoABC\upload_test\Jordan/2008' at line 1" I seem to be going around in circles?? Any more help is appreciated It does seem to be nearly there tho cause the VALUES seem to be correct!!! Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 4, 2008 Share Posted March 4, 2008 Oh forgot that the column names need to be ` not ' so try this: $resins=mysql_query("INSERT INTO gallery (`user_id`, `image_name`) VALUES ('$userid','$v')") Quote Link to comment Share on other sites More sharing options...
punky79 Posted March 4, 2008 Author Share Posted March 4, 2008 Thank u so muc Little guy That worked a treat I thought I was gonna go mad with all the ' and " Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.