Validate USEr Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

petenyce108
Forum Newbie
Posts: 7
Joined: Wed Feb 18, 2004 5:50 pm

Validate USEr Problem

Post by petenyce108 »

Im trying to validate a users. I have a mysql database set up and the php code is validating all three if not returns a error. All is fine but ehres the problem. If users MemID is 1 then i want them to see page 1 if users MemID is 2 then i want them to see page 2. The code i have shows all three users the same page , how can i get it to show each user a different page based on MemID????

Here s code


<html>

<head>
<title>Member Look up</title>

</head>

<body bgcolor="006666">
<?php
if ($_POST['Facid'] != "") $Facid = $_POST['Facid'];
if ($Facid != "") {
@ $db = mysql_pconnect('host', 'name', 'password');

if (!$db) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$listing_query = "select * from DB.Facility where Facid = '".$Facid."'";
$listing_result = mysql_query($listing_query) or die("Error in return query<br>".mysql_error());
$num_rows = mysql_num_rows($listing_result);
if ($num_rows == 0) {
echo '<font color="white"><b>Please try again</b></font></br></br>';
print "Practice ID invalid.</br></br>";
echo '<a href ="poup.html"><font color="white">Back</font></a>';

} else {
?>
<? php
<script language="JavaScript">
window.location = "reports_1st_quarter.htm";
</script>
<?php
}
} else { ?>
<form method="POST">
<p align="left"><b><font color="#FFFFFF">Enter Practice Id</font></b></p>
<p align="left">
<input type="text" name="Facid" size="20">
<input type="submit" value="Go">
</p>
</form>

<?php } ?>
<p align="center">&nbsp;</p>
</body>

</html>



SOme body please help cant find any research????? :(
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

Code: Select all

<?php
$row = mysql_fetch_array($listing_result);
$id = $row["MemID"];

if ($id == "1") {
// display your page one
}

if ($id == "2") {
// display your page two
}

// and so forth


?>
Is that what u wanted? I'm a lil unclear how ur set-up is
petenyce108
Forum Newbie
Posts: 7
Joined: Wed Feb 18, 2004 5:50 pm

I tried that and i get a error

Post by petenyce108 »

heres the code i added i bolded it


<html>

<head>
<title>Referral History Look Up</title>

</head>

<body bgcolor="006666">
<?php
if ($_POST['Facid'] != "") $Facid = $_POST['Facid'];
if ($Facid != "") {
@ $db = mysql_pconnect('localhost', 'eni', 'password');

if (!$db) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$listing_query = "select * from eni.Facility where Facid = '".$Facid."'";
$listing_result = mysql_query($listing_query) or die("Error in return query<br>".mysql_error());
$num_rows = mysql_num_rows($listing_result);
if ($num_rows == 0) {
echo '<font color="white"><b>Please try again</b></font></br></br>';
print "Practice ID invalid.</br></br>";
echo '<a href ="refpop.php"><font color="white">Back</font></a>';
} else {
?>
?>
<?php
$row = mysql_fetch_array($listing_result);
$id = $row["MemID"];
if ($id == "1") {
reports_1st_quarter.htm
}

if ($id == "2") {
Facility2.htm
}

?>

}
} else { ?>
<form method="POST">
<p align="left"><b><font color="#FFFFFF">Enter Practice Id</font></b></p>
<p align="left"><b><font color="#FFFFFF">Referral History Login</font></b></p>
<p align="left">
<input type="text" name="Facid" size="20">
<input type="submit" value="Go">
</p>
</form>

<?php } ?>
<p align="center">&nbsp;</p>
</body>

</html>
<?php
// End session
page_close();
?>
petenyce108
Forum Newbie
Posts: 7
Joined: Wed Feb 18, 2004 5:50 pm

Post by petenyce108 »

im still haveing a problem with the above code Pete
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

well u ended the php that has the database connection in it so it has no Database/table to even pull a array from... u need to put that by your

Code: Select all

<?php
$listing_query = "select * from eni.Facility where Facid = '".$Facid."'"; 


?>
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

and for testing puropse, change this:

Code: Select all

<?php
if ($id == "1") { 
reports_1st_quarter.htm 
} 

if ($id == "2") { 
Facility2.htm 
} 
?>


to:

Code: Select all

<?php
if ($id == "1") { 
echo "Id # 1";
} 

if ($id == "2") { 
echo "id # 2";
} 
?>
this will let us know if its picking up the memID variable
petenyce108
Forum Newbie
Posts: 7
Joined: Wed Feb 18, 2004 5:50 pm

Im getting a parse error near the code

Post by petenyce108 »

im almost there im gettign a parse error near the code i added dont know why heres the code

<html>

<head>
<title>Member Look up</title>

</head>

<body bgcolor="006666">
<?php
if ($_POST['Facid'] != "") $Facid = $_POST['Facid'];
if ($Facid != "") {
@ $db = mysql_pconnect('localhost', 'en', 'password');

if (!$db) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$listing_query = "select * from en.Facility where Facid = '".$Facid."'";
<?php
$row = mysql_fetch_array($listing_result);
$id = $row["MemID"];

if ($id == "1") {
echo "Id # 1";
}

if ($id == "2") {
echo "Id # 2";
}


?>

$listing_result = mysql_query($listing_query) or die("Error in return query<br>".mysql_error());
$num_rows = mysql_num_rows($listing_result);
if ($num_rows == 0) {
echo '<font color="white"><b>Please try again</b></font></br></br>';
print "Practice ID invalid.</br></br>";
echo '<a href ="poup.html"><font color="white">Back</font></a>';

} else {
?>

}
} else { ?>
<form method="POST">
<p align="left"><b><font color="#FFFFFF">Enter Practice Id</font></b></p>
<p align="left">
<input type="text" name="Facid" size="20">
<input type="submit" value="Go">
</p>
</form>

<?php } ?>
<p align="center">&nbsp;</p>
</body>

</html>



Im getting a parse error near the bolded code i dont know why and when i add the .html files in do i need a window.location to direct the user to the right page or no? Pete
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

lol, dont use the <?php and ?> tags...

here:

Code: Select all

$listing_query = "select * from en.Facility where Facid = '".$Facid."'"; 
<?php 
$row = mysql_fetch_array($listing_result); 
$id = $row["MemID"]; 

if ($id == "1") { 
echo "Id # 1"; 
} 

if ($id == "2") { 
echo "Id # 2"; 
} 


?> 
$listing_result = mysql_query($listing_query) or die("Error in return query<br>".mysql_error());


change to:

Code: Select all

$listing_query = "select * from en.Facility where Facid = '".$Facid."'"; 
$listing_result = mysql_query($listing_query) or die("Error in return query<br>".mysql_error()); 
$row = mysql_fetch_array($listing_result); 
$id = $row["MemID"]; 

if ($id == "1") { 
echo "Id # 1"; 
} 

if ($id == "2") { 
echo "Id # 2"; 
}
u need to query the database selection first, then fetch your array.

I guess I should have been alot more specific, sorry.

try that, if the MemID=1 it should echo:

Id # 1

let me know.


?>
petenyce108
Forum Newbie
Posts: 7
Joined: Wed Feb 18, 2004 5:50 pm

Well i tried what u said and still parse error

Post by petenyce108 »

heres the code still getting the parse error now it says at the bottom where theres no code Pete

<html>

<head>
<title>Member Look up</title>

</head>

<body bgcolor="006666">
<?php
if ($_POST['Facid'] != "") $Facid = $_POST['Facid'];
if ($Facid != "") {
@ $db = mysql_pconnect('localhost', 'eni', 'password');

if (!$db) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$listing_query = "select * from ehpadmin.Facility where Facid = '".$Facid."'";
$listing_result = mysql_query($listing_query) or die("Error in return query<br>".mysql_error());
$row = mysql_fetch_array($listing_result);
$id = $row["MemID"];

if ($id == "1") {
echo "Id # 1";
}

if ($id == "2") {
echo "Id # 2";
}

$num_rows = mysql_num_rows($listing_result);
if ($num_rows == 0) {
echo '<font color="white"><b>Please try again</b></font></br></br>';
print "Practice ID invalid.</br></br>";
echo '<a href ="poup.html"><font color="white">Back</font></a>';

} else {
?>

}
} else { ?>
<form method="POST">
<p align="left"><b><font color="#FFFFFF">Enter Practice Id</font></b></p>
<p align="left">
<input type="text" name="Facid" size="20">
<input type="submit" value="Go">
</p>
</form>


<p align="center">&nbsp;</p>
</body>
<?php } ?>
</html>



Thanks for all help im not a professional and im trying my best
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

what line # has the error in it?

Code: Select all

<html> 

<head> 
<title>Member Look up</title> 

</head> 

<body bgcolor="006666"> 
<?php 
if ($_POST['Facid'] != "") $Facid = $_POST['Facid']; 
if ($Facid != "") { 
@ $db = mysql_pconnect('localhost', 'eni', 'password'); 

if (!$db) { 
echo 'Error: Could not connect to database. Please try again later.'; 
exit; 
} else {
$listing_query = "select * from ehpadmin.Facility where Facid = '".$Facid."'"; 
$listing_result = mysql_query($listing_query) or die("Error in return query<br>".mysql_error()); 
$row = mysql_fetch_array($listing_result); 
$id = $row["MemID"]; 

if ($id == "1") { 
echo "Id # 1"; 
} 

if ($id == "2") { 
echo "Id # 2"; 
} 
$num_rows = mysql_num_rows($listing_result); 
if ($num_rows == 0) { 
echo '<font color="white"><b>Please try again</b></font></br></br>'; 
print "Practice ID invalid.</br></br>"; 
echo '<a href ="poup.html"><font color="white">Back</font></a>'; 

}  else { 
<form method="POST"> 
<p align="left"><b><font color="#FFFFFF">Enter Practice Id</font></b></p> 
<p align="left"> 
<input type="text" name="Facid" size="20"> 
<input type="submit" value="Go"> 
</p> 
</form> 
  }
}
</body> 
</html> 
?>
U had two else commands that basically wasnt needed... u had some other things I fixxed, this code looks good to me.
try it
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Also change this

Code: Select all

<?php
if ($id == "1") { 
echo "Id # 1"; 
} 

if ($id == "2") { 
echo "Id # 2"; 
} 
?>
to

Code: Select all

<?php
if ($id == "1") { 
echo "Id # 1"; 
} elseif ($id == "2") { 
echo "Id # 2"; 
} 
?>
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

umm..

Code: Select all

//you'll need to get $id before here
include($id . ".php");
petenyce108
Forum Newbie
Posts: 7
Joined: Wed Feb 18, 2004 5:50 pm

But if you want the user to see a different page

Post by petenyce108 »

i dont want it to display in the popup the include will display in the popup i want the user to be directed to that page?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

What did you just say... is it me or doesnt that not make any sense
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Please be more clear.

Give me a run down of what will happen.

Something like:

- User logs in
- $id variable gets set determined by the username
- pops up with their special page

etc.
Post Reply