PHP - Can't Get Session Message To Display
Hi,
I'm having a problem with contact form not display message log. It does successfully send, but fails to get the session variables. Where did I go wrong? This is my contact form code <?php include('includes/ui.php'); head('Contact Us','contactpage.css'); ?> <script src="js/SpryValidationTextField.js" type="text/javascript"></script> <link href="js/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> <script src="js/SpryValidationTextarea.js" type="text/javascript"></script> <link href="js/SpryValidationTextarea.css" rel="stylesheet" type="text/css" /> <div class="section"> <h3>Contact Us</h3> <div class="scontent"> <?php /* ------------------------------------------------- Displays success/error message --------------------------------------------------*/ if ($_SESSION['message']!='') { ?> <div id="log"><?php echo $_SESSION['message']; ?></div> <?php unset($_SESSION['message']) ?> <?php } ?> <?php /* ------------------------------------------------- Contact Form --------------------------------------------------*/ ?> <p><em>If you have any questions, feel free to fill the form below:</em></p> <form action="sendmail.php" method="post"> <label>Name:</label> <span id="sprytextfield1"> <input type="text" class="istext" name="name"/> <span class="textfieldRequiredMsg">This field is required.</span></span> <label>Email:</label> <span id="sprytextfield2"> <input type="text" class="istext" name="email"/> <span class="textfieldRequiredMsg">This field is required.</span></span> <label>Message</label> <span id="sprytextarea1"> <textarea name="message"></textarea> <span class="textareaRequiredMsg">This field is required.</span></span><br/> </span> <label>Enter the code:</label> <img src="includes/captcha.php" /><span id="sprytextfield3"> <input class="input" type="text" name="norobot" /> <span class="textfieldRequiredMsg">This field is required.</span></span><br/> <input type="submit" class="btn" value="Send"/><span class="tab2em"></span><input type="reset" class="btn" value="Reset"/> </form> <div id="bible"> </div> <span class="clear"></span> <br class="clear"/> </div> </div> </div> <script type="text/javascript"> <!-- var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1"); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2"); var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1"); var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3"); //--> </script> <?php footer(); ?> This is my sendmail.php <?php session_start(); if (md5($_POST['norobot']) == $_SESSION['randomnr2']) { // here you place code to be executed if the captcha test passes $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $name = filter_var($name, FILTER_SANITIZE_STRING); $email = filter_var($email, FILTER_SANITIZE_EMAIL); $message = filter_var($message, FILTER_SANITIZE_STRING); require_once('includes/class.phpmailer.php'); $mail = new PHPMailer(); $body = "Someone with the ".$name." and an email address of ".$email." send you the ff message: ".$message; $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = "mail.example.com"; // SMTP server $mail->SMTPAuth = true; // enable SMTP authentication $mail->Host = "mail.example.com"; // sets the SMTP server $mail->Port = 26; // set the SMTP port for the GMAIL server $mail->Username = "example@example.com"; // SMTP account username $mail->Password = "thepassword"; // SMTP account password $mail->SetFrom('example@example.com', 'Me'); $mail->Subject = "Message sent from site contact form"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $address = "tosomeone@yahoo.com"; $mail->AddAddress($address, "Richard"); if(!$mail->Send()) { $_SESSION['message'] = "Failed sending, please try again later"; } else { $_SESSION['message'] = "Message sent"; } } else { // here you place code to be executed if the captcha test fails $_SESSION['message'] = "Invalid code"; } header('Location: http://example.com'); ?> Thanks in advance Similar TutorialsI was wondering if there is away to set a logout message when you are using sessions this is my code <?php session_start(); if($_SESSION[auth] = "yes") { session_unset(); session_destroy(); header( "Location: index.php" ); exit(); } else { if ($_SESSION[auth] != "yes") { header( "Location: index.php" ); $_SESSION['error'] = "please login!"; exit(); } } ?> I am so glad someone told me about putting in the error_reporting ALL because I was not sure why my id for members was not picking up on the next pages. Can someone let me know how I can fix this I thought it automatically picks it up and sets it to private pages for each member. Notice: Undefined index: id in /home/ebermy5/public_html/login.php on line 25 <?php session_id(); session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Welcome</title> </head> <body> <?php /* Program: New_member.php * Desc: Displays the new member welcome page. Greets * member by name and gives a choice to enter * restricted section or go back to main page. */ error_reporting(E_ALL); ini_set("display_errors", 1); $firstname = ''; include('Connections/connect_to_mysql.php'); $result = mysql_query("SELECT firstname FROM `Members` WHERE id='{$_SESSION['id']}'"); $row = mysql_fetch_array($result); if ($firstname == ''){ //condition, is name equal to lower case firstname notice we use == and not = echo "Welcome, $firstname"; } else { //so incase the condition is not as expected echo "Sorry you are not $firstname"; } ?> <p>Your new Member accounts lets you enter the members only section of our web site. You'll find special discounts, a profile of matches, live advise from experts, and much more.</p> <p>Your new Member ID and password were emailed to you. Store them carefully for future use.</p> <div style="text-align: center"> <p style="margin-top: .5in; font-weight: bold"> Glad you could join us!</p> <form action="profile.php" method="post"> <input type="submit" value="Enter the Members Only Section"> </form> <form action="index.php" method="post"> <input type="submit" value="Go to eBermylove Main Page"> </form> </div> </body> </html> I am getting an error message. But the program works Code: [Select] Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\Exam_Online\try.php:3) in C:\xampp\htdocs\Exam_Online\Staff_login_process.php on line 4 Wrong Username or Password my code is <Html> <?php //session_start(); include 'Staff_login_process.php'; MYSQL_CONNECT(localhost,'root','') OR DIE("Unable to connect to database"); @mysql_select_db(Examination) or die( "Unable to select database"); ?> <body> <form action="try1.php" method="post"> <?PHP $query=("SELECT * FROM User u, User_X_Subject us, Subject s WHERE u.Use_Name = '{$_SESSION['username']}' AND u.Use_ID= us.Use_ID AND s.Sub_ID=us.Sub_ID"); $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<select name=myselect>"; while($row=mysql_fetch_array($result)){ echo "<OPTION VALUE=".$row['Sub_ID'].">".$row['Sub_Name']."</OPTION>"; } echo "</select>"; ?> <input type="submit" value="submit"/> </form> </body> </html>
Hi! The file login.php and the config file containing the db connection are in the model folder and the login_view is in view folder. I am trying to make a login form am display some error messages to the user, but I don't get the error messages. Can you help me figure it out? PS: the connection to the db works fine! Thx! LOGIN.PHP <?php //start the session session_start(); foreach (glob("model/*.php") as $filename) { include $filename; } //form defaults $error["alert"]= ""; $error["user"]= ""; $error["pass"]= ""; $input["user"]= ""; $input["pass"]= ""; if(isset($_POST["submit"])) { //process form if($_POST["username"] == "" || $_POST["password"] == ""){ //display errors if($_POST["username"] == ""){$error["user"] = "required";} if($_POST["password"] == ""){$error["pass"] = "required";} $error["alert"] = "Please fill in the required fields"; //get the values for the username and password $input["user"]= $_POST["username"]; $input["pass"]= $_POST["password"]; include("../views/login_view.php"); } }else{ include("../views/login_view.php"); } LOGIN_VIEW.PHP <?php session_start(); foreach (glob("model/*.php") as $filename) { include $filename; } ?> <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!--author:starttemplate--> <!--reference site : starttemplate.com--> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="keywords" content="unique login form,leamug login form,boostrap login form,responsive login form,free css html login form,download login form"> <meta name="author" content="leamug"> <title>Unique Login Form | Bootstrap Templates</title> <link href="/styles/style.css" rel="stylesheet" id="style" type="text/css"> <!-- Bootstrap core Library --> <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!-- Google font --> <link href="https://fonts.googleapis.com/css?family=Dancing+Script" rel="stylesheet"> <!-- Font Awesome--> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> </head> <body> <!-- Page Content --> <div class="container"> <div class="row"> <div class="col-md-offset-5 col-md-4 text-center"> <h1 class='text-white'>Login Form</h1> <form action ="" method="POST"> <div class="form-login"></br> </br> <?php if($error["alert"] != ''){ echo "<div class='alert'>".$error["alert"]."</div>"; } ?> <div> <input type="text" name ="username" id="userName" class="form-control input-sm chat-input" placeholder="Username" value= "<?php echo $input['user'] ?>" required/> <?php echo $error['user'] ?> </div> </br></br> <input type="text" name ="password" id="userPassword" class="form-control input-sm chat-input" placeholder="Password" value= "<?php echo $input['password'] ?>" required/> <div class="error"> <?php echo $error['pass'] ?> </br></br> <div class="wrapper"> <input type="submit" class="btn btn-primary" value="submit"> </div> </div> </div> </form> </div> </div> </body> </html> Edited October 28, 2020 by Alexa Hello all, I'm new to PHP and new to this forum (although I have benefitted from your help already -cheers!). However, this time I cannot find the answer I need/recognise/understand.. I have a form and want to conduct tests on each field returning an error message as a session variable if the test fails. The test will be different for some of the fields, and the error message is specific to each field. If there is an error in any one of the fields I want to be redirected to a failure page where all of the error messages are displayed, otherwise I am sent on to another page. I have already written and tested a function to sanitise the incoming form data, so that's not a problem - it's just how to loop through and test. I can guess that there are many ways to do this but I need to understand why one option is better than another, and follow the syntax used (it's all part of my steep learning curve) The approach I have thought to use is to create an array holding the field name, the test and the message, then loop through using foreach, applying the array values into the test and creating the error message....but it's not working for me. The other method is to declare a variable $Stop='No' and if the loop identifies an error, part of the output is to change this to 'yes' and through that redirect to the error page. I'd really welcome your advice and tuition....cheers.. my code so far is... Code: [Select] $Stop='No'; $StaffPassCheck=sanitisealphanum($_POST['PasswordCheck']); $Errors[0]['value']= sanitisealphanum($_POST['FirstName']); $Errors[0]['message']='Please re-enter your name'; $Errors[0]['test']=($StaffFname=""); $Errors[1]['value']= sanitisealphanum($_POST['Surname']); $Errors[1]['message']='Please re-enter your surname'; $Errors[1]['test']=($StaffSname=""); $Errors[2]['value']= sanitisealphanum($_POST['Post']); $Errors[2]['message']='You must select an option'; $Errors[2]['test']=($StaffPost="Select Value"); $Errors[3]['value']= sanitisealphanum($_POST['Username']); $Errors[3]['message']='You must select an option'; $Errors[3]['test']=($StaffUser=""); $Errors[4]['value']= sanitisealphanum($_POST['Password']); $Errors[4]['message']='Please re-enter your password'; $Errors[4]['test']=($StaffPass=""); $Errors[5]['value']= sanitisealphanum($_POST['PasswordCheck']); $Errors[5]['message']='Sorry, your passwords do not match'; $Errors[5]['test']=($StaffPass===$StaffPassCheck); foreach ($Errors as $key => $Value){ if ( $Errors['test']=true ){ $Stop='Yes'; return $_SESSION[$key]=$Value['message']; } } if ($Stop='Yes'){ header('Location.test.php'); die(); }else{ header('Location.indexp.php'); } I am trying to display "open" / "closed" depending on the time of day. I tried to write my own script but it doesn't seem to be working. Does anyone know of some boxed script I can use? Here is what I have... function open(){ $AMPM = date('A', time()); if ($AMPM == "PM"){ connect(); $day = date('l'); $sqlcurrent = "select * from hours where day = '$day' and closed ='1'"; $currently = mysql_query($sqlcurrent) or die(mysql_error()); $checkDay = mysql_num_rows($currently); if ($checkDay == "1"){ while($getID = mysql_fetch_assoc($currently)){ $convertopen = strtotime($getID['open']); $convertclose = strtotime($getID['close']); $displayTimeH = date('H', time()); $displayTimeM = date('i', time()); $displayTimeAMPM = date('A', time()); $opentime = explode(":", $getID['open']); $openhour=$opentime[0]; $openminute=$opentime[1]; $closetime = explode(":", $getID['close']); $closehour=$closetime[0]; $closeminute=$closetime[1]; //echo "$closehour$closeminute<br />"; //echo "$displayTimeH$displayTimeM<br />"; if (($openhour <= $displayTimeH && $openminute <= $displayTimeM) && ($closehour >= $displayTimeH && $closeminute >= $displayTimeM)){ echo "We're Open ... Come On In!"; }else{ echo "Hours of Service"; } } }else{ echo "Hours of Service"; free($currently); } }else{ echo "Hours of Service"; } } // close function I know it's brutal but it's all I could come up with... Here I use two php page with two forms. my first form is 'sign_up.php' and second is select_subject.php'. sign_up.php page has more categories and users can select up to 3 more categories there. So. after selecting and user click the continue bottom, page want to go to second form page its select_subject.php page. If a user not select a category of who selected over 3 category I need to display a error message. like this "Please select atleast 1, not more than 3 categories." I use this HTML my first page Code: [Select] <form method="post" action="select_subject.php"> <my select boxes> </form> Then I process it in my second page and if user have made a mistake in first page I need to redirect to the first page again with relevant error message. So I use this code in my second page. Code: [Select] } else { // No valid ID, kill the script. $_SESSION['errors'] = "Please select atleast 1, not more than 3 categories."; $url = 'http://localhost/lanka_institute/tutorsignup/tutor_registration.php'; // Define the URL: ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } and my first page I use this Code: [Select] if (isset($_SESSION['errors'])) { echo '<p> ' . $_SESSION['errors'] . '</p>'; } unset($_SESSION['errors']); but it is not printing my error message in the first page that Im expecting. But it printing 'Array' instead of my message. can you help me, what is the mistake that I have done??? thanks in advance. Hi there, New to the forum... thank you in advance for any help! I created a login system using a tutorial found online. Everything works perfectly.. but now the client wants "Hello [First Name]" displayed after logging in. I've tried about 12 different tutorials at this point and can't seem to tweak them enough to work with my code. A lot of the tutorials have session_start(); at the top of their protected (welcome.php) page. But mine seems to be held in a variable in another script and the top of my welcome.php looks like this: Code: [Select] <?PHP require_once("./include/membersite_config.php"); if(!$fgmembersite->CheckLogin()) { $fgmembersite->RedirectToURL("login.php"); exit; } ?> This is what I have on my welcome page as well but I don't know how to make this all come together and work.. Code: [Select] Hello <?php echo $_SESSION['name']; ?> I'm using mySQL 5.0, and php 5.2. Will anyone shed light on this for me? I'll provide any other info you may need.. Thank you I have a login modal window which is user for entering the login and password, and check it with the database.If the login and password is not there i nthe database the message shuld be displayed in the popup window itself. But in my case the popup window disapperas if the login details are wrong. how shuld i code for this. My code is pasted below. <div id="cover"></div> <div id="dialog"> <form action='' method='post' name='onlinepay'> <table width="388" border=1><tr><td colspan="4" align="right"></td><td align="right"><a href="index.php" onclick="closePopUp('dialog');"><img src='images/close.jpg' align="right" /></a></td></tr> <tr><td width="11" ></td> <td width="90">Username </td> <td width="57">:</td> <td width="147"><input type='text' name='username' id='username' /></td><td width="59"></td> </tr> <tr><td></td><td>Password</td><td>:</td><td><input type='text' name='password' id='password' /></td><td><input type='submit' name='submit' id='submit' value="Login" /></td></tr><tr><td colspan='5'><?php //connection statements goes here if(isset($_POST['submit'])){ $username=$_POST['username']; $password=$_POST['password']; $sql="select username,password from register where username='$username' and password='$password'"; $result=mysql_query($sql); $row=mysql_fetch_row($result); $row1=mysql_num_rows($result); if(($row['0']==$username) && ($row['1']==$password)){ header ('Location:themes/index.php'); } else{ echo "Username and password doesnot match"; } } ?> </td></tr> <tr><td colspan="5"><hr color="#999999" /></td></tr><tr><td></td><td colspan='2'><a href="javascript:void window.open('themes/forgotpassword.php?fullview=Y','','height=350,width=525,resizable=yes,scrollbars=yes')">Forgot password? </a> </td> <td><a href='register.php'>New User</a></td> <td align='center'> </td> </tr> </table> </form> how do I make it so that $message displays on form submit on the same page?: Code: [Select] <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; ?> <?php $message ='Registration has been verified!'; // Process the form if it is submitted if ($_POST['submit']) { $verified = $_POST['verified']; $sql = mysql_query("UPDATE Events SET verified='yes', WHERE barcode='$verified'"); exit(); } // close if post ?> <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM members WHERE userid='$userid'"); while($row = mysql_fetch_array($sql)){ $userid = $row["userid"]; $name = $row["name"]; $phone = $row["phone"]; $username = $row["username"]; $address = $row["address"]; $city = $row["city"]; $state = $row["state"]; $zip = $row["zip"]; $cell = $row["cell"]; $email = $row["email"]; $accounttype = $row["accounttype"]; $rank = $row["rank"]; $badges = $row["badges"]; $password = $row["password"]; $password2 = $row["password2"]; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template2.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <!-- InstanceBeginEditable name="doctitle" --> <title>Untitled Document</title> <!-- InstanceEndEditable --> <style type="text/css"> #editregion { position:absolute; left:-8px; top:272px; width:1293px; height:51px; z-index:1; text-align: center; clear: none; float: none; } body { background-image: url(file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/button/boyscout1.png); background-repeat: no-repeat; position: relative; } #menu { position:relative; left:160px; top:0px; width:931px; height:59px; z-index:19; } #menu #MenuBar1 li a { color: #000; border-top-style: outset; border-right-style: outset; border-bottom-style: outset; border-left-style: outset; width: 100px; } #status { position:relative; left:16px; top:180px; width:124px; height:44px; z-index:14; } </style> <script src="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/SpryAssets/SpryMenuBar.js" type="text/javascript"></script> <script type="text/javascript"> function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } </script> <!-- InstanceBeginEditable name="head" --> <style type="text/css"> body { background-image: url(file:///Macintosh%20HD/Users/aaron/Downloads/memberSystemBasic%204/button/boyscout1.png); background-repeat: no-repeat; } </style> <!-- InstanceEndEditable --> <!-- InstanceParam name="id" type="text" value="apDiv6" --> <link href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" /> <style type="text/css"> #logout { position:relative; left:0px; top:0pxpx; width:134px; height:38px; z-index:20; font-weight: bold; font-size: 24px; } #logout a { color: #000; } #status { text-align: center; } #logout1 { position:absolute; left:1071px; top:191px; width:224px; height:61px; z-index:2; } #menu2 { position:absolute; left:-1px; top:172px; width:497px; height:92px; z-index:20; } #footer { position:fixed; left:-10px; top:0px2 width:1290px; height:63px; z-index:1; color: #000; background-color: #000; right: 0px; bottom: 0px; } </style> </head> <body> <div id="logout1"><div id="logout"><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/logout.php">Logout</a></div></div> <div id="status"><?php echo "$accounttype"; ?> <br /><?php echo "$name"; ?> <p> </p> </div> <div id="editregion"><!-- InstanceBeginEditable name="EditRegion3" --> <p> </p> <form id="form1" name="form1" method="post" action=""> Please enter verification code: <label for="verified"></label> <input type="text" name="verified" id="verified" /> </form> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <!-- InstanceEndEditable --><br /><br /> <?php if ($accounttype == "Admin") {echo '<div id="footer"><img src="footer_admin.png" width="1290" height="63" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="10,5,112,32" href="myprofile.php" /> <area shape="rect" coords="153,5,235,31" href="register.php" /> <area shape="rect" coords="277,7,333,32" href="news.php" /> <area shape="rect" coords="471,7,682,33" href="scoutmanager.php" /> <area shape="rect" coords="726,5,874,34" href="membermanager.php" /> <area shape="rect" coords="906,3,1058,34" href="eventmanager.php" /> <area shape="rect" coords="1092,6,1226,32" href="newsmanager.php" /> </map> </div>'; } else if ($accounttyp="scout"){echo '<div id="footer"><img src="footer_scout.png" width="1290" height="63" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="526,6,632,34" href="myprofile.php" /> <area shape="rect" coords="668,5,752,32" href="register.php" /> <area shape="rect" coords="789,5,850,34" href="news.php" /> </map> </div>';} else {echo '<div id="footer"><img src="footer_admin.png" width="1290" height="63" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="10,5,112,32" href="myprofile.php" /> <area shape="rect" coords="153,5,235,31" href="register.php" /> <area shape="rect" coords="277,7,333,32" href="news.php" /> <area shape="rect" coords="471,7,682,33" href="scoutmanager.php" /> <area shape="rect" coords="726,5,874,34" href="membermanager.php" /> <area shape="rect" coords="906,3,1058,34" href="eventmanager.php" /> <area shape="rect" coords="1092,6,1226,32" href="newsmanager.php" /> </map> </div>'; } ?></div> <div id="menu2"><div id="menu"> <ul id="MenuBar1" class="MenuBarHorizontal"> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/myprofile.php">My Profile</a> </li> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/register.php">Register</a></li> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/projects.php">Projects</a> </li> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/news.php">News</a></li> <?php if ($accounttype == "Admin") { ?> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/membermanager.php">Scout Manager</a></li> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/eventmanager.php">Event Manager</a></li> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/newsmanager.php">News Manager</a></li> </ul><?php } ?> </div></div> <script type="text/javascript"> var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"}); </script> </body> <!-- InstanceEnd --></html> Hi,
I'm trying to display a message first before redirect to other page, but my code just directly redirect the page without display the message.please help me.
if($num_rows == 0) { echo '<script type="text/javascript">alert("Please Enter Correct Details!");</script>'; header ('Location :login.php'); } Hello all, my first post after joining this very informative site, unfortunatly I was unable to find the answer to my simple yet frastrating dilemma. I am in the process of building a website that will enable users to log-in through a dedicated loginU.php page, I have all of this working but I would like to display an error message on this page saying if the user has entered a wrong username/password, I have the message displaying on a blank white page, but I would like it to be displayed within the container I have created. the validation code is contained within a different login.php file. At the moment I am using an iframe to display the messages, which I know is not the right way to do it, so am asking for a better way to do it. here is what I have so far: loginU.php Code: [Select] <div id = "div-Login"> <form action="login.php" method="POST" target="loginerror"> <center><h2>Login Here</h2> <p> Username: <input type="text" name="username"><p> Password: <input type="password" name="password"><p> <input type="submit" name="submit" value="Login"> </center> <a href="register.html"><pre>need to register? Click Here!</pre></a> </form> <iframe name="loginerror" style="border: 0px; width: 200px; height: 100px; overflow: hidden;" src="login.php"></iframe> </div> login.php Code: [Select] if ($username==$dbusername&&$enc_password==$dbpassword) //if the username & encrpyted password matches the records in the database { if($admin !=0) //if the admin flag is true { $_SESSION['level']='ADMIN';//admin is logging in header ("Location: admin.php"); //the user is an admin, direct to admin page } else header ("Location: index.php"); //user is a customer, direct user to index page $_SESSION['username']=$dbusername; //set the session name to the database record username. } else //$nopass='TRUE'; //header ("location: loginU.php"); echo "Incorrect Password, Please try again"; // if incorrect password } else die ("That username doesn't exist"); // if user doesn't exist } else die ("Please enter a username and password"); //if either field is empty ?> how can i disply this message withing the form echo "data submitted successfully!"; currently after validation check when data is entered the message show on top of my page not within the form function insertDATA($postData) { if(!ifEmailExists($postData['email'])){ $sql = " INSERT INTO tbl SET email = '".$postData['email']."', name = '".$postData['name']."', phone = '".$postData['phone']."' "; echo "data submitted successfully!";//this line withing the form executeSql($sql); } Please i need help on popup message when an image is clicked. Some one should help me with the code to place in my html document. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347166.0 I am building a website that uses session variables extensively. The site is getting a little complicated, and I am starting to lose track of which session variables are assigned, and what their values are. Is there some way where I can create a piece of code that will display all of the existing session variables and their values? I am attempting to us glob to display contents of a users folder using a session variable. Example: I have a session variable called department Code: [Select] $row_fullname['department']; In department I have the name of the department the user belongs to such as: office, plant, maintenance, and groundskeeping I created a folder called docs inside of docs there are 4 subfolders called office, plant, maintenance, and groundskeeping I found this code which will display the contents of the folder: Code: [Select] <?php $files = glob( './docs/office/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/office/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?> The above code works fine, but I would like it to only display the contents of a departments folder only if the user is part on that department. Here is an example that I know is completely wrong but it may help explain what I am trying to do. Code: [Select] <?php ]<?php $files = glob( './docs/echo $row_fullname['department'];/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/echo $row_fullname['department'];/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?>Thanks for your time Hello, I have coded a contact form in PHP and I want to know, if according to you, it is secure! I am new in PHP, so I want some feedback from you. Moreover, I have also two problems based on the contact form. It is a bit complicated to explain, thus, I will break each of my problem one by one. FIRST:The first thing I want to know, is if my contact form secure according to you: The HTML with the PHP codes: Code: [Select] <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { //Assigning variables to elements $first = htmlentities($_POST['first']); $last = htmlentities($_POST['last']); $sub = htmlentities($_POST['subject']); $email = htmlentities($_POST['email']); $web = htmlentities($_POST['website']); $heard = htmlentities($_POST['heard']); $comment = htmlentities($_POST['message']); $cap = htmlentities($_POST['captcha']); //Declaring the email address with body content $to = 'alithebestofall2010@gmail.com'; $body ="First name: '$first' \n\n Last name: '$last' \n\n Subject: '$sub' \n\n Email: '$email' \n\n Website: '$web' \n\n Heard from us: '$heard' \n\n Comments: '$comment'"; //Validate the forms if (empty($first) || empty($last) || empty($sub) || empty($email) || empty($comment) || empty($cap)) { echo '<p class="error">Required fields must be filled!</p>'; header ('refresh= 3; url= index.php'); return false; } elseif (filter_var($first, FILTER_VALIDATE_INT) || filter_var($last, FILTER_VALIDATE_INT)) { echo '<p class="error">You cannot enter a number as either the first or last name!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Incorrect email address!</p>'; return false; } elseif (!($cap === '12')){ echo '<p class="error">Invalid captcha, try again!</p>'; return false; } else { mail ($to, $sub, $body); echo '<p class="success">Thank you for contacting us!</p>'; } } ?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <p>Your first name: <span class="required">*</span></p> <p><input type="text" name="first" size="40" placeholder="Ex: Paul"/></p> <p>Your last name: <span class="required">*</span></p> <p><input type="text" name="last" size="40" placeholder="Ex: Smith"/></p> <p>Subject: <span class="required">*</span></p> <p><input type="text" name="subject" size="40" placeholder="Ex: Contact"/></p> <p>Your email address: <span class="required">*</span></p> <p><input type="text" name="email" size="40" placeholder="Ex: example@xxx.com"/></p> <p>Website:</p> <p><input type="text" name="website" size="40" placeholder="Ex: http//:google.com"/></p> <p>Where you have heard us?: <span class="required">*</span></p> <p><select name="heard"> <option>Internet</option> <option>Newspapers</option> <option>Friends or relatives</option> <option>Others</option> </select></p> <p>Your message: <span class="required">*</span></p> <p><textarea cols="75" rows="20" name="message"></textarea></p> <p>Are you human? Sum this please: 5 + 7 = ?: <span class="required">*</span></p></p> <p><input type="text" name="captcha" size="10"/></p> <p><input type="submit" name="submit" value="Send" class="button"/> <input type="reset" value="Reset" class="button"/></p> </form> SECOND PROBLEM:If a user has made a mistake, he gets the error message so that he can correct! However, when a mistake in the form occurs, all the data the user has entered are disappeared! I want the data to keep appearing so that the user does not start over again to fill the form. THIRD: When the erro message is displayed to notify the user that he made a mistake when submitting the form, the message is displaying on the top of the page. I want it to appear below each respective field. How to do that? In JQuery it is simple, but in PHP, I am confusing! in this page http://maximaart.com/newscp/ i have this problem Code: [Select] Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/maximasy/public_html/newscp/index.php:1) in /home/maximasy/public_html/newscp/index.php on line 2 my source code is <?php session_start(); include_once("config.php"); include_once("functions.php"); $errorMessage = ''; if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) { if ($_POST['txtUserId'] === "$user" && $_POST['txtPassword'] === "$pass") { // the user id and password match, $_SESSION['basic_is_logged_in'] = true; require("main.php"); exit;?> I am trying to create an index page which contains registration and login field the problem that i get is on successful login a warning is displayed session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\Eventz.com\index.php:116) in C:\xampp\htdocs\Eventz.com\index.php on line 235 This is the login part of my index.php this tag is inside an html table below the login form I also have a registration form and its php code above the login form Code: [Select] <?php if (isset($_REQUEST['pass'])) { $id=$_POST['id']; $pass=$_POST['pass']; $conn =mysql_connect("localhost","root",""); if (!$conn) { die('Could not connect: ' . mysql_error()); } /* checking connection....success! */ $e=mysql_select_db('test', $conn); if(!$e) { die(''.mysql_error()); } else { echo 'database selected successfully'; } if (isset($_REQUEST['id']) || (isset($_REQUEST['pass']))) { if($_REQUEST['id'] == "" || $_REQUEST['pass']=="") { echo "login fields cannot be empty"; } else { $sql=mysql_query("Select email,password from login where email='$id' AND password='$pass'"); $count=mysql_num_rows($sql); if($count==1) /* $count checks if username and password are in same row */ { session_start(); $_SESSION['id']=$id; echo "</br>Login Successful</br>"; } else { echo "</br>invalid</br>"; echo "please try to login again</br>"; } } } } ?> Any help or suggestion would be appreciated |