1

I developed a small script to update some fields in two tables. The query run with no error, but for any reason nothing happen on these fields. I'm sure that something are omittedd by me, but I don't know what. Any idea?

<?php
//connection to the database
$connect=mysql_connect("localhost","xxxxxx","xxxxxxxxx") or
die("Unable to Connect"); echo ("Connected to server<br>");

//select a database to work with
mysql_select_db("xxxxxxxx") or die("Could not open the db"); echo        ("Connected to database<br>");

//execute the SQL query tu update Price taxes on Products
$sql= "UPDATE pslpn_product SET id_tax_rules_group='68'";
$sql= "UPDATE pslpn_product_shop SET id_tax_rules_group='68'";
or die ('Could not update data: ' . mysql_error());

//close the connection
echo ("Finalizado<br>")
?>

2 Answers2

0

If you forget to add WHERE clause, it will update all rows in the table.

UPDATE table_name SET field = value WHERE id = something -- or else

Richard
  • 1,045
  • 7
  • 11
0

You forgot to execute your statement.

The mysql_connect() extension is deprecated. Use the MySQLi or PDO_MySQL extension instead: When should I use MySQLi instead of MySQL?

With mysqli you can execute a query like this:

if ($connect->query($sql) === TRUE) {
  echo “Updated";
} else {
   echo "Error " . $connect->error;
}

Read more: http://www.w3schools.com/php/php_mysql_update.asp

Community
  • 1
  • 1
piscator
  • 8,028
  • 5
  • 23
  • 32