Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the database cannot update the data and
$customer_id =$_GET['customer_id'];
is error here. someone please help me :'(

What I have tried:

<?php

include "config.php";
$link = mysqli_connect($h ,$u ,$p,$db);
$customer_id =$_GET['customer_id'];

$sql="select*from customer where customer_id='$customer_id' ";
$result=mysqli_query($link,$sql);
$check =mysqli_fetch_array($result);

if (isset($_POST['done']))
{

$cuname=$_POST['cuname'];
$phoneno=$_POST['phoneno'];
$email=$_POST['email'];
$address=$_POST['address'];

$sql="update customer set cuname='$cuname',phoneno='$phoneno',email='$email',address='$address' where customer_id='$customer_id'";

if(!$sql)
{
echo "error";
}
else {
echo "try again" ;
}
}


?>

<html>
<form  method=post onsubmit="return check()"  >
<input type="text" name="cuname" value="<?php echo $check['cuname'];?>" placeholder="name">
<input type="text" name="phoneno" value="<?php echo $check['phoneno'];?>" placeholder="phoneno">
<input type="text" name="email" value="<?php echo $check['email'];?>" placeholder="email">
<input type="text" name="address" value="<?php echo $check['address'];?>" placeholder="address">
<input type="submit" name="done" >

</form>
</html>
<a href="home.html">Home</a>
Posted
Updated 8-Dec-18 2:43am

1 solution

Quote:
the database cannot update the data and
PHP
$customer_id =$_GET['customer_id'];

is error here.

What error message ?
An error in code before updating statement id enough to prevent any update.
Also make sure customer_id exist in your form.

PHP
$sql="update customer set cuname='$cuname',phoneno='$phoneno',email='$email',address='$address' where customer_id='$customer_id'";

Not necessary a solution to your question, but another problem you have.
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[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
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