Jump to content

very simple but need help


Danny620

Recommended Posts

right what i wish to do is this

 

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

$p = mysqli_real_escape_string ($dbc, $_POST['pass']);

} else {

$p = FALSE;

echo '<p class="error">You forgot to enter your password!</p>';

 

 

print this message echo "'<p class="error">You forgot to enter your password!</p>';" in a div where i have put the div e.g my div is in a table i wish to print this message in it

 

Link to comment
https://forums.phpfreaks.com/topic/164144-very-simple-but-need-help/
Share on other sites

this is the code

 

<?php # Script 16.8 - login.php
// This is the login page for the site.

require_once ('config.inc.php'); 
$page_title = 'Login';
include ('includes/header.php');

if (isset($_POST['submitted'])) {
require_once (MYSQL);

// Validate the email address:
if (!empty($_POST['email'])) {
	$e = mysqli_real_escape_string ($dbc, $_POST['email']);
} else {
	$e = FALSE;
	echo '<p class="error">You forgot to enter your email address!</p>';
}

// Validate the password:
if (!empty($_POST['pass'])) {
	$p = mysqli_real_escape_string ($dbc, $_POST['pass']);
} else {
	$p = FALSE;
	echo '<p class="error">You forgot to enter your password!</p>';
}

if ($e && $p) { // If everything's OK.

	// Query the database:
	$q = "SELECT user_id, first_name, user_level FROM users WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL";		
	$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));

	if (@mysqli_num_rows($r) == 1) { // A match was made.

		// Register the values & redirect:
		$_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC); 
		mysqli_free_result($r);
		mysqli_close($dbc);

		$url = BASE_URL . 'index.php'; // Define the URL:
		ob_end_clean(); // Delete the buffer.
		header("Location: $url");
		exit(); // Quit the script.

	} else { // No match was made.
		echo '<p class="error">Either the email address and password entered do not match those on file or you have not yet activated your account.</p>';
	}

} else { // If everything wasn't OK.
	echo '<p class="error">Please try again.</p>';
}

mysqli_close($dbc);

} // End of SUBMIT conditional.
?>
<link href="includes/css.css" rel="stylesheet" type="text/css">

<div class="login" id="login">
  <form name="form1" method="post" action="">
    <table width="342" height="89" border="0">
      <tr>
        <td width="90" height="26"> </td>
        <td width="161">          
        <label><div class="style2" id="user"></div>
        </label></td>
        <td width="77"> </td>
      </tr>
      <tr>
        <td height="23"> </td>
        <td><label></label></td>
        <td> </td>
      </tr>
      <tr>
        <td><div align="right" class="style2">Email:</div></td>
        <td><label>
          <input name="email" type="text" class="input_form" id="email" size="35" maxlength="40" />
        </label></td>
        <td> </td>
      </tr>
      <tr>
        <td><div align="right" class="style2">Password:</div></td>
        <td><input name="pass" type="password" class="input_form" id="pass" size="35" maxlength="20" /></td>
        <td> </td>
      </tr>
      <tr>
        <td> </td>
        <td><input name="submit" type="submit" class="input_form" id="submit" value="Login" /></td>
        <td><input type="hidden" name="submitted" value="TRUE" /></td>
      </tr>
    </table>
  </form>
</div>
<?php
include ('./includes/footer.html');
?>

 

that's the code right and this is what i wish to do "<label><div class="style2" id="user"></div>" this part is where i wish to output the error message in which is this bit "echo '<p class="error">You forgot to enter your email address!</p>';"

Change these sections:

 

 

1.

   // Validate the email address:
   if (!empty($_POST['email'])) {
      $e = mysqli_real_escape_string ($dbc, $_POST['email']);
   } else {
      $e = FALSE;
      $password = '
You forgot to enter your email address!';
   }

 

2.

        

instead of echo try

 

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

 

then at the end use

 

        <td width="161">
<?
  if(count($errors)) {
    echo "<div class='error_messages'>\n";
    foreach($errors as $v) echo "<p class='error'>$v</p>\n";
    echo "</div>\n";
  }
?>

Archived

This topic is now archived and is closed to further replies.

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