hype_rain Posted October 1, 2010 Share Posted October 1, 2010 Hi Everyone, I am working with an exercise from Adobe Dreamweaver CS5 with PHP Training from the Source. I am trying update a user in the database by clicking an "EDIT" link in a "USER LIST PAGE" which will take me to the "UPDATE USER" page. ButWhen I click the edit button, I get an error that says, 'Notice: Undefined index: password in C:\vhosts\phpcs5\lesson06\workfiles\update_user.php on line 45' The update user form shows up with the specified criteria (first name, last name, user name) already populated in the update form, as desired. Here is the code for my "USER LIST" page (I don't know how much code to include because I am new to this so I put it all here): <?php require_once('../../Connections/cs5read.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_getUsers = 10; $pageNum_getUsers = 0; if (isset($_GET['pageNum_getUsers'])) { $pageNum_getUsers = $_GET['pageNum_getUsers']; } $startRow_getUsers = $pageNum_getUsers * $maxRows_getUsers; mysql_select_db($database_cs5read, $cs5read); $query_getUsers = "SELECT user_id, first_name, family_name, username FROM users ORDER BY family_name ASC"; $query_limit_getUsers = sprintf("%s LIMIT %d, %d", $query_getUsers, $startRow_getUsers, $maxRows_getUsers); $getUsers = mysql_query($query_limit_getUsers, $cs5read) or die(mysql_error()); $row_getUsers = mysql_fetch_assoc($getUsers); if (isset($_GET['totalRows_getUsers'])) { $totalRows_getUsers = $_GET['totalRows_getUsers']; } else { $all_getUsers = mysql_query($query_getUsers); $totalRows_getUsers = mysql_num_rows($all_getUsers); } $totalPages_getUsers = ceil($totalRows_getUsers/$maxRows_getUsers)-1; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Registered Users</title> <link href="../../styles/users.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Registered Users</h1> <table> <tr> <th scope="col">Real name</th> <th scope="col">Username</th> <th scope="col"> </th> <th scope="col"> </th> </tr> <?php do { ?> <tr> <td><?php echo $row_getUsers['first_name']; ?> <?php echo $row_getUsers['family_name']; ?></td> <td><?php echo $row_getUsers['username']; ?></td> <td><a href="update_user.php?user_id=<?php echo $row_getUsers['user_id']; ?>">EDIT</a></td> <td><a href="delete_user.php?user_id=<?php echo $row_getUsers['user_id']; ?>">DELETE</a></td> </tr> <?php } while ($row_getUsers = mysql_fetch_assoc($getUsers)); ?> </table> </body> </html> <?php mysql_free_result($getUsers); ?> Here is the code for my "UPDATE USER" page: <?php require_once('../../Connections/cs5write.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_Recordset1 = "-1"; if (isset($_GET['user_id'])) { $colname_Recordset1 = $_GET['user_id']; } mysql_select_db($database_cs5write, $cs5write); $query_Recordset1 = sprintf("SELECT user_id, first_name, family_name, username FROM users WHERE user_id = %s", GetSQLValueString($colname_Recordset1, "int")); $Recordset1 = mysql_query($query_Recordset1, $cs5write) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); if (isset($_POST['password']) && empty($_POST['password'])) { $_POST['password'] = $row_getUser['password']; }else{ $_POST['password'] = sha1($_POST['password']); } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE users SET first_name=%s, username=%s, password=%s WHERE user_id=%s AND family_name=%s", GetSQLValueString($_POST['first_name'], "text"), GetSQLValueString($_POST['username'], "text"), GetSQLValueString($_POST['password'], "text"), GetSQLValueString($_POST['user_id'], "int"), GetSQLValueString($_POST['surname'], "text")); mysql_select_db($database_cs5write, $cs5write); $Result1 = mysql_query($updateSQL, $cs5write) or die(mysql_error()); $updateGoTo = "user_list.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Update user details</title> <link href="../../styles/users.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Update User Record</h1> <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <fieldset> <legend>Leave password blank if no change</legend> <p> <label for="first_name">First name:</label> <input name="first_name" type="text" id="first_name" value="<?php echo $row_Recordset1['first_name']; ?>" /> </p> <p> <label for="surname">Family name:</label> <input name="surname" type="text" id="surname" value="<?php echo $row_Recordset1['family_name']; ?>" /> </p> <p> <label for="username">Username:</label> <input name="username" type="text" id="username" value="<?php echo $row_Recordset1['username']; ?>" /> </p> <p> <label for="password">Password:</label> <input type="password" name="password" id="password" /> </p> <p> <label for="conf_password">Confirm password:</label> <input type="password" name="conf_password" id="conf_password" /> </p> <p> <input name="user_id" type="hidden" id="user_id" value="<?php echo $row_Recordset1['user_id']; ?>" /> <input type="submit" name="add_user" id="add_user" value="Update" /> </p> </fieldset> <input type="hidden" name="MM_update" value="form1" /> </form> </body> </html> <?php mysql_free_result($Recordset1); ?> Thank you in advance for your help. Quote Link to comment https://forums.phpfreaks.com/topic/214883-call-to-undefined-index/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.