skrypt pobiera mi dane z bazy i pokazuje je w formularzu, ale jak chce je zminie i chce zaktualizowac to wywala mi blad:
Notice: Undefined index: id in F:\EasyPHP-12.1\www\glencaldy\editstudent.php on line 33
w tabeli 'student' mam pola: studentid, firstname, surname, username, password. chce zeby moliwa byla edycja wsyzstkich poza studentid.
jak zmienialem w tej 33 lini id na student id to wogole nie pobiera danych i nie wyskakuje ten blad juz na glownej stronie. oto kod mojego skryptu edycji danych. moglby ktos mi pomoc z tym albo dac jakies wskazowki? musze to skonczyc do szkoly w tym tygodniiu
<?php
// Connects to your Database
//checks cookies to make sure they are logged in
if (isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
//if the cookie has the wrong password, they are taken to the login page
if ($pass != $info['password']) {
header("Location: login.php");
}
//otherwise they are shown the admin area
else {
$a = trim($_REQUEST['a']); if ($a == 'edit' and
!empty($id)) { studentid='$id'") or
die('Error');
// read content of table
echo "<h1>EDIT STUDENT</h1><p>"; echo '<form action="editstudent.php" method="post"> <input type="hidden" name="a" value="save" />
<input type="hidden" name="studentid" value="' . $id . '" />
First name:<br />
<input type="text" name="firstname"
value="' . $r['firstname'] . '" /><br />
Surname:<br />
<input type="text" name="surname"
value="' . $r['surname'] . '" /><br />
Username:<br />
<input type="text" name="username"
value="' . $r['username'] . '" /><br />
Password:<br />
<input type="text" name="password"
value="' . $r['password'] . '" /><br />
<input type="submit" value="Update Record" />
</form>';
echo "<a href=deletestudent.php><< Back to delete/edit menu</a><p>"; echo "<a href=menu.php><< Back to main menu</a><p>";
}
}
}
}
} elseif ($a == 'save') {
// get the new records from form
$id = $_POST['studentid'];
$firstname = trim($_POST['firstname']); $surname = trim($_POST['surname']); $username = trim($_POST['username']); $password = trim($_POST['password']); // update table
mysql_query("UPDATE studnet SET firstname='$firstname', surname='$surname', username='&username', password='$password' WHERE studentid='$id'") or
die('Error'); }
else
//if the cookie does not exist, they are taken to the login screen
{
header("Location: login.php");
}
?>
tutaj wrzucam paczke z calym skryptem:
https://dl.dropbox.com/u/63492647/glencaldy_dp.zip