Click here to Skip to main content
15,844,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<?php


include 'connect.php';
$id=$_GET['id'];
$select ="SELECT * FROM job1 WHERE id='$id'";
  $data= mysqli_query($con,$select);
  $row=mysqli_fetch_array($data);

?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>form</title>
 
</head>
<body>
     <form action="" method="post">


     <table>
     <tr>
       <td>name:<td>
           <td><input type="text" name="name" value="<?php echo $row['name'] ?>" id=""></td> 
       </tr>
       <tr> 
       <td>email:<td>
           <td><input type="email" name="email" value="<?php echo $row['email'] ?>" id=""></td> 
       </tr>
       <td>degree:<td>
           <td><input type="number" name="number" value="<?php echo $row['phn'] ?>" id=""></td> 
       </tr>
       <td>degree:<td>
           <td><input type="sub" name="sub" value="<?php echo $row['sub'] ?>" id=""></td> 
       </tr>
       <tr>
       <td>:<td>
           <td><input type="submit" value="update" name="update"></td> 
       </tr>
       
       <td>:<td>
           <td><button><a href="view.php">check form</a></button></td> 
       </tr>
       
       </table>
     </form>
</body>
</html>
<?php



if(isset($_POST['update']))
{
    $name=$_POST['name'];
    $email=$_POST['email'];
    $number=$_POST['number'];
    $sub=$_POST['sub'];

    $update="UPDATE  job1 SET name='$name',email='$email',phn='$number',sub='$sub' WHERE id='$id";
    $res=mysqli_query($con,$update);
  

    
}


?>


What I have tried:

i have tried it many time to update data bt i failed


Fatal error: Uncaught mysqli_sql_exception: 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 ''2' at line 1 in C:\xampp\htdocs\database\update.php:67 Stack trace: #0 C:\xampp\htdocs\database\update.php(67): mysqli_query(Object(mysqli), 'UPDATE job1 SE...') #1 {main} thrown in C:\xampp\htdocs\database\update.php on line 67
Posted
Updated 29-Apr-22 1:38am
v4
Comments
OriginalGriff 29-Apr-22 4:21am    
Failed what?
We have no idea what your problem is, or what that code is supposed to do!

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?

That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!

Use the "Improve question" widget to edit your question and provide better information.
280_ Khadiza Akter_7A 29-Apr-22 5:32am    
actually i cant update data

Quote:
actually i cant update data
$update="UPDATE  job1 SET name='$name',email='$email',phn='$number',sub='$sub' WHERE id='$id";

Don't do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?

Fix that throughout your whole app, and you may find the error has gone away at the same time.
 
Share this answer
 
Try this
PHP
$update="UPDATE  job1 SET name='$name',email='$email',phn='$number',sub='$sub' WHERE id='$id'";
// a single quote was missing                                                          here ^


Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900