Mysql in PHP

I currently made a script, but does not run properly. The line that is wrong is($number is a variable that holds a variable from 1 - 9):
[php]
$result = mysql_query(“SELECT * from links where prog = ‘$name’ and name LIKE ‘%$numberx%’ ORDER BY name;”) or die(mysql_error());
[/php]

It runs fine with no $number(So it works if it is [php]SELECT * from links where prog = '$name’and name LIKE ‘%x%’ ORDER BY name;[/php]). I need it to be able to look for any name that has $number (e.g. 1) with the a x next to it. If $number was 5 Then it would be name LIKE ‘%5x%’. I do not know how put the variable in so it works.

I desperately need it as my website cannot function properly without it.

Thanks,

one think i’ll sai over and over again (this is not against u, but against a lot of tutorials):
I hate the “…$var…” syntax it’ll create errors over and over again.
“…$numberx…” trys to insert a variable called $numberx (of cause there is a solution using the “…$var…”-syntax ["…${numbers}x…"]) but the best is to end a string as soon as u need to attach a variable and use the string-combine-operator .:
[php]“SELECT * from links where prog = '”.$name."’ and name LIKE ‘%".$number."x%’ ORDER BY name;"[/php]
if ur gpc_magic_quotes is turned of u need to use:
[php]“SELECT * from links where prog = '”.mysql_escape_string($name)."’ and name LIKE ‘%".intval($number)."x%’ ORDER BY name;"[/php]
anyway, to avoid the possibility of sql-injection

hope that was the prob (ur query should have always returned all/the first row as “%$numberx%” evaluates to “%%” as long as $numberx is not set)

P.S.: what editor are u using? good once have a syntax highlighting that would highlite the x as well.

Thanks so much. It seems obvious now, I tried things similar but never thought of that. All tutorials that I have seen have not mentioned it in a MYSQL and PHP tutorial.

I only use Macromedia Dreamweaver 8 for my php editor. I do not know of any others.

try weaverslave (freeware)
http://www.weaverslave.ws

Sponsor our Newsletter | Privacy Policy | Terms of Service