Jump to content

Recommended Posts

I have a standard form using an <input> tag. I am entering quotes into this field and updating my database. When the text is updated into the data base the quotes hava a \ in front of them. I've tried double quotes, single quotes, inserting the \ and it always updates incorectly. Here is the php code I'm using to update the db any help is greatly appreciated.

 

<code>

 

$query = "Update tblEvents set eventDate = '" . $eventDate . "', eventTime = '" . $eventTime . "', eventTitle = '" . $eventTitle . "', eventLocation = '" . $eventLocation . "', eventDescription = '" . $eventDescription . "', showOnWeb = '" . $showOnWeb . "' where eventID = " . $eventID;

 

</code>

Link to comment
https://forums.phpfreaks.com/topic/155348-solved-update-with-quotes/
Share on other sites

$query = "Update tblEvents set eventDate = '$eventDate', eventTime = '$eventTime', eventTitle = '$eventTitle', eventLocation = '$eventLocation', eventDescription = '$eventDescription', showOnWeb = '$showOnWeb' where eventID = $eventID;

 

 

The problem is likely due to Magic Quotes are being on

your need to use stripslashes, but that opens a security hole.. so try this

<?php
        if(get_magic_quotes_gpc()) {
            $eventDate = stripslashes($_POST['eventDate']);
            $eventTime= stripslashes($_POST['eventTime']);
            $eventTitle = stripslashes($_POST['eventTitle']);
            $eventLocation = stripslashes($_POST['eventLocation']);
            $eventDescription = stripslashes($_POST['eventDescription']);
            $showOnWeb = stripslashes($_POST['showOnWeb']);
            $eventID = stripslashes($_POST['eventID']);
        } else {
            $eventDate  = $_POST['eventDate'];
            $eventTime= $_POST['eventTime'];
            $eventTitle = $_POST['eventTitle'];
            $eventLocation = $_POST['eventLocation'];
            $eventDescription = $_POST['eventDescription'];
            $showOnWeb = $_POST['showOnWeb'];
            $eventID = $_POST['eventID'];
        }

$query = sprintf("Update tblEvents set eventDate = '%s', eventTime = '%s', eventTitle = '%s', eventLocation = '%s', eventDescription = '%s', showOnWeb = '%s' where eventID = %d",
mysql_real_escape_string($eventDate), 
mysql_real_escape_string($eventTime), 
mysql_real_escape_string($eventTitle),
mysql_real_escape_string($eventLocation),
mysql_real_escape_string($eventDescription),
mysql_real_escape_string($showOnWeb),
$eventID
);
?>

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.