Prev | Current Page 65 | Next

Larry Ullman

"Building a Web Site with Ajax: Visual QuickProject Guide"


if (isset($_POST[???department_id??™]) && is_numeric($_
POST[???department_id??™]) && ($_POST[???department_id??™] >
0)) {
$did = (int) $_POST[???department_id??™];
} else {
$error = true;
echo ???department_id
???;
}
if (isset($_POST[???phone_ext??™]) && is_numeric($_
POST[???phone_ext??™]) && ($_POST[???phone_ext??™] > 0)) {
$ext = (int) $_POST[???phone_ext??™];
} else {
$error = true;
echo ???phone_ext
???;
}
adding records via Ajax 71
update the database
Assuming that the form data passed all the validation
routines, an INSERT query should be run.
1 If there were no errors, then this conditional will be true
(because the $error variable will be false).
2 The INSERT query adds the new employee to the database
using the purifi ed data from the validation routines.
3 The mysql_affected_rows() function returns the
number of, well, a?¬? ected rows. This should be 1, as one
new record should be added.
4 The results are added to the XML output,
using an element name of result.
??¦
echo ???phone_ext
???;
}
if (!$error) {
$q = ???INSERT INTO employees VALUES (NULL, $did,
???$fn??™, ???$ln??™, ???$e??™, $ext)???;
$r = mysql_query($q, $dbc);
if (mysql_affected_rows($dbc) == 1) {
echo ???The employee has been added.


Pages:
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77