0
<?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 ')

3
Contributors
6
Replies
24
Views
2 Years
Discussion Span
Last Post by phoenix254
0

@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! :)

Edited by cereal

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.