Page 1 of 1

Database generated listbox having problems with spaces

Posted: Wed Sep 05, 2007 11:29 am
by davidtube
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?

Posted: Wed Sep 05, 2007 11:40 am
by hawleyjr
Can we see some code? Sounds like the error is in your php or insert.

Posted: Wed Sep 05, 2007 1:07 pm
by miro_igov
Do not forget to put the value in quotes:

<option value="Nintendo DS">Nintendo DS</option>

Below is wrong and will display Nintendo only in your db:

<option value=Nintendo DS>Nintendo DS</option>

Posted: Wed Sep 05, 2007 1:11 pm
by davidtube
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);

Posted: Wed Sep 05, 2007 2:13 pm
by califdon
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);
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??

Posted: Wed Sep 05, 2007 2:35 pm
by davidtube
I'm probably misunderstanding you but am I not using the variable $title here?

Code: Select all

SET title='$title'

Posted: Wed Sep 05, 2007 2:58 pm
by califdon
davidtube wrote: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.

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.

Posted: Wed Sep 05, 2007 3:11 pm
by davidtube
Oh. That's just because of the code changing as I've added new things. It still works as it's supposed to, unless there's space when the "subcat" is being posted.

I set the title so the WHERE can find the current title, then it can be changed.

Posted: Fri Sep 07, 2007 6:16 am
by davidtube
I've sorted it. In another piece of code, I'd put

"$subcat'

(one single and one double quote)

thanks for your help