Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7746175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:12:41+00:00 2026-06-01T10:12:41+00:00

I have a variable which I need to strip of sybols before inserting into

  • 0

I have a variable which I need to strip of sybols before inserting into my database, any ideas how I would add the mysql_real_escape_string() function to my existing code?

Form page

This page is a basic html form which shows the database content.

<?php 
 $query = sprintf( "SELECT * FROM sitecontent WHERE ID = $_GET[id]");
$result = mysql_query($query) or die (mysql_error());
$post = mysql_fetch_array($result);

   ?>

       <form action="editp.php" method="POST" name="editform">
    <label for="pName" style="padding:10px; ">Post Title</label>
    <input type="text" name="pName" style=" width:550px;border:#000099; margin:10px;"   value="<?php echo $post['Post_Title']; ?>"/>
    <label for="pCategory" style="padding:10px; ">Category</label>
    <input type="text" name="pCategory" style=" width:50px;border:#000099; margin:10px;" value="<?php echo $post['Post_Year']; ?>"/>
    <label for="pItem" style="padding:10px;">Item Type</label>
   <select name="pItem" style="border:#000099; margin:10px;">
    <option value="1">News</option>
   <option value="2">Review</option>
 </select>
 <label for="pName" style="padding:10px;">Article ID</label>
      <input type="text" name="pID" style="border:#000099; margin:10px;" value="<?php echo $post['ID']; ?>"/>
  <label for="pName" style="padding:10px;">Post Date</label>
   <input type="text"  name="pDate" style="border:#000099; margin:10px;" value="<?php echo $post['Date']; ?>">
   <label for="pName" style="padding:10px;">Post Author</label>
 <input type="text" name="pAuthor" style="border:#000099; margin:10px;" value="<?php echo $post['Post_Author']; ?>"/>
   <label for="pName" style="padding:10px;">Home Page</label>
  <select name="Page" style="border:#000099; margin:10px;">
  <option value="0">None</option>
  <option value="1">Home</option>
 </select>
 <label for="pPriority" style="padding:10px;">Home Priority</label>
   <select name="pPriority" style="border:#000099; margin:10px;">
 <option value="0">None</option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  </select>
    <label for="pName" style="padding:10px;">Post Content</label>
  <textarea style="width:550px; height:200px;border:#000099; margin:10px;" type="text" name="pContent" id="pContent" value="<?php echo $post['Post_Content']; ?>"><?php echo $post['Post_Content']; ?></textarea>
    <span id="btnStrong" style="  padding: 2px 8px;background-color:#C00;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#FFF; cursor:pointer;">Bold</span> &nbsp; <span id="btnItalic" style=" padding: 2px 8px; background-color:#C00;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#FFF; cursor:pointer;">Italic</span>
   <label for="pImage_Name" style="padding:10px;">Image Name</label>
   <input type="text" name="pImage_Name" style="border:#000099; margin:10px; width:550px;" value="<?php echo $post['Image_Name']; ?>"/>
   <label for="pApproval" style="padding:10px;">Approval</label>
   <select name="pApproval" style="border:#000099; margin:10px;">
  <option value="0">Pending</option>
  <option value="1">Approved</option>
  </select>
   <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>"/>
     <span style="margin-left:10px;">Please check the changes above before submitting</span>                <br/>
   <input type="submit" name="go" value="Submit Changes" style=" padding: 2px 8px;background-color:#C00; color:#FFF; margin:10px;"/>
   </form>

   <?php
$updateq = "UPDATE sitecontent WHERE ID = '$_POST[id]'";
   ?>

Update page

This is the page that writes the content from the form to the database.

    <?php
 include'includes/connection.php';
 $pName = $_POST['pName'];
 $pItem = $_POST['pItem'];
 $pCategory = $_POST['pCategory'];
 $pDate = $_POST['pDate'];
 $pAuthor = $_POST['pAuthor'];
 $pContent = $_POST['pContent'];
 $Page = $_POST['Page'];
 $id = $_POST['id'];
 $pApproval = $_POST['pApproval'];
 $pPriority = $_POST['pPriority'];
 $pImage_Name = $_POST['pImage_Name'];

 $updateq = "UPDATE sitecontent SET ID = '$pID', Post_Title = '$pName', Post_Year =      '$pCategory', Date = '$pDate', Post_Author = '$pAuthor', Post_Content = '$pContent', Page =      '$Page', Post_Approval = '$pApproval', Priority = '$pPriority', Image_Name = '$pImage_Name'      WHERE ID = '$_POST[id]'";

 $result = mysql_query($updateq) or die (mysql_error());
 header("Location:admin.php");

 ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:12:43+00:00Added an answer on June 1, 2026 at 10:12 am

    For strings just say:

    $pName = mysql_real_escape_string($_POST['pName']);
    

    For integers:

    $id = intval($_POST['id']);
    

    That’s all there is to it; just do it for all your variables

    edit
    Anyways, I’d advise you to use PDO in stead, way better to prevent sql injection!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP-variable called $go_Adress which contains the adress I need to get
I have a java string, which has a variable length. I need to put
I have a variable which contains the value 1234567 . I would like it
I have a variable which I get from database I want to output this
I have a variable which is defined as a DateTime . I need to
I have a variable which has a string stored in it and need to
I have the following variable which returns my URL as needed. But i need
I have a SQL variable called @FileName which I need to trim numbers off
I have a variable StudentID which is an int, I need to convert to
I have a variable $params which gets data from the database: $params = mssql_fetch_array($result)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.