• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

wats the deal with \"blah\" and \'blah\' ??

ozefrog

Active Member
wats the deal with \"blah\" and \'blah\' ?? when i post from a web form via php to a MySQL db or flat text file?

is there any simple way to get rid of this?

thanx
 
a php func. starts wiht function("asdasdasd") [in a string],
and when you write " in the func, you need to use \ before the " to avoid parse error..

try to use this :
PHP:
stripslashes($message);
 
i cant get that php command to work

and it doesnt matter that i put a \ b4 a " it comes out \\\" in the preview mode of the script, but when it posts, anything after the " or ' disappears
 
the .htaccess idea didnt work

my code is as follows over 2 files

<? include '/usr/home/o/z/ozefrog/public_html/lib/header.inc'; ?>
<?php
// Important : keep your database table name as 'joke4'..i.e don't touch the select statements
include("joke4cfg.php");
$connection = mysql_connect($serverAddress,$databaseName,$serverPass)or die("Couldn't make connection.");
$db = mysql_select_db($databaseName,$connection)or die("Couldn't select database");
$limit=20; // rows to return
$numresults=mysql_query("select * from joke4 order by date_post desc");
$numrows=mysql_num_rows($numresults);

// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
$offset=0;
}
echo "<center><strong><font face=verdana size=3>Q&A Jokes</font></strong></center><br>";
echo "<hr width=90% size=1 color=#000000 noshade>";
echo "<br><br>";
// get results
$result=mysql_query("select * from joke4 order by date_post desc limit $offset,$limit");
// now you can display the results returned
while ($data=mysql_fetch_array($result)) {
echo "<table width=475 border=0 align=center id=AutoNumber2>";
echo "<tr>";
echo "<td width=55 bgcolor=#FFCC00><b><font size=2 face=Verdana>&nbsp;Name:</font></b></td>";
echo "<td width=420 bgcolor=#008BCE align=justify><font face=Verdana size=2 color=#ffffff>".$data[0]."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width=55 bgcolor=#FFCC00><b><font face=Verdana size=2>&nbsp;IP:</font></b></td>";
echo "<td width=420 bgcolor=#008BCE align=justify><font face=Verdana size=2 color=#ffffff>".$data[1]."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width=55 bgcolor=#FFCC00 height=60 valign=top><b><font size=2 face=Verdana>&nbsp;Question:</font></b></td>";
echo "<td width=420 bgcolor=#008BCE height=60 valign=top align=justify><font face=Verdana size=2 color=#ffffff>".$data[2]."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width=55 bgcolor=#FFCC00 height=60 valign=top><b><font size=2 face=Verdana>&nbsp;Answer:</font></b></td>";
echo "<td width=420 bgcolor=#008BCE height=60 valign=top align=justify><font face=Verdana size=2 color=#ffffff>".$data[3]."</font></td>";
echo "</tr>";
echo "</table>";
echo "<br>";
}
// next we need to do the links to other results
print "<center><font face=verdana size=2>Page Number: </font>";

// calculate number of pages needing links
$pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}

for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
print "<font face=verdana size=2><a href=\"$PHP_SELF?offset=$newoffset\">$i</a>&nbsp</font>\n";
}
print "</center>";

mysql_close($connection);
?> <br>
<hr width="90%" size="1" color="#000000" noshade>
<script language=javascript>
function validate()
{
if (document.frm.usr_name.value==""){
alert("Please enter your name.");
return false;
}
if (document.frm.usr_joke.value==""){
alert("Please tell us your joke.");
return false;
}
if (document.frm.usr_ans.value==""){
alert("Please tell us your answer.");
return false;
}
}
</script>
<br>
<p align=center><font size=2 face=verdana>Please fill out the following to add your joke to our archive</font></p>
<form name="frm" action="joke4show.php" method="Post" onSubmit="return validate();">
<table width="400" border="0" cellspacing="1" cellpadding="3" align="center" id="AutoNumber1" style="border-collapse: collapse">
<tr>
<td width="50"><b><font size="2" face="Verdana">Name:</font></b></td>
<td width="350"><input type="text" name="usr_name" size="33"><input type="hidden" name="usr_id" size="30" value="<? echo $REMOTE_ADDR ?>"></td>
</tr>
<tr>
<td width="50" valign="top"><b><font size="2" face="Verdana">Question:</font></b></td>
<td width="350"><textarea rows="7" name="usr_joke" cols="32"></textarea></td>
</tr>
<tr>
<td width="50" valign="top"><b><font size="2" face="Verdana">Answer:</font></b></td>
<td width="350"><textarea rows="7" name="usr_ans" cols="32"></textarea></td>
</tr>
<tr>
<td width="50">&nbsp;</td>
<td width="350"><input type="submit" value="Add">
<input type="reset" value="Clear"></td>
</tr>
</table>
</form>

<? include '/usr/home/o/z/ozefrog/public_html/lib/footer.inc'; ?>

file 2

<?php

include("joke4cfg.php");
$date_post = date("Y-m-d H:i:s");
$connection = mysql_connect($serverAddress,$databaseName,$serverPass)or die("Couldn't make connection.");
$db = mysql_select_db($databaseName,$connection)or die("Couldn't select database");
$insertSql ="insert into joke4 values ('".$usr_name."','".$usr_id."','".$usr_joke."','".$usr_ans."','".$date_post."')";
mysql_query($insertSql);
mysql_close($connection);
include '/usr/home/o/z/ozefrog/public_html/lib/header.inc';
echo "\n\n<font face=verdana size=2><center><strong>Your joke has been added into the joke archive!</center></strong></font><br><br>";
echo "<br><br><br><br><font size=2><center>Click <a href=joke4.php>Here</a> to go back to the joke archive.</font></center>";
include '/usr/home/o/z/ozefrog/public_html/lib/footer.inc';
?>
 
Oops, try this instead:

Code:
php_flag magic_quotes_runtime off

I think the _gpc variable was for GET/POST/COOKIES. This one is for databases...

There's a way to do it in your PHP code too, if your host does not let you change the PHP configuration in the .htaccess. I think the function is

Code:
set_magic_quotes_runtime( 0 );
 
How about just putting the function call (the set_magic_quotes_runtime() mentioned above) at the top of your code and trying again? Does it work when you do that?
 
Just a long shot: did you place the function *after* the "<?" - ie,

Code:
<?
set_magic_quotes_runtime ( 0 );

...
 
Originally posted by megapuzik


This should work !!!

Actually both solutions (.htaccess and the function call) should work.

Ozefrog, if you get a parse error, you need to find out why. Eg, was something spelt wrongly, or was the file accidentally was uploaded in binary, etc?

BTW, which PHP version are you using? (I should have asked this at the beginning! :) )
 
the first part that i put in here is the one that prints it out

but the following previews it

<? include '/usr/home/o/z/ozefrog/public_html/lib/header.inc'; ?>
<font face=verdana size=2>
<p align=center><b>The following is being added to the CheapHumour joke archive:</b><br><br><br>
<table width="475" border="0" align="center" id="AutoNumber2">
<tr>
<td width="55" bgcolor="#FFCC00"><b><font size="2" face="Verdana">&nbsp;Name:</font></b></td>
<td width="420" bgcolor="#008BCE" align="justify"><font face=Verdana size=2 color=#ffffff><?php echo ($usr_name);?></font></td>
</tr>
<tr>
<td width="55" bgcolor="#FFCC00"><b><font face="Verdana" size="2">&nbsp;IP:</font></b></td>
<td width="420" bgcolor="#008BCE" align="justify"><font face=Verdana size=2 color=#ffffff><?php echo ($usr_id);?></font></td>
</tr>
<tr>
<td width="55" bgcolor="#FFCC00" height="60" valign="top"><b><font size="2" face="Verdana">&nbsp;Question:</font></b></td>
<td width="420" bgcolor="#008BCE" height="60" valign="top" align="justify"><font face=Verdana size=2 color=#ffffff><?php echo ($usr_joke);?></font></td>
</tr>
<tr>
<td width="55" bgcolor="#FFCC00" height="60" valign="top"><b><font size="2" face="Verdana">&nbsp;Answer:</font></b></td>
<td width="420" bgcolor="#008BCE" height="60" valign="top" align="justify"><font face=Verdana size=2 color=#ffffff><?php echo ($usr_ans);?></font></td>
</tr>
</table>
<br><br>
<p align=justify><font face=verdana size=2>If you wish to edit this information, click on "Go Back", or click "Add Entry" to add it to our archive.</font></p><br>
<form name=actualsubmit method=post action="joke4add.php">
<input type=hidden name="usr_name" value="<?php echo $usr_name;?>">
<input type=hidden name="usr_id" value="<?php echo $usr_id;?>">
<input type=hidden name="usr_joke" value="<?php echo $usr_joke;?>">
<input type=hidden name="usr_ans" value="<?php echo $usr_ans;?>"><br>
<font face=verdana size=2>
<center><a href="javascript:history.back();">Go Back</a> | <a href="javascript:document.actualsubmit.submit();">Add Entry</a>
</center></font>
</form>
<? include '/usr/home/o/z/ozefrog/public_html/lib/footer.inc'; ?>
 
Originally posted by fatman


Actually both solutions (.htaccess and the function call) should work.

Ozefrog, if you get a parse error, you need to find out why. Eg, was something spelt wrongly, or was the file accidentally was uploaded in binary, etc?

BTW, which PHP version are you using? (I should have asked this at the beginning! :) )

the host im with runs PHP Version 4.1.1
 
Back
Top