0

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);

}
2
Contributors
2
Replies
11
Views
3 Years
Discussion Span
Last Post by erminasrcutp
1

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'";
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.