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 8854031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:47:25+00:00 2026-06-14T13:47:25+00:00

I am having trouble getting this to work I want to make sure that

  • 0

I am having trouble getting this to work I want to make sure that if the user adds HTML tags or PHP tags in the text fields in a form that they do not get added into the database.
The code that I have now adds the strip_tags along with the HTML and PHP tags into the database.

Here is my code:

    <?php
      //Check for Valid Email
function valid_email($email) {
    return filter_var($email, FILTER_VALIDATE_EMAIL);
}


    //Add people Information to Database 
function addToDB ($sql, $con) {
require 'db.php';

    $sql= ("INSERT INTO people (name,email) VALUES(
            'strip_tags($_POST[name])', 
           '($_POST[email])')");

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }


mysql_close($con);
}

    //Add vehicle Information to Database
function addToDB1 ($sql, $con) {
require 'db.php';

$sql="INSERT INTO vehicle (year, make, model, color)
VALUES
('$_POST[year]','$_POST[make]', '$_POST[model]', '$_POST[color]')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }


mysql_close($con);
}

?>
  • 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-14T13:47:26+00:00Added an answer on June 14, 2026 at 1:47 pm

    It is not possible to call functions within a string as you do for displaying variables on double quoted strings!

    So your query needs to be something like that :

    $sql= 'INSERT INTO people (name,email) VALUES(\''.strip_tags($_POST[name]).'\', \''.$_POST[email].'\')';
    

    by the way, you should really consider to escape your input data coming from post/get variables! Something like:

    $sql= 'INSERT INTO people (name,email) VALUES(\''.mysql_real_escape_string(strip_tags($_POST[name])).'\', \''.$_POST[email].'\')';
    

    The best alternative, however, would be to use prepared statements to prevent sql injection!


    Eidt : if you are working with variables within strings use {$_POST[email]} and not ($_POST[email]) to mantain your varnames consistent!

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

Sidebar

Related Questions

I am having trouble getting this to work: http://jsfiddle.net/2jg2F/1/ I basically want to make
I'm having trouble getting this Javascript Regular Expression to work. What i want is
I'm sure this is fairly straightforward but i'm having trouble getting it to work.
Having some trouble getting this to work... I basically want the report to look
I'm having trouble getting this to work. I want to use nested attributes in
I'm having some trouble getting this to work. This is the code I want
Ok this seems so silly but I'm having some trouble getting this to work.
I am having trouble getting this invisibilityOfElementLocated() method to work. Here is the code
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function

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.