<?php
$con=mysqli_connect("localhost","root","","uplod");
if (mysqli_connect_error())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  else{
      echo work
            $sql ="UPDATE tea SET name = ' 8req'  WHERE id = '3 ' "or die ("cant update" . mysql_error());
            if($sql)
                echo"working";
 }
?>

Who can tell me which is error is the script?
it isnt update the db, i try in phpmyadmin sql queries it works. This is what i wrote in sqlquery (UPDATE tea SET name = ' 8req' WHERE id = '3 ')

You have suspicious looking spaces in ' 8req' WHERE id = '3 '

What error do you get?

@phoenix

There are some errors here:

echo work
        $sql ="UPDATE tea SET name = ' 8req'  WHERE id = '3 ' "or die ("cant update" . mysql_error());

The echo statement needs quotes if you're trying to return a string, if that is a constant it's ok, but you have to close the command with a semicolon, for example:

echo "work";

# or, for constants
echo work;

Then you've defined a query and right after or die() but:

  1. you are not running the query
  2. you are mixing in the wrong way the quotes after the query
  3. you are using MySQLi to start the connection to the database and switching to the MySQL API to return the error

So the above should look like:

mysqli_query($con, "UPDATE tea SET name = '8req' WHERE id = '3'");

if(mysqli_errno($con))
{
    echo mysqli_errno($con) . ' ['. mysqli_sqlstate($con) .']' . ': ' . mysqli_error($con);
}

To execute a query with external arguments you should use prepared statements, for some examples check this:

For the log, if using the MySQL API, then the above would look like this:

$sql = mysql_query("UPDATE tea SET name = '8req' WHERE id = '3'") or die("cant update" . mysql_error());

But is deprecated, and will be removed so, if possible, don't use it.

Last note: please next time, provide the error information here in the forum, not through a video. Bye! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.