Hi guys I 'm having extreme headaches with a php displaying contents from a $POST or a $COOKIE.
I'm creating a page that allows a user to view information that they've entered in a page on a previous page.
Simple Right ?
I only changed table pointing information when I copied code from my already 'working' page (only difference table and some fields).
testing: the database works.
I ran a separate test for this
i did
= mysql_error(), initially got a dredded vars error at point in code, called host server comp
=print_r for $res ---it returned Resource ID#241 (read manual don't quite understand yet)
=i also echoed $_COOKIE- got back the set cookie
what happens is that the page jump to else statement " bad username..."
doesn't even post form with info for user to view profile
here is the authenication at the post of the form:
outbuffering is set at top of page along with a session_start()
<?php
include("includes/connectdb_host.php") or die(mysql_error());
if (!isset($_POST['update'])){
header('location:login_test.php');
exit;
}
$prod_user=$_POST['prod_user'];
$prod_pass=$_POST['prod_pass'];
$authorized=false;
//echo " <br> user is". $prod_user. "prod_pass is". $prod_pass";
//empty pass will show a random profile of empty password when everyone's logged out, so no empty pass variables should be kept
if($prod_pass=="")
$prod_pass="xyz";
// echo" <br> user is $prod_user, prod_pass is $prod_pass";
//if(!empty($_POST)) //i.e. dont run when no post is sent,
$query=mysql_query ("SELECT * FROM producer WHERE prod_user='$prod_user'");
//if(!$query)
//echo(" <br> cant verify password, db error? <br>");
while($res=mysql_fetch_array($query))
{
if($res['prod_pass']==$prod_pass)
{
$authorized=true;
$id=$res['id'];
echo $res['id'];
}
}
//if still not authorized, check cookies and try if the user is valid (this is actually giving it a second chance) if user/pass not sent via post then check cookies
if(!$authorized)
{
$query=mysql_query("SELECT * FROM producer WHERE prod_user='".$_COOKIE['prod_user']."' LIMIT 1") ;
while($res=mysql_fetch_array($query))
{
if($res['prod_pass']==$_COOKIE['prod_pass'])
{
$authorized=true;
$id=$res['id'];
//overwrite $user and $pass <<-- these will have data from post, but since we're using the 2nd resort i.e. cookies so update cookies values into these
$prod_user=$_COOKIE['prod_user'];
$prod_pass=$_COOKIE['prod_pass'];
}
}
}
if($authorized)
{
//echo "Congratulations you've logged in<br>";
//setcookies now to remember the user
setcookie("prod_user",$prod_user);
setcookie("prod_pass",$prod_pass);
//echo("<br>cookies set<br>");
echo "<br><a href=\"logout_test.php\">Log out</a> |  <a href=\"pEditProfile.php\">Edit your profile</a> <a href=\"search_test.php\">Log IN</a><br> <br> ";
//show the profile data of the the user
$query=mysql_query("SELECT * FROM producer WHERE id=$id");
while($res=mysql_fetch_array($query))
{
?>
<?php
}
}
else
{
echo "<br><br>Bad username or password || If you're a producer <a href=\"login2_prod.php\">click here to get to the login page</a><br><br><br>";
}
?>
[/code]
Any feedback would be great. Everything works accept this page