0

I have a php form that needs to update information in aSQL database. I have read numerous replies on here but for some reason I am not getting my code to work.

I am using "POST" in the form and this is the code I use in the PHP action page.

{   global $host;
    global $username;
    global $password;
    global $db_name;
$imei = $_REQUEST['imei'];

$insertSuccessful = false;
   $sql = "UPDATE tracking_sim SET      
        imei = '".$imei."',
                    loaded_by = '".$loaded_by."'
        Where card_no='$card_no'"; 

    if (mysql_query($sql, $con)) {
            $insertSuccessful = true;
        } else {
            echo mysql_error ();
            echo $sql;
            print_r($_POST);
            echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
            echo "mysql err no : " . mysql_errno($con);
        }
    return $insertSuccessful;

Function Def:

//update database
update_lbs($msisdn, $reqby1, $reqdate, $reqtime, $client, $clientcase, $saps, 
$cas, $reason, $reqby, $long, $lat, $msisdn, $dist, $response);

//update database
function update_lbs($imei, $serial, $status, $msisdn_no, $card_no, $client_name,
 $inst_date, $tech, $inst_cert, $isp, $account, $account_price, $deposit, $cont_start,  
$cont_end, $rica, $date_rica, $prod, $suspended, $loaded_by)

All brackets are closed and some smaller code in between have been left out. Connection to SQL is completed and no errors as well. Even if I post the form doesn't show me any errors at all

Please guide me in right direction here

Maggie Ackermann
  • 253
  • 1
  • 4
  • 15
  • Show your function definition. – Yogesh Suthar Sep 12 '13 at 12:43
  • have you tried to show the content of `$sql`? – sikas Sep 12 '13 at 12:44
  • The first chunk of code looks like it's part of a function, from the `global` lines at the top. You're using that to pass in your database details, but then you're just calling `mysql_query($sql, $con)` - `$con` isn't defined anywhere in your code. – andrewsi Sep 12 '13 at 13:03
  • I have not place the full code if ($con = mysql_connect($host, $username, $password)) It is to save some space. The connection is fine but for some reason no update on the SQL. Also have tried Micheal's method nothing showing. I am not even getting SQL errors – Maggie Ackermann Sep 12 '13 at 13:06

2 Answers2

0

Here's a quick test you can do - try $_POST['imei'] and the same for any other post variables...

or add this code to the top of your code.

foreach($_POST as $key=>$value){ 

  // Optional code
  $value = addslashes($value);
  $value = stripslashes($value);

  $$key = $value;

  // Optional code      
  $k[] = $value;
  $counter++;

} 

This is just a test to make sure you're actually getting the POST data from the form.

Michael Bellamy
  • 543
  • 1
  • 8
  • 16
0

It seems you're missing an

extract($_POST);

on top of your code.

Also take a look at the security issues related with injection here

Ruben Serrate
  • 2,724
  • 1
  • 17
  • 21