spires Posted May 14, 2008 Share Posted May 14, 2008 Hi Guys. I'm trying to register a session, but I just can't seem to get it to work. Can you please help me find the fault. Thanks for any help <?PHP session_start(); include("dbconnect.php"); $arrErrors = array(); if (!empty($_POST['submit'])) { if ($_POST['Pword']==''){ $arrErrors['Pword'] = 'Add Your Password'; $star1 = '*'; } if ($_POST['email']==''){ $arrErrors['email'] = 'Add Your Email'; $star2 = '*'; } if (count($arrErrors) == 0) { $password1=$_POST['Pword']; $email1=$_POST['email']; $sql="SELECT * FROM awards_register WHERE email='$email1' && Pword='$password1'"; $result = mysql_query($sql); $count = mysql_num_rows($result); $row = mysql_fetch_array($result); $reg_id = $row['reg_id']; if($count==1){ session_register("reg_id"); echo $_SESSION['reg_id']; //header("Location:rewards_members.php"); } else { $noinput = '<div class="warning">Your details are incorrect<br>Please try again</div>'; } } else { if (empty($password1) || empty($email1)) { $strError = '<div class="warning">ERROR<br></div><div class="boxTitle">'; foreach ($arrErrors as $error) { $strError .= "<li>$error</li>"; } $strError .= '</div>'; } } } ?> <!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=ISO-8859-1" /> <title>Untitled Document</title> </head> <body> <?PHP if ($strError){ echo $strError; } if ($noinput){ echo '<br>'.$noinput; } echo '<br> <form action="'.$PHP_SELF.'" method="post" name="form1"> <table width="200" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="25">Email: </td> <td height="25"><input name="email" type="text" size="15" value="'.$_POST['email'].'"/></td> <td height="25"><span class="smallOrange">'.$star2.'</span></td> </tr> <tr> <td width="90" height="25">Password: </td> <td width="90" height="25"><input name="Pword" type="text" size="15" value="'.$_POST['Pword'].'" /></td> <td width="20" height="25"><span class="smallOrange">'.$star1.'</span></td> </tr> <tr> <td height="30" colspan="3" align="center"><input type="submit" class="smallOrange" name="submit" value="Login" /></td> </tr> </table> </form> '; ?> </body> </html> Thanks Link to comment https://forums.phpfreaks.com/topic/105676-solved-sessions-help-please/ Share on other sites More sharing options...
MadTechie Posted May 14, 2008 Share Posted May 14, 2008 change <?php session_register("reg_id"); echo $_SESSION['reg_id']; ?> to <?php $_SESSION['reg_id'] = $reg_id; echo $_SESSION['reg_id']; ?> if you script use session_register(), it will not work in environments where the PHP directive register_globals is disabled. Link to comment https://forums.phpfreaks.com/topic/105676-solved-sessions-help-please/#findComment-541414 Share on other sites More sharing options...
spires Posted May 15, 2008 Author Share Posted May 15, 2008 Thats excellent. Are you saying that it is better to create the sessions this way instead of using session_register? Thanks for your help Link to comment https://forums.phpfreaks.com/topic/105676-solved-sessions-help-please/#findComment-541419 Share on other sites More sharing options...
PFMaBiSmAd Posted May 15, 2008 Share Posted May 15, 2008 The session_register (and related functions) were depreciated in php4.2 in the year 2002 when register globals were turned off by default. Link to comment https://forums.phpfreaks.com/topic/105676-solved-sessions-help-please/#findComment-541421 Share on other sites More sharing options...
DeanWhitehouse Posted May 15, 2008 Share Posted May 15, 2008 yer, please select topic solved at the bottom if it is. Link to comment https://forums.phpfreaks.com/topic/105676-solved-sessions-help-please/#findComment-541423 Share on other sites More sharing options...
spires Posted May 15, 2008 Author Share Posted May 15, 2008 Ok, Thanks for letting me know. Cheers Link to comment https://forums.phpfreaks.com/topic/105676-solved-sessions-help-please/#findComment-541424 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.