Forum Moderators: coopster

Message Too Old, No Replies

Not sure how to use stripslashes?

Inside a function with a while loop...

         

freshrod

4:20 am on May 31, 2006 (gmt 0)

10+ Year Member



I have a function that retieves data from a DB. I used addslashes and now I need stripslashes to get rid of the slashes on all the ', like in can't and don't.

Here is the code:

function displayAlumInfo($result) {

while ($row = mysql_fetch_array ($result))
{
$pic = $row['pic_url'];
print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Picture:</td><td><img src='$pic'></td></tr>";
print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Tell us about where you are living now:</td><td>&nbsp; {$row['living']}</td></tr>";
print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Are you married (Spouse name, Years married)?:</td><td>&nbsp; {$row['spouse']}</td></tr>";
print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Kids (Names, Ages)?:</td><td>&nbsp; {$row['kids']}</td></tr>";
print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>What are you doing (Jobs, Hobbies, Pastimes)?:</td><td>&nbsp; {$row['job']}</td></tr>";
print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Anything else we should know about your life now?:</td><td>&nbsp; {$row['life']}</td></tr>";
print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Best MHS memory:</td><td>&nbsp; {$row['bestMHS']}</td></tr>";
print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Worst MHS memory:</td><td>&nbsp; {$row['worstMHS']}</td></tr>";
print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Most embarrassing MHS memory:</td><td>&nbsp; {$row['embarrassMHS']}</td></tr>";
print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Message to fellow MHS Alumni:</td><td>&nbsp; {$row['message']}</td></tr>";
}
}

$result = mysql_query("SELECT * FROM alumInfo WHERE userId = '$alumni'");

displayAlumInfo($result);

I've tried adding
$result = stripslashes($result);

and changing the function to
function displayAlumInfo(stripslashes($result))

but I get errors with the while loop.

Any ideas?

jatar_k

4:27 am on May 31, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you don't need to stripslashes on $result

you need to do it on every array value

stripslashes($row['living']);

etc

by the way, you shouldn't use stripslashes for inserting into mysql, you should use mysql_real_escape_string [php.net]

freshrod

5:11 am on May 31, 2006 (gmt 0)

10+ Year Member



Thank you.

I'm not sure I can get the syntax right. I keep getting an error when I try and add the stripslashes.

print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Tell us about where you are living now:</td><td>&nbsp; " . stripslashes{$row['living']} . "</td></tr>";

Could you give me an example?

eelixduppy

10:21 am on May 31, 2006 (gmt 0)



You're syntax is wrong. Use parenthesis instead of brackets:
print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Tell us about where you are living now:</td><td>&nbsp; " . stripslashes($row['living']) . "</td></tr>";