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
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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.