Hi Peter, are you limited to using arrays? If not, try msql_fetch_row()
since you are only looking for the one record, ie: the corresponding
username and password record for the username and password that was passed.
Hope this helps, Joe :)
<?php
session_start();
include("config.php");
mysql_connect($host_name, $user_name, $passwd)
or die("Unable to connect to $hostname.");
// select database on MySQL server
mysql_select_db($db_name) or die("Unable to select databse.");
// formulate the query
$sql_statement = "SELECT user_id, password FROM $table_name WHERE
user_id = '$user_id' AND
password = '$password'";
$result = mysql_query($sql_statement) or die("Unable to execute
query.");
//if there is a corresponding record
if(mysql_fetch_row($result)) {
$usid = mysql_result($result,0);
$pswd = mysql_result($result, 1);
//create session variables
session_register("password");
$password = $pswd;
session_register("user_id");
$username = $usid;
//echo a friendly message or use header() function to redirect the user to
the appropriate page
echo "Succesful login!";
}
else
{
//the user is not a registered member so redirect them to a sign up page or
another page to try and login again
header("Location: signup.php");
}
?>
Peter Ruan <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi,
> I am running into a problem that I can't figure out the solution to. So
> I'm hoping that someone can give me some pointers here. I have two files
> (see below): verify.php and edit.php
> The job of verify.php is basically to verify that a user is in the
> database before allowing him/her to edit the information. The information
> retrieved is saved to arrary varaiable $row. I do a session_register() to
> $row and that information should be passed to subsequent pages that has
> session_start(), right? However, when I tried to print out the
information
> again in edit.php, it doesn't seem to register it in. At first I thought
it
> was the array problem, so I put the array variable $dummy to test it out
and
> that can be reigstered and retrieved correctly. What am I doing wrong???
> Also, how do I redirect to a page automatically once the user is verfied
> (right now I have to ask the user to click on a link to redirect).
>
> Thanks in advance,
> Peter
>
> /******* verify.php ********/
> <?php
> session_start();
>
> include("config.php");
> mysql_connect($host_name, $user_name, $passwd)
> or die("Unable to connect to $hostname.");
> // select database on MySQL server
> mysql_select_db($db_name) or die("Unable to select databse.");
>
> // formulate the query
> $sql_statement = "SELECT * FROM $table_name WHERE
> user_id = '$user_id' AND
> password = '$password'";
>
> $result = mysql_query($sql_statement) or die("Unable to execute
> query.");
>
> $num_of_rows = mysql_num_rows($result);
> /* XXX: test array variable...take out later */
> $dummy = array("one", "two", "three");
> session_register(dummy);
>
> if (!$num_of_rows) {
> echo "<h3>User ID and password missmatch, try again!</h3>";
> } else {
> while ($row = mysql_fetch_array($result)) {
> session_register(row); // register information retrieved from
> MySQL
> }
> printf("Successfully Logged In! <a href=\"edit.php\">Click
> Here</a>");
> echo "<br>";
> }
> ?>
>
>
> /************* edit.php *****************/
> <?php
> session_start();
> foreach ($dummy as $val) {
> echo $val . "<br>";
> }
>
> foreach ($row as $data) {
> echo $data . "<br>";
> }
> ?>
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php