1

I have managed to create a php code that will link to MYSQL, so the user can add data, delete and edit. Howerver, I'm currently having an issue so if the user wishes to edit some data, it will reset the last 3 columns to 0's. If I edit a data during the last 3 columns, it will not be eddited and instead be replaced with 0's at the last 3 columns.

{
  $eBranch=$_POST['eBranch'];
  $eSales=$_POST['eSales'];
  $eQuantity=$_POST['eQuantity'];
  $eChargeNO=$_Post['eChargeNO'];
  $eCreditNO=$_Post['eCreditNO'];
  $eTotal=$_Post['eTotal'];
  $updated=mysql_query("UPDATE report SET  BranchID='$eBranch', Sales_Assistant_ID='$eSales', Quantity='$eQuantity' , Charge_Accounts='$eChargeNO', Credit_Accounts='$eCreditNO', Total='$eTotal' WHERE id='$id'")or die();

  if($updated)
  {
  $msg="Successfully Updated!!";
  header('Location:index.php');
  }
}
}

Please ask me if you need more information! I'm not sure if this is enough

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Zeon
  • 327
  • 3
  • 18
  • Have you actually checked that the $_POST values are being passed as you expect? – Mark Baker Apr 13 '15 at 16:54
  • `error_reporting(E_ALL); ini_set('display_errors', '1');` would tell you. – AbraCadaver Apr 13 '15 at 16:55
  • *"Question has been solved - I did not capitalize my _POST"* - From your edit. No need to do that. Accepting the answer was good enough ;-) I had to do a rollback, otherwise people visiting the question may ask "why the answers?". – Funk Forty Niner Apr 13 '15 at 21:36

3 Answers3

4

You see these $_Post?

They're a superglobal and must be in uppercase $_POST


Sidenotes:

  • Your present code is open to SQL injection. Use mysqli with prepared statements, or PDO with prepared statements, they're much safer. You should also consider moving to and using mysqli_ or PDO, as the mysql_ functions are deprecated and will be removed from future PHP releases.

  • Add exit; after header, should there be any other instructions below. Otherwise, your code may want to continue executing.

  • or die() doesn't help you. Use or die(mysql_error()) to get the real error, should there be any.


Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: Error reporting should only be done in staging, and never production.

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Thanks man!! You have no idea how long i been looking at this ahah – Zeon Apr 13 '15 at 17:11
  • @Prymz You're welcome. Those related questions are getting rarer; it's been a while since I last saw one where someone was using `$_Post`. I'm glad I was able to help, *cheers*. – Funk Forty Niner Apr 13 '15 at 17:12
3

Try changing your 3 occurrences of $_Post to $_POST

Mex
  • 1,011
  • 7
  • 16
  • Something else you might be interested in knowing is that whilst variable name are case-sensitive in PHP, function names are not. – Mex Apr 13 '15 at 17:54
1

You're using $_Post in for $eChargeNO, $eCreditNO, and $eTotal, your three last columns. Change it to $_POST.

Muhammad Abdul-Rahim
  • 1,980
  • 19
  • 31