Database generated listbox having problems with spaces
Moderator: General Moderators
Database generated listbox having problems with spaces
I have a list box which is populated from a database by a list of games consoles. So there's PS2, PS3, Nintendo DS, Xbox and XBox 360. A default is selected from the database also. I've found it works fine unless there is a space in the name and the default is select, in which case everything after the space goes missing from the sql update query. If an option with a space is selected, but it isn't the default, it works ok.
Any ideas?
Any ideas?
ok, here's the relevant parts
Code: Select all
$title=mysql_real_escape_string($_REQUEST[title]);
$editproduct="UPDATE product SET title='$title', headline='$headline', description='$description', info='$info', imageurl='$imageurl', catagory='$catagory', subcat='$subcat' WHERE title='$_GET[title]' AND subcat='$_GET[subcat]'";
mysql_query($editproduct,$con);You defined a variable $title and passed it to mysql_real_escape_string() -- although you left out the quotes around "title" -- but then you didn't use the variable in your SQL string...why??davidtube wrote:ok, here's the relevant parts
Code: Select all
$title=mysql_real_escape_string($_REQUEST[title]); $editproduct="UPDATE product SET title='$title', headline='$headline', description='$description', info='$info', imageurl='$imageurl', catagory='$catagory', subcat='$subcat' WHERE title='$_GET[title]' AND subcat='$_GET[subcat]'"; mysql_query($editproduct,$con);
I'm probably misunderstanding you but am I not using the variable $title here?
Code: Select all
SET title='$title'Yes, there, but not in the WHERE clause.davidtube wrote:I'm probably misunderstanding you but am I not using the variable $title here?Code: Select all
SET title='$title'
Actually, I just looked at your SQL again and there's no need to SET the title, since you're updating the record WHERE that's already the value in the field. It doesn't hurt anything, but it also doesn't accomplish anything.