Jump to content

hype_rain

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

hype_rain's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey Gizmo, Here is my code into which I would like to place the code you gave me. I keep screwing it up. Can you tell me how to place properly? $errors = array();if ($_POST) { // run the validation script require_once('library.php'); try {// main script goes here$val = new Zend_Validate_Regex('/^[a-z]+[-\'a-z ]+$/i');if (!$val->isValid($_POST['first_name'])) { $errors['first_name'] = 'Required field, no numbers';}if (!$val->isValid($_POST['surname'])) { $errors['surname'] = 'Required field, no numbers';}$val = new Zend_Validate();$length = new Zend_Validate_StringLength(6,15);$val->addValidator($length);$val->addValidator(new Zend_Validate_Alnum());if (!$val->isValid($_POST['username'])) { $errors['username'] = 'Use 6-15 letters or numbers only';} else { $sql = $dbRead->quoteInto('SELECT user_id FROM users WHERE username = ?', $_POST['username']); $result = $dbRead->fetchAll($sql); if ($result) { $errors['username'] = $_POST['username'] . ' is already in use'; }}$length->setMin(;$val = new Zend_Validate();$val->addValidator($length);$val->addValidator(new Zend_Validate_Alnum());if (!$val->isValid($_POST['password'])) { $errors['password'] = 'Use 8-15 letters or numbers only';}$val = new Zend_Validate_Identical($_POST['password']);if (!$val->isValid($_POST['conf_password'])) { $errors['conf_password'] = "Passwords don't match";}$val = new Zend_Validate_EmailAddress();if (!$val->isValid($_POST['email'])) { $errors['email'] = 'Use a valid email address';}if (!$errors) { //insert the details into the database $data = array('first_name' => $_POST['first_name'], 'family_name' => $_POST['surname'], 'username' => $_POST['username'], 'password' => sha1($_POST['password'])); $dbWrite->insert('users', $data); header('Location: login.php');} } catch (Exception $e) {echo $e->getMessage(); }} Thanks! Hype
  2. Hey Giz, Thanks for the prompt reply. I have been trying to successfully add this to my validation code, but no success. I am going to take a couple more stabs at it, though. If I still don't have any progress I will let you know ( I am VERY sure it's something I'm doing or not doing). I have some exposure to PHP, but am still kinda new. I took a 6 week class (a joke) in which the instructor's answer to most things was, "...who cares how it works? It just works..." (and the remarkable scholarship of the western world just rolls right on). My point is this: I want to master the language and copying things into my pages without a.) understanding what is going on b.) without trying it myself is (besides being plain lazy) not what gets really killer web applications built. I know that much, if nothing else. So, again, thanks for getting me started. I will keep trying and come back with solid, intelligent questions. Also, can you please comment on (or suggest) any books for learning php? Right now, I am using the [...] videos, along with a couple other books (I don't know if I can mention proprietary names in these posts--can I?). Lemme kno. Thanks! Hype...
  3. Hi, I looked at the other posts on this subject, but due to fact that I am new to this and it is difficult to determine if some of the solutions are on point with my issue and I don't want to start extracting pieces of code that "look like" they could be the answer (thereby confusing myself even further), I just thought I would keep it simple, show you guys what I got, tell you what I want, and listen and learn. I want to code regular expressions for email addresses. Here is what I am using for basic validation $val = new Zend_Validate_EmailAddress(); if (!$val->isValid($_POST['email'])) { $errors['email'] = 'Use a valid email address'; } I don't know if Zend qualifies as "third party", because I don't know if that refers to frameworks. If it belongs in another forum, please move it and I will get the message and follow the thread (if any) accordingly. Kindly, Hype
  4. good deal, Thorpe. Makes all the sense in the world. I have already begun reading the book and am looking forward putting the stuff to work. Regarding, the IDE overkill observation, I can easily see how this would be a fact of life with such tools. I will be talking with you more, I'm sure. Hype...
  5. Well taken. I understand your point. Also, The interface really is getting on my nerves. Just as with HTML / CSS, it is often so much easier just to write the stuff by hand. What book would you recommend? Also, what makes DW code so bad? Certainly would like to beware of that stuff so I can avoid it. Thanks, Thorpe.
  6. 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.
  7. Hi All, New to PHP. Thanks for the invitation to introduce myself. I own Hype Rain Studio. I am a designer by trade who is studying to be a programmer. I have some background with AS3 and Javascript, but since I don't do it much at all, I don't consider myself a programmer. I do understand the concepts very well, but I just haven't done it enough. I am, however at an "advanced intermediate" level with HTML & CSS. I was going to start with Coldfusion, but thought it wise to start with PHP. I have decided to start my studies with Adobe Dreamweaver CS5 with PHP Training from the Source by David Powers (this book will be the impetus for most of the questions I will ask, here). From there, I will keep working through exercises in other books and videos to keep in practice until I my client load starts to keep me writing code all the time. I hope to become and expert and begin to answer questions for other members, once I achieve some semblance of fluency with the language. Thanks! Hype
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.