Danny620 Posted June 29, 2009 Share Posted June 29, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/164144-very-simple-but-need-help/ Share on other sites More sharing options...
Maq Posted June 29, 2009 Share Posted June 29, 2009 Sorry, I don't understand the issue here. Where is the div? You can put HTML in PHP variables and echo it out later if you wish. Quote Link to comment https://forums.phpfreaks.com/topic/164144-very-simple-but-need-help/#findComment-865870 Share on other sites More sharing options...
Danny620 Posted June 29, 2009 Author Share Posted June 29, 2009 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>';" Quote Link to comment https://forums.phpfreaks.com/topic/164144-very-simple-but-need-help/#findComment-865877 Share on other sites More sharing options...
Maq Posted June 29, 2009 Share Posted June 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/164144-very-simple-but-need-help/#findComment-865882 Share on other sites More sharing options...
aggrav8d Posted June 29, 2009 Share Posted June 29, 2009 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/164144-very-simple-but-need-help/#findComment-865887 Share on other sites More sharing options...
Danny620 Posted June 29, 2009 Author Share Posted June 29, 2009 nope still not getting anywhere but thanks for the help so far il try and explain it a bit clearer all i wish to do is print that error message on the page where i want the error message to apear Quote Link to comment https://forums.phpfreaks.com/topic/164144-very-simple-but-need-help/#findComment-865916 Share on other sites More sharing options...
JJ2K Posted June 29, 2009 Share Posted June 29, 2009 Store the error in a variable say $error then inside the div just echo it out like: <div id="myerrordiv"><?php echo $error; ?></div> Quote Link to comment https://forums.phpfreaks.com/topic/164144-very-simple-but-need-help/#findComment-865963 Share on other sites More sharing options...
Maq Posted June 29, 2009 Share Posted June 29, 2009 Store the error in a variable say $error then inside the div just echo it out like: <?php echo $error; ?> Please read the previous posts before replying. Quote Link to comment https://forums.phpfreaks.com/topic/164144-very-simple-but-need-help/#findComment-865964 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.