Jump to content

for and mysql


fshock

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

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

Archived

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

×
×
  • Create New...