0

Hi everyone, can you help me how to add update form in this code?

<html>
<head>
<title>Eastern Mediterranean University-Student's ID</title>
</head>
<body>
<h3>Edit Student</h3>

<?php
$num=$_POST['num'];


@ $db = new mysqli('localhost', 'root', 'ilyas1987', 'dau');
if (mysqli_connect_errno()) {
	echo 'Error: Could not connect to database. Please try again.';
	exit;
}

$query = "select * from students where num='$num'";
$result = $db->query($query);
$row = $result->fetch_assoc();
echo $query;

echo "<tr>

<form method='post' action='sonuc.php' >
<input type='hidden' name='num' value='$num'>
	<b>ID:</b><br>
	<input type='text' name='id' value='".$row['id']."' size='10'>
	<br>	
	<b>Name:</b><br>
	<input type='text' name='name' value='".$row['name']."' size='10'>
	<br>
	<b>Surname:</b><br>
	<input type='text' name='surname' value='".$row['surname']."' size='10'>
	<br>
	<b>Department:</b><br>
	<input type='text' name='department' value='".$row['department']."' size='10'>
	<br>
	<b>GPA:</b><br>
	<input type='text' name='cpa' value='".$row['cpa']."' size='10'>
	<br>
	<br>
	<input type='submit' name='edit' value='Save'><br>
	</form>
	</tr><br />\n";
$result->free();
$db->close();
?>
</body>
</html>
2
Contributors
2
Replies
8
Views
7 Years
Discussion Span
Last Post by ilyas_varol
0

Its simple as you do code for insert same thing should be there for update.
Like insert query here you will have update query.

<html>
<head>
<title>Eastern Mediterranean University-Student`s ID</title>
</head>
<body>
<h3>Edit Student</h3>

<?php
$num=$_POST['num'];


@ $db = new mysqli('localhost', 'root', 'ilyas1987', 'dau');
if (mysqli_connect_errno()) {
	echo 'Error: Could not connect to database. Please try again.';
	exit;
}

//-------------- update is clicked ----------------
if(isset($_REQUEST['edit']))
{
	$id = $_REQUEST['id'];
	$name = $_REQUEST['name'];
	$surname = $_REQUEST['surname'];
	$department = $_REQUEST['department'];
	$cpa = $_REQUEST['cpa'];
	
	$q="update students set 
		name = '".$name."',
		surname = '".$surname."',
		department = '".$department."',
		cpa = '".$cpa."'
		where id = ".$id;
	mysql_query($q);
	
	header('Location:succupdate.php');
	exit;
	
}

$query = "select * from students where num='$num'";
$result = $db->query($query);
$row = $result->fetch_assoc();
echo $query;

echo "<tr>

<form method='post' action='sonuc.php' >
<input type='hidden' name='num' value='$num'>
	<b>ID:</b><br>
	<input type='text' name='id' value='".$row['id']."' size='10'>
	<br>	
	<b>Name:</b><br>
	<input type='text' name='name' value='".$row['name']."' size='10'>
	<br>
	<b>Surname:</b><br>
	<input type='text' name='surname' value='".$row['surname']."' size='10'>
	<br>
	<b>Department:</b><br>
	<input type='text' name='department' value='".$row['department']."' size='10'>
	<br>
	<b>GPA:</b><br>
	<input type='text' name='cpa' value='".$row['cpa']."' size='10'>
	<br>
	<br>
	<input type='submit' name='edit' value='Save'><br>
	</form>
	</tr><br />\n";
$result->free();
$db->close();
?>
</body>
</html>

Edited by vibhaJ: n/a

This question has already been answered. 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.