jim.davidson Posted April 12, 2007 Share Posted April 12, 2007 I’m running PHP 5.0 – MySQL 4.1.21 – Dreamweaver 8 I’ve hit a roadblock, I have a page to update user information. Everything works except I don’t know how to get the current user level from the record set to display in the list menu. I don’t know if this helps but here’s the code for the whole page. I sure the code will look messy, but I’m new to this and still learning as I go. I would appreciate any and all help <?php require_once('Connections/imcrecycle.php'); ?> <?php if (!isset($_SESSION)) { session_start(); } if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $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; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } $colname_getUser = "-1"; if (isset($_GET['user_id'])) { $colname_getUser = $_GET['user_id']; } mysql_select_db($database_imcrecycle, $imcrecycle); $query_getUser = sprintf("SELECT * FROM users WHERE user_id = %s", GetSQLValueString($colname_getUser, "int")); $getUser = mysql_query($query_getUser, $imcrecycle) or die(mysql_error()); $row_getUser = mysql_fetch_assoc($getUser); $totalRows_getUser = mysql_num_rows($getUser); $error = array(); // Validate form input $MM_flag="MM_update"; if (isset($_POST[$MM_flag])) { // Check Name if (empty($_POST['first_name']) || empty($_POST['last_name'])) { $error['name'] = 'Please enter both first and last names'; } // remaining checks go here // set a flag that assumes the password is ok $pwdOK = true; //trim leading and trailing whitespaces from password $_POST['password'] = trim($_POST['password']); // if password field is empty, use existing password if (empty($_POST['password'])) { $_POST['password'] = $row_getUser['password']; } // Otherwise conduct normal checks else { // if less than 6 characters create an alert and set flag to false if (strlen($_POST['password']) < 6) { $error['password_length'] = 'Your password must be at least six characters'; $pwdOK = false; } // if password no match to confirmation set password flag to false if ($_POST['password'] != trim($_POST['confirm_password'])) { $error['password'] = 'Your passwords don\'t match'; $pwdOK = false; } if ($pwdOK) { $_POST['password'] = sha1($_POST['password']); } } // check username $_POST['username'] = trim($_POST['username']); $loginUsername = $_POST['username']; if (strlen($loginUsername) < 6) { $error['length'] = 'Please select a username that contains at least six characters'; } $LoginRS__query = sprintf("SELECT username FROM users WHERE username=%s AND user_id != %s", GetSQLValueString($loginUsername,"text"), GetSQLValueString($_POST['user_id'], "int")); mysql_select_db($database_imcrecycle, $imcrecycle); $LoginRS=mysql_query($LoginRS__query, $imcrecycle) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); //if there is a row in the database, the username was found - can not add the requested username if($loginFoundUser){ $error['username'] = "$loginUsername is already in use. Please choose a different username."; } } if (!$error) { if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "updateUser")) { $updateSQL = sprintf("UPDATE users SET username=%s, password=%s, first_name=%s, last_name=%s, user_level=%s WHERE user_id=%s", GetSQLValueString($_POST['username'], "text"), GetSQLValueString($_POST['password'], "text"), GetSQLValueString($_POST['first_name'], "text"), GetSQLValueString($_POST['last_name'], "text"), GetSQLValueString($_POST['UserLevel'], "text"), GetSQLValueString($_POST['user_id'], "int")); mysql_select_db($database_imcrecycle, $imcrecycle); $Result1 = mysql_query($updateSQL, $imcrecycle) or die(mysql_error()); $updateGoTo = "recycle_list_users.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=iso-8859-1" /> <title>IMC Recycle Update User</title> <link href="CssFiles/IMC.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style1 {font-size: xx-large} .style3 { font-size: 12px; color: #FF0000; font-style: italic; } --> </style> </head> <body> <?PHP include('recycle_heading.php');?> <?PHP include('left_logo.php');?> <p align="center" class="formlabel style1"> Update User Information </p> <div align="center" > <?php if ($error) { echo '<ul>'; foreach ($error as $alert) { echo "<li class='warning'>$alert</li>\n"; } echo '</ul>'; // remove escape characters from POST array if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); } } ?> </div> <table width="640" border="0" align="center" cellpadding="0"> <tr> <th scope="col"><form action="<?php echo $editFormAction; ?>" id="updateUser" name="updateUser" method="POST"> <p> </p> <table width="560" border="0" align="center" cellpadding="0"> <tr> <td width="202" class="formlabel"><div align="right">First Name:</div></td> <td width="12"> </td> <td width="187"><div align="left"> <input value="<?php if (isset($_POST['first_name'])) {echo $_POST['first_name'];} else { echo $row_getUser['first_name'];} ?>" type="text" name="first_name" id="first_name" /> </div></td> </tr> <tr> <td class="formlabel"><div align="right"></div></td> <td> </td> <td> </td> </tr> <tr> <td class="formlabel"><label for="label2"> </label> <div align="right">Last Name:</div></td> <td> </td> <td><div align="left"> <input value="<?php if (isset($_POST['last_name'])) {echo $_POST['last_name'];} else { echo $row_getUser['last_name'];} ?>" type="text" name="last_name" id="label" /> </div></td> </tr> <tr> <td class="formlabel"><div align="right"></div></td> <td> </td> <td> </td> </tr> <tr> <td class="formlabel"><label for="textfield"> </label> <div align="right">Username:</div></td> <td> </td> <td> <div align="left"> <input value="<?php if (isset($_POST['username'])) {echo $_POST['username'];} else { echo $row_getUser['username'];} ?>" type="text" name="username" id="username" /> </div></td> </tr> <tr> <td class="formlabel"><div align="right"></div></td> <td> </td> <td> </td> </tr> <tr> <td class="formlabel"><div align="right">Password:</div></td> <td> </td> <td><div align="left"> <input type="password" name="password" id="password" /> <span class="style3">Leave blank if not changing</span> </div></td> </tr> <tr> <td class="formlabel"><div align="right"></div></td> <td> </td> <td> </td> </tr> <tr> <td class="formlabel"><div align="right">Confirm Password:</div></td> <td> </td> <td><div align="left"> <input type="password" name="confirm_password" id="confirm_password" /> </div></td> </tr> <tr> <td class="formlabel"><div align="right"></div></td> <td> </td> <td> </td> </tr> <tr> <td class="formlabel"><div align="right"><span class="radioLabel">User Level :</span></div></td> <td> </td> <td><div align="left"> <select name="UserLevel" id="UserLevel"><?php if (isset($_POST['user_level'])) {echo $_POST['user_level'];} else { echo $row_getUser['user_level'];} ?> <option value="1">Level 1</option> <option value="2">Level 2</option> <option value="3">Level 3</option> <option value="4">Level 4</option> <option value="5">Level 5</option> </select> </div></td> </tr> <tr> <td class="formlabel"><div align="right"></div></td> <td> </td> <td> </td> </tr> <tr> <td class="formlabel"><div align="right"></div></td> <td> </td> <td> </td> </tr> <tr> <td class="formlabel"><div align="right"></div></td> <td> </td> <td><input type="image" name="imageField" src="images/Update_User_info.gif" /></td> </tr> </table> </p> <input name="user_id" type="hidden" id="user_id" value="<?php echo $row_getUser['user_id']; ?>" /> <input type="hidden" name="MM_update" value="updateUser"> </form></th> </tr> <tr> <td><a href="recycle_users_menu.php"><img src="images/Return_to_User_Menu.gif" width="332" height="27" border="0" /></a></td> </tr> <tr> <td> </td> </tr> <tr> <td><a href="recycle_users_list.php"><img src="images/Go_to_Users_list.gif" width="332" height="27" border="0"/></a></td> </tr> </table> <p> </p> <p> </p> <p><a href="recycle_users_menu.php"></a> </p> <p><a href="recycle_users_list.php"></a> </p> </body> </html> <?php mysql_free_result($getUser); ?> Link to comment https://forums.phpfreaks.com/topic/46715-solved-need-help-with-list-menu/ Share on other sites More sharing options...
trq Posted April 12, 2007 Share Posted April 12, 2007 You might want to narrow your code down to what is relevent. No one wants to sit through all that, sorry. Link to comment https://forums.phpfreaks.com/topic/46715-solved-need-help-with-list-menu/#findComment-227574 Share on other sites More sharing options...
jim.davidson Posted April 12, 2007 Author Share Posted April 12, 2007 Ok here's the section I'm talking about, if user_level from the record set is 3 how do I get the the page to display 'Level 3' <select name="UserLevel" id="UserLevel"><?php if (isset($_POST['user_level'])) {echo $_POST['user_level'];} else { echo $row_getUser['user_level'];} ?> <option value="1">Level 1</option> <option value="2">Level 2</option> <option value="3">Level 3</option> <option value="4">Level 4</option> <option value="5">Level 5</option> </select> Link to comment https://forums.phpfreaks.com/topic/46715-solved-need-help-with-list-menu/#findComment-227591 Share on other sites More sharing options...
trq Posted April 12, 2007 Share Posted April 12, 2007 <option value="1" <?php ($row_getUser['user_level'] ==1 ? echo 'selected="selected"' : '') ?>>Level 1</option> <option value="2" <?php ($row_getUser['user_level'] ==2 ? echo 'selected="selected"' : '') ?>>Level 2</option> <option value="3" <?php ($row_getUser['user_level'] ==3 ? echo 'selected="selected"' : '') ?>>Level 3</option> <option value="4" <?php ($row_getUser['user_level'] ==4 ? echo 'selected="selected"' : '') ?>>Level 4</option> <option value="5" <?php ($row_getUser['user_level'] ==5 ? echo 'selected="selected"' : '') ?>>Level 5</option> Link to comment https://forums.phpfreaks.com/topic/46715-solved-need-help-with-list-menu/#findComment-227599 Share on other sites More sharing options...
jim.davidson Posted April 12, 2007 Author Share Posted April 12, 2007 I get an error Parse error: parse error, unexpected T_ECHO says error is on this line <option value="1" <?php ($row_getUser['user_level'] ==1 ? echo 'selected="selected"' : '') ?>>Level 1</option> Here's the section of code <select name="UserLevel" id="UserLevel"><?php if (isset($_POST['user_level'])) {echo $_POST['user_level'];} else { echo $row_getUser['user_level'];} ?> <option value="1" <?php ($row_getUser['user_level'] ==1 ? echo 'selected="selected"' : '') ?>>Level 1</option> <option value="2" <?php ($row_getUser['user_level'] ==2 ? echo 'selected="selected"' : '') ?>>Level 2</option> <option value="3" <?php ($row_getUser['user_level'] ==3 ? echo 'selected="selected"' : '') ?>>Level 3</option> <option value="4" <?php ($row_getUser['user_level'] ==4 ? echo 'selected="selected"' : '') ?>>Level 4</option> <option value="5" <?php ($row_getUser['user_level'] ==5 ? echo 'selected="selected"' : '') ?>>Level 5</option> </select> Link to comment https://forums.phpfreaks.com/topic/46715-solved-need-help-with-list-menu/#findComment-227685 Share on other sites More sharing options...
trq Posted April 12, 2007 Share Posted April 12, 2007 Sorry, in a bit of a daydream here. They should all be like... <option value="1" <?php echo ($row_getUser['user_level'] ==1 ? 'selected="selected"' : '') ?>>Level 1</option> Link to comment https://forums.phpfreaks.com/topic/46715-solved-need-help-with-list-menu/#findComment-227689 Share on other sites More sharing options...
jim.davidson Posted April 12, 2007 Author Share Posted April 12, 2007 Thank you very much, that did it, I tried to find the answer myself without any luck. This web site is a godsend. I love it. On last question...how do I mark this as being solved? Link to comment https://forums.phpfreaks.com/topic/46715-solved-need-help-with-list-menu/#findComment-227717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.