The update database is not working , please help me.

edit.php

<?php

    include_once('db.php');
    if(isset($_GET['edit']))
    {
        $id=$_GET['edit'];
        $res=mysql_query("SELECT * from apple WHERE id='$id'");
        $row=mysql_fetch_array($res);
    }

    if(isset($_POST['newName']))
    {
        $newName= $_POST['newName'];
        $id = $_POST['id'];
        $sql = "UPDATE  apple SET name=''$newName' WHERE id='$id'";
        $res = mysql_query($sql) or die("Could not update".mysql_error());
        echo "<meta http-equiv='refresh' content='0;url=index.php'>";
    }
?>

<form action="edit.php" method="POST">
Name :<input type="text" name="newName" value="<?php echo $row[1];?>"> </br>
<input type="hidden" name="id" value="<?php echo $row[0];?>">
<input type ="submit" value="Update">
</form>

db.php

<?php
$conn_error = 'Could not connect.';
$mysql_host = '127.0.0.1';
$mysql_user = 'root';
$mysql_pass = '';
$mysql_db='software';

if(!@mysql_connect($mysql_host, $mysql_user,$mysql_pass)|| !@mysql_select_db($mysql_db))
{
  die($conn_error);

}

You have an extra single quote in your query

$sql = "UPDATE  apple SET name=''$newName' WHERE id='$id'";

Should be

$sql = "UPDATE apple SET name='$newName' WHERE id='$id'";
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.