PHP: stripslash(troubles)

  • Thread starter lifestream
  • 4 comments
  • 1,793 views
I seem to be having some trouble with stripslashes.

PHP:
while($row = mysql_fetch_array($result)){

	if ($tog==0){
	echo "<tr>";
		if($_SESSION['acclevel']=="normal"){
			if($row[0] == $_SESSION['username']){
			echo "<td width='120'><a href='editform.php?edit=" . stripslashes($row[0]) . "&confirm=undecided'>Edit</a> | \n";
			echo "<a href='deleteform.php?delete=" . stripslashes($row[0]) . "&confirm=undecided'>Delete</a> | \n";
			echo "<a href='../viewform.php?view=" . stripslashes($row[0]) . "'>View</a></td>\n";
			}
			else {
			echo "<td width='120'><font color='#888888'>Edit</font> | <font color='#888888'>Delete</font> | <a href='../viewform.php?view=" . stripslashes($row[0]) . "'>View</a></td>\n";
			}
		}
		if($_SESSION['acclevel']=="admin"){
			echo "<td width='120'><a href='editform.php?edit=" . $row[0] . "&confirm=undecided'>Edit</a> | \n";
			echo "<a href='deleteform.php?delete=" . $row[0] . "&confirm=undecided'>Delete</a> | \n";
			echo "<a href='../viewform.php?view=" . $row[0] . "'>View</a></td>\n";
		}
	echo "<td>" . $row[0] . "</td>\n";
	echo "<td>" . $row[1] . "</td>\n";
	echo "<td>" . $row[2] . "</td>\n";
	echo "<td>" . $row[3] . "</td>\n";
	echo "<td>" . $row[4] . "</td>\n";
	echo "</tr>\n";
	$tog=1;
	}
	else{
	echo "<tr>";
		if($_SESSION['acclevel']=="normal"){
			if($row[0] == $_SESSION['username']){
			echo "<td width='120' class='alternate'><a href='editform.php?edit=" . stripslashes($row[0]) . "&confirm=undecided'>Edit</a> | \n";
			echo "<a href='deleteform.php?delete=" . stripslashes($row[0]) . "&confirm=undecided'>Delete</a> | \n";
			echo "<a href='../viewform.php?view=" . stripslashes($row[0]) . "'>View</a></td>\n";
			}
			else {
			echo "<td width='120' class='alternate'><font color='#888888'>Edit</font> | <font color='#888888'>Delete</font> | <a href='../viewform.php?view=" . stripslashes($row[0]) . "'>View</a></td>\n";
			}
		}

		if($_SESSION['acclevel']=="admin"){
			echo "<td width='120' class='alternate'><a href='editform.php?edit=" . $row[0] . "&confirm=undecided'>Edit</a> | \n";
			echo "<a href='deleteform.php?delete=" . $row[0] . "&confirm=undecided'>Delete</a> | \n";
			echo "<a href='../viewform.php?view=" . $row[0] . "'>View</a></td>\n";
		}
	echo "<td class='alternate'>" . $row[0]. "</td>\n";
	echo "<td class='alternate'>" . $row[1] . "</td>\n";
	echo "<td class='alternate'>" . $row[2] . "</td>\n";
	echo "<td class='alternate'>" . $row[3] . "</td>\n";
	echo "<td class='alternate'>" . $row[4] . "</td>\n";
	echo "</tr>\n";
	$tog=0;
	}
}

For some reason when I am echoing out $row[0], it will remove the slashes just fine, but when I try to concatonate(sp) stripslashes($row[0]) with a URL, i always get "http://www.address.com/\". It only detects the first breaking character, and then its cuts out the rest of row[0]. To be more specific, lets say row[0] is \'\'\"\'\':
PHP:
This line of code....
echo "<td class='alternate'>" . stripslashes($row[0]) . "</td>\n";
Yeilds this output...
''"''
PHP:
Yet this line of code...
echo "<td width='120' class='alternate'><a href='editform.php?edit=" . stripslashes($row[0]) . "&confirm=undecided'>Edit</a> | \n";
Yeilds this URL...
http://www.blahblah.com/editform.php?edit=\&confirm=undecided
When it should be...
http://www.blahblah.com/editform.php?edit=''"''&confirm=undecided
---------------------------------------
Any suggestions on this?

* please note in some of my code the URLs don't use stripslashes(), this is just for testing purposes, im not trying to be inconsistant :P
 
Hmm. I don't see any problems.. What you could try doing is setting a variable to what you wanted to be stripped... ex:

PHP:
$var = stripslashes($row[0]);

Thats all i can really think of, considering your code seems correct.. (unless i'm missing something?)
 
see unforuntately ive tried this but it doesn't seem to work correctly....doing anything other then echo stripslashes($row[0]); won't work.
 
Hmm. Well thats odd..

Well, either way, MySQL automatically adds and strips slashes, bro. (Or php does it.. not sure.)
 
Hmm. I see what you're doing. And I see what you're doing in a different way to how I do it. I don't know why your way isn't working, but I'll post my way, and you can try it, see if it helps...

PHP:
$result = mysql_query(query);
$noofrows = mysql_num_rows($result);
for($i=0; $i < $noofrows; $i++)
{
    $row = mysql_fetch_array($result);
    echo "<a href=\"editform.php?edit=".stripslashes($row["user"])."\">Edit"</a>";
}

Actually, now I look at it, you're trying to read $row[0]. What is that? When you do a mysql_fetch_array(), it creates an associative array with each array parameter being named after the field name from the database, and the parameter value containing the contents of that record's field in the database.

So in the above code sample, this would echo the contents of the "user" field for this particular database record.

Does that help at all?
 
Back