Jump to content

frijole

Members
  • Posts

    214
  • Joined

  • Last visited

    Never

Everything posted by frijole

  1. thanks for the link. I am trying to use the box to display a register form. When I try to use my register.php file in the box, nothing shows up. Is there some special set-up for PHP files in the box?
  2. I am trying to get a register form to pop out when the link is clicked. replacing the log in form. Does anyone know a way to do this?
  3. sorry, that feature was disabled last time i was on the site. Thanks again.
  4. I am still working on my login script. I am trying to get the username of the person who signed to display on the front page that the form redirects to. I have a <?php echo $_SESSION['userName']; ?> on the front page. But, nothing is displayed. I can't tell why. <?php ob_start(); // buffer the output require_once 'dbConnect.php'; require_once 'functions.php'; $error = ''; if ($_POST['logIn'] == 1) { //if the form has been submitted $userName = $_POST['user']; $pass = $_POST['pass']; $query = "SELECT * FROM users WHERE user_name='$userName' AND user_pass='$pass'"; $result = mysql_query($query) or die("connection error."); if (empty($userName) || empty($pass)) { //are any of the fields empty $error = "All fields must be filled out.";} elseif (mysql_num_rows($result) != 1) { //if the username and password combo are not valid $error = "Invalid username, password combo.";} else { //log in was successful if (keepLogged ==1) { $year = 525600 + time(); setcookie(thinksnack, 1, $year); } $_SESSION['userName'] = $userName; $_SESSION['loggedIn'] = 1; header('Location: http://www.thinksnack.com/index.php'); } } showLogInForm ($error); ob_end_flush(); // dump the buffer ?>
  5. I am working on a log in script and I am trying to redirect the user back to the front page once they have logged in. This is my log in Script, followed by the attached functions: I would really appreciate some guidance if anyone has seen this before. <?php require_once 'dbConnect.php'; require_once 'functions.php'; $error = ''; if ($_POST['logIn'] == 1) { //if the form has been submitted $userName = $_POST['user']; $pass = $_POST['pass']; $query = "SELECT * FROM users WHERE user_name='$userName' AND user_pass='$pass'"; $result = mysql_query($query) or die("connection error."); if (empty($userName) || empty($pass)) { //are any of the fields empty $error = "All fields must be filled out.";} elseif (mysql_num_rows($result) != 1) { //if the username and password combo are not valid $error = "Invalid username, password combo.";} else { //log in was successful if (keepLogged ==1) { $year = 525600 + time(); setcookie(thinksnack, 1, $year); } $_SESSION['userName'] = $userName; $_SESSION['loggedIn'] = 1; header('Location: http://www.thinksnack.com/'); } } showLogInForm ($error); ?> <?PHP function showRegisterForm ($error) { echo $error; ?> <fieldset> <legend>Register</legend> <table> <form name="input" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <tr> <td>Username: </td> <td><input type="text" name="user"></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="pass"></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="rePass"></td> </tr> <tr> <input type="hidden" name="register" value="1"> <td><input type="submit" value="Submit"></td> </tr> </form> </table> </fieldset> <?PHP }?> <?PHP function showLogInForm ($error) { echo $error; ?> <table> <form name="input" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <tr> <td>username </td><td>password</td><td>stay logged in<input type="checkbox" name="keepLogged" value="1"></td> </tr><tr> <td><input type="text" name="user"></td> <td><input type="password" name="pass"></td> <input type="hidden" name="logIn" value="1"> <td><input type="submit" value="Submit"></td> </tr> </form> </table> <?php } ?>
  6. sweet, that's exactly it. Thank a lot!
  7. I am not sure if this effect is js or not. Does anyone know how to create the effect where you clink the register link on a sire and instead of opening up a new page it displays a box on top of the current page, and the background grays out a little? I am trying to find a tutorial or something, but it is hard to describe. Have you guys seen or know anything about setting that up?
  8. it's fixed! thanks so much guys. You've really been a huge help.
  9. ok, thank you so much for the help. Now it is inserting the data but it is inserting $userName as the username instead of the value that it holds.
  10. here is the error errorUnknown column '$userName' in 'field list'
  11. here is what I have now and it is acting as if it was successful, no error. It echoes "You have been successfully added" I don't get it. <?php //Database Settings $host = "localhost"; $dbUser = "thinksna"; $pass = "******"; $DB = "thinksna_db"; //MySQL Connection $conn = mysql_connect($host, $dbUser, $pass); if (!conn) { // the connection failed so quit the script die('Could not connect !<br />Please contact the site administrator.'); } $db = mysql_select_db($DB, $conn); if (!db) { // cannot connect to the database so quit the script die('Could not connect to database <br /> Please contact the site administrator.'); } //this script registers a new user. require_once 'functions.php'; $error = ''; if ($_POST['register'] == 1) { //if the form has been submitted $userName = $_POST['user']; $pass = $_POST['pass']; $rePass = $_POST['rePass']; $query = 'SELECT * FROM users WHERE user_id="$userName"'; $insertUser = 'INSERT INTO users VALUES ($userName, $pass)'; if (empty($userName) || empty($pass) || empty($rePass)) { //are any of the fields empty $error = "All fields must be filled out.";} elseif ($pass != $rePass) { //all fileds are filled out, are the values valid? $error = "The passwords do not match.";} elseif (strlen($pass) < 4 || strlen($pass) > 12) { //check if username is too long or too short $error = "You password must be between 4 and 12 characters long.";} elseif (strlen($userName) < 4 || strlen($userName) > 12) { //check if username is too long or too short $error = "You username must be between 4 and 12 characters long.";} elseif (preg_replace('/[\w ]/', '', $userName)) { //check for invalid characters in the username $error = "Your username may only contain letters, numbers, or underscores";} else { //check if username already exists $result = mysql_query($query) or mysql_error($conn); if (mysql_num_rows($result) > 0) { $error = "That username is already taken."; } else { //add user to the database if (strlen($error) > 0) { showRegisterForm($error); } else { $result = mysql_query($insertUser) or mysql_error($conn); echo 'You have been added! sign-in and enjoy.'; } } } //show form and errors if applicable } showRegisterForm($error); ?>
  12. so I would replace die with a mysql_error()?
  13. was anything changed here? or just reposted?
  14. My script is working as it should but when it gets to the point where it is supposed to query the DB, I a connection error. Here is the script: <?php //this script registers a new user. require_once 'dbConnect.php'; require_once 'functions.php'; $error = ''; if ($_POST['register'] == 1) { //if the form has been submitted $userName = $_POST['user']; $pass = $_POST['pass']; $rePass = $_POST['rePass']; $query = 'SELECT * FROM users WHERE user_id="$userName"'; $insertUser = 'INSERT INTO users VALUES ($userName, $pass)'; if (empty($userName) || empty($pass) || empty($rePass)) { //are any of the fields empty $error = "All fields must be filled out.";} elseif ($pass != $rePass) { //all fileds are filled out, are the values valid? $error = "The passwords do not match.";} elseif (strlen($pass) < 4 || strlen($pass) > 12) { //check if username is too long or too short $error = "You password must be between 4 and 12 characters long.";} elseif (strlen($userName) < 4 || strlen($userName) > 12) { //check if username is too long or too short $error = "You username must be between 4 and 12 characters long.";} elseif (preg_replace('/[\w ]/', '', $userName)) { //check for invalid characters in the username $error = "Your username may only contain letters, numbers, or underscores";} else { //check if username already exists $result = mysql_query($query) or die('Connection Error.'); if (mysql_num_rows($result) > 0) { $error = "That username is already taken."; } else { //add user to the database if (strlen($error) > 0) { showRegisterForm($error); } else { mysql_query($insertUser) or die('Connection Error.'); echo 'You have been added! sign-in and enjoy.'; } } } //show form and errors if applicable } showRegisterForm($error); ?> and here is my dbConnect.php which deals with the DB, minus the username etc. <?php //Database Settings define("HOST", "localhost"); define("DBUSER", "******"); define("PASS", "******"); define("DB", "******"); //MySQL Connection $conn = mysql_connect(HOST, DBUSER, PASS); if (!conn) { // the connection failed so quit the script die('Could not connect !<br />Please contact the site administrator.'); } $db = mysql_select_db(DB); if (!db) { // cannot connect to the database so quit the script die('Could not connect to database <br /> Please contact the site administrator.'); } ?> I would appreciate any ideas.
  15. Is this what you are saying? <?php //this script registers a new user. require_once 'dbConnect.php'; require_once 'functions.php'; $errors[] = array(); if (isset($_POST['register'])) { //if the form has been submitted $userName = $_POST['user']; $pass = $_POST['pass']; $rePass = $_POST['rePass']; $query = 'SELECT * FROM users WHERE user_id="$userName"'; $insertUser = 'INSERT INTO users VALUES ($userName, $pass)'; if (empty($userName) || empty($pass) || empty($rePass)) { //are any of the fields empty $errors[] = "All fields must be filled out.";} elseif ($pass != $rePass) { //all fileds are filled out, are the values valid? $errors[] = "The passwords do not match.";} elseif (strlen($pass) < 4 || strlen($pass) > 12) { //check if username is too long or too short $errors[] = "You password must be between 4 and 12 characters long.";} elseif (strlen($userName) < 4 || strlen($userName) > 12) { //check if username is too long or too short $errors[] = "You username must be between 4 and 12 characters long.";} elseif (preg_replace('/[\w ]/', '', $userName)) { //check for invalid characters in the username $errors[] = "Your username may only contain letters, numbers, or underscores";} else { //check if username already exists $result = mysql_query($query) or die('Connection Error.'); if (mysql_num_rows($result) > 0) { $errors[] = "That username is already taken.";} else { //add user to the database if (count($errors) > 0) { showRegisterForm($errors); } else { mysql_query($insertUser) or die('Connection Error.'); echo 'You have been added! sign-in and enjoy.'; } } } else { //show form and errors if applicable showRegisterForm(); } ?>
  16. what if it is the first run through the script. i.e. will this display the form the first time? Thank you for the help.
  17. I am trying to validate a register form. I have taken care of the errors but it is not working correctly. When I fill in the form the page reloads but nothing happens, no errors or signs of success. Any ideas what could be wrong? <?php //this script registers a new user. require_once 'dbConnect.php'; require_once 'functions.php'; $errors[] = array(); if (isset($_POST['register'])) { //if the form has been submitted $userName = $_POST['user']; $pass = $_POST['pass']; $rePass = $_POST['rePass']; $query = 'SELECT * FROM users WHERE user_id="$userName"'; $insertUser = 'INSERT INTO users VALUES ($userName, $pass)'; if (empty($userName) || empty($pass) || empty($rePass)) { //are any of the fields empty $errors[] = "All fields must be filled out.";} elseif ($pass != $rePass) { //all fileds are filled out, are the values valid? $errors[] = "The passwords do not match.";} elseif (strlen($pass) < 4 || strlen($pass) > 12) { //check if username is too long or too short $errors[] = "You password must be between 4 and 12 characters long.";} elseif (strlen($userName) < 4 || strlen($userName) > 12) { //check if username is too long or too short $errors[] = "You username must be between 4 and 12 characters long.";} elseif (preg_replace('/[\w ]/', '', $userName)) { //check for invalid characters in the username $errors[] = "Your username may only contain letters, numbers, or underscores";} else { //check if username already exists $result = mysql_query($query) or die('Connection Error.'); if (mysql_num_rows($result) > 0) { $errors[] = "That username is already taken.";} else { //add user to the database mysql_query($insertUser) or die('Connection Error.'); echo 'You have been added! sign-in and enjoy.'; } } } else { //show form and errors if applicable showRegisterForm($errors); } ?>
  18. Thanks for the help. Can you show me what you have changed? I don't see it.
  19. I am getting an error that looks like this: Parse error: syntax error, unexpected T_IF in /home/thinksna/public_html/register.php on line 19 Is there a way to make this work? Here is the code: <?php //this script registers a new user. require_once 'dBconnect.php'; require_once 'functions.php'; if (isset($_POST['register'])) { //if the form has been submitted $userName = $_POST['user']; $pass = $_POST['pass']; $rePass = $_POST['rePass']; $query = 'SELECT * FROM users WHERE user_id="$userName"'; $insertUser = 'INSERT INTO users VALUES ($userName, $pass)'; $errors[] = '' if (empty($userName) || empty($pass) || empty($rePass)) { //are any of the fields empty $errors += 'All fields must be filled out.'; } elseif ($pass != $rePass) { //all fileds are filled out, are the values valid? $errors += 'The passwords do not match.'; } elseif (strlen($pass) < 4 || > 12) { //check if username is too long or too short $errors += 'You password must be between 4 and 12 characters long.'; } elseif (strlen($userName) < 4 || > 12) { //check if username is too long or too short $errors += 'You username must be between 4 and 12 characters long.'; } elseif (preg_replace('/[\w ]/', '', $userName) { //check for invalid characters in the username $errors += 'Your username may only contain letters, numbers, or underscores'; } else { //check if username already exists $result = mysql_query($query) or die('Connection Error.'); if (mysql_num_rows($result) > 0) { $errors += 'That username is already taken.'; } else { //add user to the database mysql_query($insertUser) or die('Connection Error.'); echo 'You have been added! sign-in and enjoy.'; } } else { //show form and errors if applicable showRegisterForm($errors); }
  20. I got it, I shouldn't have had the dollar sign before artists in the POST array.
  21. I can't see what is wrong with my foreach statement? Any ideas? <?php if($_POST) { echo "<table border=\"1\" align=\"center\">"; foreach ($_POST['$artists'] as $artist) { switch ($artist) { case "dali": //show Dali picture echo "<tr><td><b>Salvador dali</b></td><td><img src=\"http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Salvador_Dal%C3%AD_1939.jpg/180px-Salvador_Dal%C3%AD_1939.jpg\"></td></tr>"; break; case "vanGogh": //show Van Gogh picture echo "<tr><td><b>Vincent Van Gogh</b></td><td><img src=\"http://upload.wikimedia.org/wikipedia/commons/thumb/3/38/VanGogh_1887_Selbstbildnis.jpg/170px-VanGogh_1887_Selbstbildnis.jpg\"></td></tr>"; break; case "escher": //show Escher picture echo "<tr><td><b>M. C. Escher</b></td><td><img src=\"http://upload.wikimedia.org/wikipedia/en/thumb/4/43/EscherSelf1929.jpg/220px-EscherSelf1929.jpg\"></td></tr>"; break; case "picasso": //show Picasso picture echo "<tr><td><b>Pablo Picasso</b></td><td><img src=\"http://upload.wikimedia.org/wikipedia/commons/thumb/9/98/Pablo_picasso_1.jpg/180px-Pablo_picasso_1.jpg\"></td></tr>"; break; } } echo "</table>"; } else { ?> <form action="<?php echo $_SERVER[php_SELF]; ?>" method="POST"> <input type="text" name="firstName" size="25"><br /> <select name="artists[]" size="4" multiple id="artists[]"> <option value="dali">Salvador Dali</option> <option value="vanGogh">Vincent Van Gogh</option> <option value="escher">M. C. Escher</option> <option value="picasso">Pablo Picasso</option> </select><br /> <INPUT TYPE="image" SRC="./images/kaufen.jpg" BORDER=0 ALT="Submit"> <input type="reset" value="Reset"> <?php } ?>
×
×
  • 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.