Jump to content

for and mysql


fshock
 Share

Recommended Posts

I'm using php for function here:

for($i=1; ; $i++){ if($i > 8){ break; }					if(!empty(${qb.$i})){				$query .= "qb".$i."=".${qb.$i}.",";				$query .= "qbname".$i."=".${qbname.$i}.",";			}		}

echo'ed $query shows something like this:qb1=2007,qbname1=Earth Quake,qb2=2008,qbname2=Fire ballThe problem is that i can't inject this to mysql, becouse i need somehow to 'quote ' the qbname's. How should i implement THAT into my for loop?p.s. this would be correct: qb1=2007,qbname1='Earth Quake',qb2=2008,qbname2='Fire ball'

Link to comment
Share on other sites

Just add quote characters in the string before and after the value. You'll also want to use the mysql_real_escape_string function to protect against SQL attacks or problems.http://us.php.net/manual/en/function.mysql...cape-string.phpAlso, instead of this:for($i=1; ; $i++){ if($i > 8){ break; }It makes more sense to do this:for($i=1; $i <= 8; $i++){

Link to comment
Share on other sites

I've used "'${something.$i}'" and works with mysql. will read about real_escape thingie.Thanks, Just Some Guy :)edit: and I was stripping non-alphanumeric chars, is it as good as real_escape?

Edited by Zilvinas
Link to comment
Share on other sites

Stripping characters will result in data loss - if you just want to make your data safe it is much better to escape the sensitive characters (e.g. by using mysql_real_escape_string()).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...