paul red Posted April 28, 2007 Share Posted April 28, 2007 Hi I'm new to php and I have a problem with my final year project (its due in a week :'( ...) Anyway, I've been browsing around your forum looking for a way to apply cookie to my inventory system. But it doesn't seem to work...Can someone show me where I've gone wrong? this is my login code <? $username = "root"; $password = "inventory"; $db_name = "inventory system"; $tb_name = "admin"; $StaffID = $_POST['StaffID']; $Password = $_POST['Password']; mysql_connect("localhost",$username,$password) or die ("cannot connect server"); mysql_select_db("$db_name") or die ("cannot connect database"); if($rec=mysql_fetch_array(mysql_query("SELECT * FROM staff WHERE StaffID='$StaffID' AND Password = '$Password'"))) { if(($rec['StaffID']==$StaffID)&&($rec['Password']==$Password)) { session_register("staff_session"); setcookie("StaffID",$_GET['StaffID']); echo "<p class=data> <center>Successfully,Logged in<br><br><a href='logoutstaff.php'> Log OUT </a><br><br><a href=staff.php>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>"; print "<script>"; print " self.location='staff.php';"; // Comment this line if you don't want to redirect print "</script>"; } } else { include("Stafflogin.php"); session_destroy(); ?> <script language="javascript"> alert("access denied"); //location= "adminlogin.php"; history.back(); </script> <? } ?> and this is my staff.php page code <?php session_start(); if(!session_is_registered("staff_session")) { header("Location: Stafflogin.php"); exit(); } $StaffID=$_REQUEST['StaffID']; if (isset($_COOKIE['StaffID'])) { echo "You've got cookies!"; echo $_POST['StaffID'];} else { echo "No cookies for you!"; } ?> it keeps showing "No cookies for you!" Please help... Link to comment https://forums.phpfreaks.com/topic/49108-cookie-not-working/ Share on other sites More sharing options...
valtido Posted April 29, 2007 Share Posted April 29, 2007 Why not try this. instead of exit use die(''); coz exit is a vb thingy. I think you have got it all wrong mate have a look at this section here if it helps:D if not let me know so i can re write the whole script and explain where you went wrong or something:D http://www.phpfreaks.com/forums/index.php/topic,136739.0.html hope it helps if not i will try n help you mate c u Link to comment https://forums.phpfreaks.com/topic/49108-cookie-not-working/#findComment-240730 Share on other sites More sharing options...
tauchai83 Posted April 29, 2007 Share Posted April 29, 2007 Hi I'm new to php and I have a problem with my final year project (its due in a week :'( ...) are you doing your final year project last minute? LOL. inventory system for one week? i guess the output must be less. <?php if($Username == ''){ echo "<li>Sorry! Please fill in your username."; }else if($Password == ''){ echo "<li>Sorry! Please fill in your password."; }else{ $qry_chk = "select user_id from user where user_id= '$Username' and cst_Password = '$Password'"; $result_chk = mysql_query($qry_chk); if(mysql_num_rows($result_chk) > 0){ list($userID) = mysql_fetch_row($result_chk); setcookie("custID",$userID); }else{ echo "<li>Sorry! Your username or password is invalid."; } } ?> try this simple script. Link to comment https://forums.phpfreaks.com/topic/49108-cookie-not-working/#findComment-240844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.