Danny620 Posted December 12, 2008 Author Share Posted December 12, 2008 right i have made a sign script but the only thing that does work is the email it don't insert into the database for some reson here is my script <?php // Connects to your Database mysql_connect("localhost", "**", "***") or die(mysql_error()); mysql_select_db("web160-admin-21") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2']) { die('You did not complete all of the required fields'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the username '.$_POST['username'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { die('Your passwords did not match. '); } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['username'] = addslashes($_POST['username']); } // now we insert it into the database $insert = "INSERT INTO users (username, password, realname, email) VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['realname']."', '".$_POST['email']."')"; $add_member = mysql_query($insert); ?> <h1>Registered</h1> <p>Thank you, you have registered - you may now login</a>.</p> <?php } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="60"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="10"> </td></tr> <tr><td>Confirm Password:</td><td> <input type="password" name="pass2" maxlength="10"> </td></tr> <tr><td>Real Name:</td><td> <input type="text" name="realname" maxlength="40"> </td></tr> <tr><td>Email:</td><td> <input type="text" name="Email" maxlength="40"> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-713872 Share on other sites More sharing options...
Brian W Posted December 12, 2008 Share Posted December 12, 2008 Thank you for using the code tags. PHP is case sensitive in almost every circumstance. Your field name is "Email" but you are trying to use $_POST['email'] which does not match. Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-713881 Share on other sites More sharing options...
Danny620 Posted December 12, 2008 Author Share Posted December 12, 2008 thanks for that but how would i go about making a foum saying about me to submint to the database Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-714276 Share on other sites More sharing options...
Brian W Posted December 12, 2008 Share Posted December 12, 2008 umm, what? foum? (forum? form?) i'm guessing i could translate to "a form that asks about me that I submit to the database". You would create an HTML form with the fields you need, and then use a the SQL syntax for INSERT to add a new about me section. To update, you'd use a similar technique except that you'd use the SQL syntax for UPDATE. The code u posted oh so nicely withing code tags below looks like you got a template from some one. Do you understand what each step does? If not, you need to get looking at more tutorials or hope you can get another template from online for what you want to do. Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-714293 Share on other sites More sharing options...
waynew Posted December 13, 2008 Share Posted December 13, 2008 Show us your database structure. Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-714307 Share on other sites More sharing options...
Danny620 Posted December 13, 2008 Author Share Posted December 13, 2008 Right i have mananaged to do that about me i was well heappy i fugured it out for my self i looked at the other code and tryed and do it myself also yes this is a temple but i have added email realname and about me to it also changed the form can you have a scan thought this code to make sure its safe and good to user nothing can change about it thanks very much so far  <?php // Connects to your Database mysql_connect("localhost", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['realname'] | !$_POST['email']) { die('You did not complete all of the required fields'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the username '.$_POST['username'].' is already in use.'); } // checks if the email is in use if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $usercheck = $_POST['email']; $check = mysql_query("SELECT username FROM users WHERE email = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the email '.$_POST['email'].' is already in use. <a href="signup.php"> Click here to go back</a>'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { die('Your passwords did not match. '); } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['username'] = addslashes($_POST['username']); } // now we insert it into the database $insert = "INSERT INTO users (username, password, realname, email, aboutyou) VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['realname']."', '".$_POST['email']."', '".$_POST['aboutyou']."')"; $add_member = mysql_query($insert); ?> <h1>Registered</h1> <p>Thank you, you have registered - you may now login</a>.</p> <?php } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr><td><div align="right">*Username:</div></td><td> <input type="text" name="username" maxlength="60"> </td></tr> <tr><td><div align="right">*Password:</div></td><td> <input type="password" name="pass" maxlength="10"> </td></tr> <tr><td>*Confirm Password:</td><td> <input type="password" name="pass2" maxlength="10"> </td></tr> <tr><td><div align="right">*Real Name:</div></td><td> <input type="text" name="realname" maxlength="40"> </td></tr> <tr><td><div align="right">*Email:</div></td><td> <input type="text" name="email" maxlength="40"> <tr><td><div align="right">About You:</div></td><td>  <textarea name="aboutyou" id="aboutyou"></textarea> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Register">  <label>  <input type="reset" name="reset" id="reset" value="Reset" />  </label></th></tr> </table> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-714320 Share on other sites More sharing options...
waynew Posted December 13, 2008 Share Posted December 13, 2008 // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } Â See that piece of code there? It's defunct. Or will be once PHP 6 comes out. Â Use this instead: Â // checks if the username is in use if (function_exists('mysql_real_escape_string')) { $_POST['username'] = mysql_real_escape_string($_POST['username']); } else{ $_POST['username'] = mysql_escape_string($_POST['username']); } Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-714324 Share on other sites More sharing options...
Danny620 Posted December 13, 2008 Author Share Posted December 13, 2008 ok thanks whens php 6 set to come out Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-714343 Share on other sites More sharing options...
waynew Posted December 13, 2008 Share Posted December 13, 2008 ok thanks whens php 6 set to come out  Heh, your guess is as good as mine at this stage. But at least you wont have to worry about it when it does. Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-714344 Share on other sites More sharing options...
premiso Posted December 13, 2008 Share Posted December 13, 2008 ok thanks whens php 6 set to come out  Well PHP 5 is just starting to become standard and most production servers, I would say when PHP5.4.x is release they will have a non-beta PHP 6, but you will never know as it is up to the developers to decide when it is ready. Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-714347 Share on other sites More sharing options...
waynew Posted December 13, 2008 Share Posted December 13, 2008 Whoa. Sorry, was looking through your code and realised that the same kind of thing is going on throughout it. Â Use: Â <?php // Connects to your Database mysql_connect("localhost", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['realname'] | !$_POST['email']) { die('You did not complete all of the required fields'); } // checks if the username is in use $_POST['username'] = mysql_real_escape_string($_POST['username']); $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the username '.$_POST['username'].' is already in use.'); } // checks if the email is in use $_POST['email'] = mysql_real_escape_string($_POST['email']); $usercheck = $_POST['email']; $check = mysql_query("SELECT username FROM users WHERE email = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the email '.$_POST['email'].' is already in use. <a href="signup.php"> Click here to go back</a>'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { die('Your passwords did not match. '); } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); $_POST['pass'] = mysql_real_escape_string($_POST['pass']); $_POST['username'] = mysql_real_escape_string($_POST['username']); $_POST['aboutyou'] = mysql_real_escape_string($_POST['aboutyou']); $_POST['realname'] = mysql_real_escape_string($_POST['realname']); // now we insert it into the database $insert = "INSERT INTO users (username, password, realname, email, aboutyou) VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['realname']."', '".$_POST['email']."', '".$_POST['aboutyou']."')"; $add_member = mysql_query($insert); ?> <h1>Registered</h1> <p>Thank you, you have registered - you may now login</a>.</p> <?php } else { ?> <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> <table border="0"> <tr><td><div align="right">*Username:</div></td><td> <input type="text" name="username" maxlength="60"> </td></tr> <tr><td><div align="right">*Password:</div></td><td> <input type="password" name="pass" maxlength="10"> </td></tr> <tr><td>*Confirm Password:</td><td> <input type="password" name="pass2" maxlength="10"> </td></tr> <tr><td><div align="right">*Real Name:</div></td><td> <input type="text" name="realname" maxlength="40"> </td></tr> <tr><td><div align="right">*Email:</div></td><td> <input type="text" name="email" maxlength="40"> <tr><td><div align="right">About You:</div></td><td> Â <textarea name="aboutyou" id="aboutyou"></textarea> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Register"> Â <label> Â <input type="reset" name="reset" id="reset" value="Reset" /> Â </label></th></tr> </table> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-714349 Share on other sites More sharing options...
trq Posted December 13, 2008 Share Posted December 13, 2008 This line here.... Â if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['realname'] | !$_POST['email']) { Â needs to be.... Â if (!$_POST['username'] || !$_POST['pass'] || !$_POST['pass2'] || !$_POST['realname'] || !$_POST['email']) { Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-714362 Share on other sites More sharing options...
Danny620 Posted December 13, 2008 Author Share Posted December 13, 2008 This line here.... Â if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['realname'] | !$_POST['email']) { Â needs to be.... Â if (!$_POST['username'] || !$_POST['pass'] || !$_POST['pass2'] || !$_POST['realname'] || !$_POST['email']) { Â why does that need to be changed Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-714562 Share on other sites More sharing options...
trq Posted December 14, 2008 Share Posted December 14, 2008 Because you need a logical or || not a bitwise or | Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-714956 Share on other sites More sharing options...
Danny620 Posted December 15, 2008 Author Share Posted December 15, 2008 ok my mate helped me with the sciptt but we cant seem to find out wrong with it what ita meat to do is login a user and get his id and store it in a session any one can help <?php    session_start();    /* This page checks user information and     * logs them in if it's correct.     *     * First, we need to check if the form has     * been submitted. If it has, we need to check     * form values, to make sure they filled them in     * right.     *     * Connect to MySQL and check if the form has     * been submitted:     */    // Connect to MySQL. Change the values to your information:    $mysql = mysqli_connect('localhost', 'username', 'password', 'database') or die('An error has occured.');    // Check if the form has been submitted:    if(isset($_POST['username']) && isset($_POST['passsword'])) {        // Now we check that both forms were filled in:        if(!empty($_POST['username']) && isset($_POST['password'])) {           // We're all good, so we can assign the post values to variables:           extract($_POST);           /* Now we can refer to $_POST['username'] as            * $username. It's much faster and easier. We            * user extract() because it's easier than            * doing it manually. Caution: May make you lazy            *            *            * Now we can query our database for the username            * and password combonation. If it returns no rows            * with the inputted password AND username, either            * the password does not match the username, or the            * user inputted information that does not exist.            *            * We can assign the user id to a session, and use            * that to retrieve all the information about the            * user from the table.            */           if($query = $mysql->prepare('SELECT userid FROM users WHERE username = ? AND password = ?')) {               $query->bind_param('ss', $username, $password);               $query->execute();               $query->store_result();               /* Now we count the number of rows returned. As               * I stated before, if the number of rows is less               * than one, the user has failed to input valid               * information.               */               if($query->num_rows < 1) {                  // Login unsuccessful. Echo error:                  echo('Incorrect information provided. Login failed.');               } else {                  /* The login was successful! We need to assign the user                   * id to a session for later use (retrieving information,                   * etc). First however, we need to retrieve the user id:                   */                  $query->bind_result($userid);                  if($query->fetch()) {                      // Assign the user id to a session:                      $_SESSION['userid'] = $userid;                      // Redirect user to the logged in page:                      header('Location: loggedin.php');                  }               }           } else {               // The query failed to be prepared:               die('An error has occured.');           }        }    } ?> <!-- Login Form --> <form action="login.php" method="post">    <fieldset>        <legend>Login To Your Account</legend>        <label for="username">Username:</label> <input type="text" id="username" name="username" /><br />        <label for="password">Password:</label> <input type="password" id="password" name="password" /><br />        <input type="submit" name="submit" value="Login" />    </fieldset> </form> <!-- End Login Form --> Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-715831 Share on other sites More sharing options...
Brian W Posted December 15, 2008 Share Posted December 15, 2008 $mysql = mysqli_connect('localhost', 'username', 'password', 'database') or die('An error has occured.'); Is your username = username? Is your password = password? Is your database called database? Â Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-715863 Share on other sites More sharing options...
Danny620 Posted December 15, 2008 Author Share Posted December 15, 2008 wtf man well not its not but i am not going to but it my real detiels in now am i Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-715937 Share on other sites More sharing options...
Brian W Posted December 15, 2008 Share Posted December 15, 2008 not trying to infiltrate, just making sure your knew you had to set those. use **** or something and that will let us know you are just censoring. "usename" makes it look like you neglected to fix your template to what you need it to be. Your "mate" who wrote that isn't very helpful. It is like handing a 2 year old legos instead of megablocks (don't mean that offensively). Its not helpful if you don't understand what it does exactly and you should start with a less complex version of that so that you know what each step is doing without having those comments. But, basically, that is exactly what that script does, just uses some syntax that isn't exactly novice. Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-715952 Share on other sites More sharing options...
RussellReal Posted December 20, 2008 Share Posted December 20, 2008 OOPS, nevermind.. didn't notice it was 3 pages alrdy.. lol I wrote like an essay for you.. but I took it away Quote Link to comment https://forums.phpfreaks.com/topic/136512-build-a-profile-page/page/2/#findComment-720244 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.