-2

When I add a new product sold with product code 00072 it saves nice but if I update the product sold and edit the product code to 00073 etc it gets saved as 73 and the 000 are missing.

Tried with INT VARCHAR CHAR and all the same Tried with unsigned zerofill and it just added a lot of 000000000000

The code I am using to update is:

<?php include("police.php"); ?>  
<?php 
$old = mysqli_real_escape_string($database,$_POST['old']);
$new = mysqli_real_escape_string($database,$_POST['new']);
$updating = mysqli_query($database, "UPDATE sales SET code = $new WHERE id = $old");  
?>

What can be wrong?

Currently using VARCHAR 30 latin swedish, when adding new product sale it works fine but not when updating ...

nicanica
  • 19
  • 3

1 Answers1

0

Use single quotes to surround the values. Values sent to the database without quotes surrounding them may be interpreted as numbers instead of text.

$updating = mysqli_query($database, "UPDATE sales SET code = '$new' WHERE id = '$old'");  
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Eugen
  • 1,356
  • 12
  • 15