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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:46:32+00:00 2026-05-16T01:46:32+00:00

I have a a php page which updates a mySql database it works fine

  • 0

I have a a php page which updates a mySql database it works fine on my mac (localhost using mamp)

I made a check if its the connection but it appears to be that there is a connection

 <?php require_once('connection.php'); ?>

 <?php  
  $id = $_GET['id'];
  $collumn = $_GET['collumn'];
  $val = $_GET['val'];
 // checking if there is a connection
 if(!$connection){
     echo "connectioned failed";
   }
  ?>


 <?php 
    $sqlUpdate = 'UPDATE plProducts.allPens SET '. "{$collumn}".' = '."'{$val}'".' WHERE allPens.prodId = '."'{$id}'".' LIMIT 1';
    mysql_query($sqlUpdate);
    // testing for errors
   if ($sqlUpdate === false) {
      // Checked this and echos NO errors.
     echo "Query failed: " . mysql_error();
    }

if (mysql_affected_rows() == 1) {
  echo "updated";
} else {
  echo "failed";
}?>

In the URL i pass in parameters and it looks like this: http://pathToSite.com/updateDB.php?id=17&collumn=prodid&val=4

Maybe this has to do with the hosting? isn’ t this simple PHP mySql database updating? what can be wrong here?

Why on localhost it does work?

Why on live server it doesn’t?

  • 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-16T01:46:33+00:00Added an answer on May 16, 2026 at 1:46 am

    Let’s start with troubleshooting your exact problem. Your query is failing for some reason. We can find out what that problem is by checking what comes back from mysql_query, and if it’s boolean false, asking mysql_error what went wrong:

    $sh = mysql_query($sqlUpdate);
    if($sh === false) {
        echo "Query failed: " . mysql_error();
        exit;
    }
    

    You have other problems here. The largest is that your code suffers from an SQL Injection vulnerability. Let’s say your script is called foo.php. If I request:

    foo.php?collumn=prodId = NULL -- 
    

    then your SQL will come out looking like:

    UPDATE plProducts.allPens SET prodId = NULL -- = "" WHERE allPens.prodId = "" LIMIT 1
    

    -- is an SQL comment.

    I just managed to nuke all of the product IDs in your table.

    The most effective way to stop SQL injection is to use prepared statements and placeholders. The "mysql" extension in PHP doesn’t support them, so you’d also need to switch to either the must better mysqli extension, or the PDO extension.

    Let’s use a PDO prepared statement to make your query safe.

    // Placeholders only work for *data*.  We'll need to validate 
    // the column name another way.  A list of columns that can be
    // updated is very safe.
    $safe_columns = array('a', 'b', 'c', 'd');
    if(!in_array($collumn, $safe_columns))
        die "Invalid column";
    // Those question marks are the placeholders.
    $sqlUpdate = "UPDATE plProducts.allPens SET $column = ? WHERE allPens.prodId = ? LIMIT 1";
    $sh = $db->prepare($sqlUpdate);
    // The entries in the array you pass to execute() are substituted
    // into the query, replacing the placeholders.
    $success = $sh->execute(array( $val, $id ));
    // If PDO is configured to use warnings instead of exceptions, this will work.
    // Otherwise, you'll need to worry about handling the exception...
    if(!$success)
        die "Oh no, it failed!  MySQL says: " . join(' ', $db->errorInfo());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following in a .htaccess file redirect 301 /page.php http://domain.com/page Which works
I have a PHP page which breaks down in IE 6 and 7, hence
We have an existing PHP page (from an earlier project) which could be described
I have a web page which uses in PHP and a jQuery DataTable to
I have an iframe tab which holds php page with various links inside (like
I have an PHP/HTML main page, in which I include different other PHP files
I have a jQuery dialog which loads an external php page. All is working
I have a dynamic drop down box which calls another PHP page. I've got
I have web page in PHP which displays all records in a table. I
I have a page (main.php) which loads content from an external PHP file (rpc.php).

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.