0

before you mark my question duplicate this is my last resort .I have tried every possible syntax there is no error but i cant update the table , although I can insert into table but cant update the content already present. config.php is used to make connection with db.

<html>
    <head>
        <title>
            Thank You FOR Entering Data !!
        </title>
    </head>
    <style>
        div {
            width:100%;
            position: absolute;
            bottom:0;
        }
        img {
            position: relative;
            display: block;
            float: right;
        }
    </style>
    <body background="wall.jpg">
        <font face="WenQuanYi Micro Hei Mono" color="white"><b>
            <h1>Thank You For Entering Data</h1>
            <?php
            include("config.php");
            // Data coming into form via POST
            if ($_POST) {
                $empide = $_POST["empid"];
                $name = $_POST["name"];
                $address = $_POST["address"];
                $pnumber = $_POST["pnumber"];
                $email = $_POST["email"];
                $gender = $_POST["gender"];
                if ($con) {
                    echo nl2br("empid= $empide \nNAME = $name\n Address = $address \n Phone Number = $pnumber \n Email = $email \n Gender = $gender  ");
                    echo $empide;
                    //$abc=mysqli_query($con,"INSERT INTO `employee` (`name`, `address`,    `pnumber`, `email`,`gender`) VALUES ('$name', '$address', '$pnumber', '$email','$gender') ;");  
                    $query = mysqli_query($con, "UPDATE 'employee' SET 'name' = '$name',      'address' = '$address', 'email' = '$email', 'pnumber' = '$pnumber',   'gender' = '$gender' WHERE 'employee'.'empid' = '$empide';");
                } else {
                    echo "Unable to make connection with your data base";
                }
            }
            ?>
            <right>
                <div>
                    <a href="index.php"><img src="home.png" width="110" height="110"></a>
                </div>
            </right>
    </body>
</html>
mitkosoft
  • 5,262
  • 1
  • 13
  • 31
Machine
  • 103
  • 7

2 Answers2

1

Always use mysqli_connect_errno() to detect connection error and

use mysqli_error() to detect query errors.

Write your code as below:-

// check connection 
if (mysqli_connect_errno()) {
     printf("Connect failed: %s\n", mysqli_connect_error());
     exit();
}
// You have added unnecessary semicolon and simple quote in field name in your query
$sql = "UPDATE employee SET name = '$name', address = '$address', email = '$email', pnumber = '$pnumber', gender = '$gender' WHERE empid = '$empide'";
$result=mysqli_query($con,$sql);
// $result will give you TRUE or FALSE
if (!result) {
    printf("Error: %s\n", mysqli_error($con));
}else{
    // success
}

Hope it will help you :-)

Ravi Hirani
  • 6,511
  • 1
  • 27
  • 42
  • At least I got an error this time.Now will find someway to correct that error.thank you btw this is the error Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''employee' SET name = 'Guff', address = 'h.no 169, Hyd' at line 1 – Machine Mar 09 '16 at 14:16
  • @Guff: Remove single quote from tablename. Use employee instead of "employee". – Ravi Hirani Mar 09 '16 at 14:19
  • Check this link for more detail. http://www.w3schools.com/php/php_mysql_update.asp – Ravi Hirani Mar 09 '16 at 14:19
  • you the man .It worked been trying to remove this error for two days – Machine Mar 09 '16 at 14:22
  • I'm glad I've helped you. :-) – Ravi Hirani Mar 09 '16 at 15:26
0

you are using single quotes around your variables. In PHP, i.e. '$name' it will take the string $name and not the value of the variable. The Update query should looks like this

$sql = 'UPDATE employee SET name="'.$name.'", address="'.$address.'" WHERE empid="'.$empide.'"';
yangsunny
  • 656
  • 5
  • 13
  • 32