Jump to content

[SOLVED] Stripslashes problem


RyanSF07

Recommended Posts

Hi All,

 

I'm using addslashes to add slashes to the string:

 

What's her dog's name?

 

before inserting to the database.

 

I can retrieve it correctly with:

 

$id = $row["id"]; 
$question = $row["question"]; 
$question2 = stripslashes($question); 

 

and echoing $question2.

 

The user then has the option to "update" or change their question.

Clicking "edit" take them to another php page where I'm using:

 

$id = $_GET[id];
$update = $_POST['update'];
$question = $_POST['question']; 

 

and retrieving that same string with:

<?php echo stripslashes($myrow["question"]); ?>

 

However, this doesn't work. Instead of getting:

 

What's her dog's name?

 

I get:

 

What

 

... everything after the first apostrophe is deleted.

 

what am I doing wrong here. Isn't stripslashes("my string") supposed to strip the slash WITHOUT deleting the rest of the string?  :-\

 

Thank you very much for your help,

Ryan

Link to comment
https://forums.phpfreaks.com/topic/89597-solved-stripslashes-problem/
Share on other sites

Here's the full chunck of code that is supposed to grab and enable the edit:

 

<?php
$id = $_GET[id];
$update = $_POST['update'];
$question = $_POST['question']; 

if($id) {
$sql = "SELECT * FROM $table WHERE id=$id";
$query_result = mysql_query($sql);
$myrow = mysql_fetch_array($query_result);

$_SESSION[editQ] = $id;

?>

Edit this question.
<form action="edit_this_q_processor.php?id=$_SESSION[editQ]" method="post">
<input type="hidden" name="id" value="<?php echo $myrow[id]?>">

    <b>Question:</b><br>
    <input type="Text" name="question" value='<?php echo stripslashes($myrow["question"]); ?>' size="50">
....

 

 

 

Thanks again for your help,

Ryan

On this line:

<input type="Text" name="question" value='<?php echo stripslashes($myrow["question"]); ?>' size="50">

change the single quotes to double quotes:

<input type="Text" name="question" value="<?php echo stripslashes($myrow["question"]); ?>" size="50">

When you have the single quotes, the single quote in the string being echoed is being taken for the string end. If you do a "show source" you will see the whole string there.

 

Ken

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.