Jump to content

PHP and MySQL WHERE clause help


punky79

Recommended Posts

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.

Link to comment
Share on other sites

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());
?>

Link to comment
Share on other sites

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"

 

 

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.