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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:25:23+00:00 2026-05-13T17:25:23+00:00

Sorry for not formatting my code. the toolbar was gone… I want to insert

  • 0

Sorry for not formatting my code. the toolbar was gone…

I want to insert some data into a mysql db. I’ve wrote a function in php:

function add_ID($ID, $token)  {
 $add = "INSERT INTO ids (ID, token) VALUES ('$ID', '$token')";
 mysql_query($add);
 echo 'added successfully';
}  
if(isset($_GET['addDeviceID'])) {
 add_ID($_GET['ID'], $_GET['token']);
}

In the URL-Field of my Browswe I’am calling the function like that:
http://www.justanexample.com/example.php?ID=123123123&token=qwertzuiop

That works.

If I put a space into either one of the parameters for example like that:
http://www.justanexample.com/example.php?ID=123123 123&token=qwertzuiop

Nothing was added to my mysql db.

Would be great to get some help 🙂
Thank you!

  • 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-05-13T17:25:24+00:00Added an answer on May 13, 2026 at 5:25 pm

    Your function is vulnerable to SQL injection. You should validate all user-received parameters before using them in an SQL query, and pass any strings through mysql_real_escape_string, because then I could just pass in something like example.php?token='; DROP DATABASE; and royally screw up your application.

    In your case, you should make a check that the received parameters are in the form that you expect first, return an error to the user if they don’t, and only then pass them into the SQL query.

    function add_ID($ID, $token)  {
      $id = mysql_real_escape_string($id);
      $token = mysql_real_escape_string($token);
    
      $add = "INSERT INTO ids (ID, token) VALUES ('$ID', '$token')";
      mysql_query($add);
      echo 'added successfully';
    }  
    
    if(isset($_GET['addDeviceID'])) {
      $id    = isset($_GET['id']) ? $_GET['id'] : 0; // in case no ID has been passed in
      $token = isset($_GET['token']) ? $_GET['token'] : '';
    
      if (!is_numeric($id) {
        die('ID is not a number');
      } 
    
      // validate token here as well
    
      add_ID($id, $token);
    }
    

    You should also look into parametrized queries, which are an overall much better way of doing SQL queries with parameters than just using string concatenation. For that, look into using the mysqli extension instead of mysql, or at a higher level, PDO.

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

Sidebar

Related Questions

I'm passing parameters (over 30 in all) from a system.data.dataset into a tableadapter insert
My run of cap deploy fails, and I think it's because of a formatting
I am just looking for a really easy way to clean up some HTML
I'm a noob working on my first app that consists of the following: Main
I am looking up which exchange services which telephone numbers, from a table of
I have defined the following classes and methods: using System; using System.Linq.Expressions; using System.Windows.Forms;
I'm working on a project for school with converting a BNF form Decaf spec
I'm trying to establish an interactive SSH connection to a remote server using PHP
I have an HTML string that has the following form: <tr valign=top><td colspan=2 style=padding-bottom:5px;text-align:
ActionScript 3, just learning AS3 but know a handful of other languages. What would

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.