Page 1 of 2
Validate USEr Problem
Posted: Wed Feb 18, 2004 5:50 pm
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"> </p>
</body>
</html>
SOme body please help cant find any research?????

Posted: Wed Feb 18, 2004 6:01 pm
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
I tried that and i get a error
Posted: Wed Feb 18, 2004 6:16 pm
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"> </p>
</body>
</html>
<?php
// End session
page_close();
?>
Posted: Wed Feb 18, 2004 6:16 pm
by petenyce108
im still haveing a problem with the above code Pete
Posted: Wed Feb 18, 2004 6:19 pm
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."'";
?>
Posted: Wed Feb 18, 2004 6:23 pm
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
Im getting a parse error near the code
Posted: Wed Feb 18, 2004 6:27 pm
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"> </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
Posted: Wed Feb 18, 2004 6:34 pm
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.
?>
Well i tried what u said and still parse error
Posted: Wed Feb 18, 2004 6:41 pm
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"> </p>
</body>
<?php } ?>
</html>
Thanks for all help im not a professional and im trying my best
Posted: Wed Feb 18, 2004 6:48 pm
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
Posted: Wed Feb 18, 2004 7:47 pm
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";
}
?>
Posted: Wed Feb 18, 2004 10:12 pm
by d3ad1ysp0rk
umm..
Code: Select all
//you'll need to get $id before here
include($id . ".php");
But if you want the user to see a different page
Posted: Wed Feb 18, 2004 10:16 pm
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?
Posted: Wed Feb 18, 2004 10:18 pm
by John Cartwright
What did you just say... is it me or doesnt that not make any sense
Posted: Wed Feb 18, 2004 10:21 pm
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.