Jump to content

Recommended Posts

:) Hi everybody. I am a very very new learner of php and MySQL, Would you please give me some advice on how to do the follows:

  Basically, I developed a registration and log in system, but I would like to have the functionalities that after a user logged in, he/she can send articles or update their registration information if they want to change any personal details.

  Hence, how can I acheive these?

  Any help would be grately and appreciated.

Hi  :) Thank you very much. Here are my codes for registration form and log in. I dont know what to do next at all :'(

 

This is my registration form's code

<?php //registration.php

ob_start();

// Check if the form has been submitted.

:)if (isset($_POST['submitted'])) {

 

require_once ('snypdb.php'); // Connect to the db.

 

$errors = array(); // Initialize error array.

 

// Check for a user name.

if (empty($_POST['user_name'])) {

$errors[] = 'You forgot to enter your user name.';

} else {

$un =$_POST['user_name'];

}

 

// Check for a password and match against the confirmed password.

if (!empty($_POST['password1'])) {

if ($_POST['password1'] != $_POST['password2']) {

$errors[] = 'Your password did not match the confirmed password.';

} else {

$p = $_POST['password1'];

}

} else {

$errors[] = 'You forgot to enter your password.';

}

 

// Check for a first name.

if (empty($_POST['first_name'])) {

$errors[] = 'You forgot to enter your first name.';

} else {

$fn =$_POST['first_name'];

}

 

// Check for a last name.

if (empty($_POST['last_name'])) {

$errors[] = 'You forgot to enter your last name.';

} else {

$ln = $_POST['last_name'];

}

 

// Check for an address.

if (empty($_POST['address'])) {

$errors[] = 'You forgot to enter your address.';

} else {

$ad = $_POST['address'];

}

 

// Check for an postcode

 

if (!empty($_POST['postcode'])) {

if (strncmp(strtolower($_POST['postcode']), "sr5",3)!=0){

$errors[] = 'Sorry, only young people from southwick can register with us';

}

else {

$psd = $_POST['postcode'];

}

    } else {

$errors[] = 'You forgot to enter your postcode.';

}

 

 

 

 

 

// Check for an contact telphone number

if (empty($_POST['tel'])) {

$errors[] = 'You forgot to enter your contact telephone number.';

} else {

$tel = $_POST['tel'];

}

 

 

// Check for an email address.

if (!empty($_POST['email'])) {

if (!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email'])))){

$errors[] = 'Sorry, the email is not valid';

}

else {

$e = $_POST['email'];

}

    } else {

$errors[] = 'You forgot to enter your email.';

}

 

if (empty($_POST['agreetolist'])) {

$errors[] = 'Please choose whether allow other member know you registered with us or not.';

} else {

$agr = $_POST['agreetolist'];

}

 

if (empty($errors)) { // If everything's OK.

 

// Register the user in the database.

 

// Check for previous registration.

$query = "SELECT user_id FROM users WHERE user_name='$un'";

$result = mysql_query($query);

if (mysql_num_rows($result) == 0) {

 

// Make the query.

$query = "INSERT INTO users (user_name, password,first_name, last_name, address, postcode,tel, email, agreetolist, registration_date) VALUES ('$un', md5('$p'),'$fn', '$ln', '$ad', '$psd', '$tel', '$e', '$agr', NOW() )";

$result = @mysql_query ($query); // Run the query.

if ($result) { // If it ran OK.

 

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

 

// Check for a trailing slash.

if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {

$url = substr ($url, 0, -1); // Chop off the slash.

}

 

// Add the page.

$url .= '/userpanel.php';

header("Location: $url");

exit();

 

} else { // If it did not run OK.

$errors[] = 'You could not be registered due to a system error. We apologize for any inconvenience.'; // Public message.

$errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message.

}

 

} else { // Email address is already taken.

$errors[] = 'The user name has already been registered.';

}

 

} // End of if (empty($errors)) IF.

 

mysql_close(); // Close the database connection.

 

} else { // Form has not been submitted.

 

$errors = NULL;

 

} // End of the main Submit conditional.

 

if (!empty($errors)) { // Print any error messages.

echo '<h1 id="mainhead">Error!</h1>

<p class="error">The following error(s) occurred:<br />';

foreach ($errors as $msg) { // Print each error.

echo " - $msg<br />\n";

}

echo '</p><p>Please try again.</p>';

}

// Create the form.

?>

<h2>Register</h2>

<form action="registration.php" method="post">

    <p>User Name: <input type="text" name="user_name" size="20" maxlength="30" value="<?php if (isset($_POST['user_name'])) echo $_POST['user_name']; ?>" /></p>

    <p>Password: <input type="password" name="password1" size="10" maxlength="20" /></p>

<p>Confirm Password: <input type="password" name="password2" size="10" maxlength="20" /></p>

<p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>

<p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>

<p>Address: <input type="text" name="address" size="40" maxlength="60" value="<?php if (isset($_POST['address'])) echo $_POST['address']; ?>" /></p>

<p>Postcode: <input type="text" name="postcode" size="10" maxlength="12" value="<?php if (isset($_POST['postcode'])) echo $_POST['postcode']; ?>" /></p>

<p>Telephone Number: <input type="text" name="tel" size="10" maxlength="15" value="<?php if (isset($_POST['tel'])) echo $_POST['tel']; ?>" /></p>

<p>Email Address: <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"  /> </p>

 

<p>Would you like to be on the registered members list so that other members can see that you have registered with us? </p>

<p> <lable>Yes: <input type="radio" name="agreetolist" value="y" <?php if($agr=='y') echo ('checked'); ?>> </lable>

<lable>No: <input type="radio" name="agreetolist" value="n" <?php if($agr=='n') echo ('checked'); ?>></lable></p>

 

<p><input type="submit" name="submit" value="Register" /></p>

<input type="hidden" name="submitted" value="TRUE" />

</form>

 

 

 

 

:) This is my log in page

<?php //login4.php

 

ob_start();

 

// Check if the form has been submitted.

if (isset($_POST['submitted'])) {

 

  require_once ('snypdb.php'); // Connect to the db.

     

  $errors = array(); // Initialize error array.

 

  // Check for an  user name.

  if (empty($_POST['user_name'])) {

      $errors[] = 'You forgot to enter your user name.';

  } else {

      $un = $_POST['user_name'];

  }

 

  // Check for a password.

  if (empty($_POST['password'])) {

      $errors[] = 'You forgot to enter your password.';

  } else {

      $p = md5($_POST['password']);

  }

 

  if (empty($errors)) { // If everything's OK.

 

      /* Retrieve the user_id and first_name for

      that user name/password combination. */

      $query = "SELECT user_id, first_name FROM users WHERE user_name='$un' AND password='$p'";     

      $result = mysql_query($query) or die(mysql_error());

      // Run the query.

      $num = mysql_num_rows($result); // Return a record, if applicable.

 

      if ($num == 1) { // A record was pulled from the database.

 

        $row = mysql_fetch_array($result, MYSQL_NUM);

 

        // Set the session data & redirect.

        session_name('YourVisitID');

        session_start();

        $_SESSION['user_id'] = $row[0];

        $_SESSION['first_name'] = $row[1];

        $_SESSION['agent']=md5($_SERVER['HTTP_USER_AGENT']);

 

        // Redirect the user to the loggedin.php page.

        // Start defining the URL.

        $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

        // Check for a trailing slash.

        if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {

            $url = substr ($url, 0, -1); // Chop off the slash.

        }

        // Add the page.

        $url .= '/loggedin.php';

       

        header("Location: $url");

        exit(); // Quit the script.

           

      } else { // No record matched the query.

        $errors[] = 'The user name and password entered do not match those on file.'; // Public message.

        $errors[] = mysql_error() . '

 

Query: ' . $query; // Debugging message.

      }

     

  } // End of if (empty($errors)) IF.

     

  mysql_close(); // Close the database connection.

 

} else { // Form has not been submitted.

 

  $errors = NULL;

 

} // End of the main Submit conditional.

 

 

 

if (!empty($errors)) { // Print any error messages.

  echo '<h1 id="mainhead">Error!</h1>

  <p class="error">The following error(s) occurred:

';

  foreach ($errors as $msg) { // Print each error.

      echo " - $msg

\n";

  }

  echo '</p><p>Please try again.</p>';

}

 

// Create the form.

?>

<h2>Login</h2>

<form action="login.php" method="post">

  <p>User Name: <input type="text" name="user_name" size="20" maxlength="40" /> </p>

  <p>Password: <input type="password" name="password" size="20" maxlength="20" /></p>

  <p><input type="submit" name="submit" value="Login" /></p>

  <input type="hidden" name="submitted" value="TRUE" />

</form>

 

 

this should work

 

SELECT $query = "SELECT * FROM users WHERE user_id='{$_SESSION['user_id']}'";

 

of course your need the fetch ect

see your

 

    /* Retrieve the user_id and first_name for

      that user name/password combination. */

 

section

Now, i assume thats a form,

 

when you submit that data, (submit to the same page) update that users recoard

 

<?php
if(isset($_POST['submit']))
{
//update record
$SQL = "update users SET realname = '{$_POST['user_name']}' WHERE user_id='{$_SESSION['user_id']}' ";
}
// display form 
?>

 

NOTE: this isn't perfect but a start

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.