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
https://forums.phpfreaks.com/topic/94335-php-and-mysql-where-clause-help/
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());
?>

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"

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.