Ich werde die Studentendatenbank aktualisieren, die Name, Standort, Adresse und Telefonnummer für eine bestimmte ID enthält.Wenn ich den unten stehenden Code ausführen, sagt undefined Mitte gibt, können Sie bitte überprüfen es und korrigieren, meine Fehler bitte .... hier ist mein Code insert.phpUpdate funktioniert nicht geben undefined Variable
<?php
$user="root";
$server="localhost";
$password="";
$db="students";
$dbconn= mysql_connect($server,$user,$password);
mysql_select_db($db,$dbconn);
if(isset($_POST['submit'])) {
$name=mysql_real_escape_string($_POST['name']);
$location=mysql_real_escape_string($_POST['location']);
$address=mysql_real_escape_string($_POST['address']);
$phonenumber=mysql_real_escape_string($_POST['phonenumber']);
$str="insert into info(name,location,address,phonenumber) VALUES ('$name','$location','$address','$phonenumber')";
$query=mysql_query($str);
if($query) {
echo"Inserted Successfully";
} else {
echo "Insert Failed";
}
$query2=mysql_query("select * from info");
echo "<table border='2'>";
echo "<tr><th>Name</th><th>Location</th><th>Address</th><th>Phonenumber</th><th>Action</th></tr>";
while($row=mysql_fetch_array($query2)) {
echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['location']."</td>";
echo "<td>".$row['address']."</td>";
echo "<td>".$row['phonenumber']."</td>";
echo "<td><a href='modify.php?sid=".$row['id']."'>Update</a></td>";
echo "</tr>";
}
echo "</table>";
}
?>
modify.php
<?php
$user="root";
$server="localhost";
$password="";
$db="students";
$dbconn= mysql_connect($server,$user,$password);
mysql_select_db($db,$dbconn);
if(isset($_GET['sid'])) {
$mid=$_GET['sid'];
echo $mid;
}
$q="select * from info where id=$mid";
echo $q;
$query3=mysql_query($q);
$row=mysql_fetch_array($query3);
?>
<html>
<head><title>Updation</title></head>
<body>
<form method="POST" action="edit.php" id="myform">
EnterName:<input type="text" name="name" id="name" value="<?php echo $row['name'];?>"><br/>
EnterLocation:<input type="text" name="location" id="location"value="<?php echo $row['location'];?>"><br/>
EnterAddress:<input type="text" name="address" id="address" value="<?php echo $row['address'];?>"><br/>
EnterPhoneNumber:<input type="text" name="phonenumber" id="phonenumber" value="<?php echo $row['phonenumber'];?>"><br/>
<input type="hidden" name="id" value=<?php if(isset($mid)) echo $mid; ?>>
<input type="submit" name="update" value="update">
</form>
</body>
</html>
Schließlich i-Update am Umleiten edit.php edit.php
<?php
$user="root";
$server="localhost";
$password="";
$db="students";
$dbconn= mysql_connect($server,$user,$password);
mysql_select_db($db,$dbconn);
if(isset($_GET['sid'])) {
$mid=$_GET['sid'];
echo $mid;
}
?>
<html>
<head><title></title></head>
<body>
<form>
<input type="hidden" name="id" value="<?php if(isset($mid)) echo $mid; ?>">
</form>
</body>
</html>
<?php
if(isset($_POST['update'])) {
echo $mid;
$name=mysql_real_escape_string($_POST['name']);
$location=mysql_real_escape_string($_POST['location']);
$address=mysql_real_escape_string($_POST['address']);
$phonenumber=mysql_real_escape_string($_POST['phonenumber']);
$query5=mysql_query("update info set name='$name',location='$location',address='$address',phonenumber='$phonenumber' where id=$mid");
if($query5) {
echo "update success";
} else {
echo "Update Failed";
}
}
?>
Woher bekommst du diesen Code? : S Sie können nach PHP-Update-Abfrage in PHP in Google suchen und nie wieder MySQL_ verwenden! Sie müssen Ihre Skripte wirklich wieder mit richtiger Kodierung schreiben! – Soheyl
Wenn '$ mid' nicht definiert ist, bedeutet dies normalerweise, dass es nicht definiert ist, um den Code zu beheben! – JustBaron