Oracle help please
Posted: Fri Nov 28, 2003 9:45 am
im totally new to php, i created a logon useing mysql, but have been told i now have to use oracle 9i, and when i change the functions over it wont work... can u have a loo at my code please and tell me if im on the right lines.. i have left the mysql code there but its commented out... cheers
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Northumbria books</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
/**
* Check to see if username and password have already been submitted from a previous
* form if has not then display the login form. For security reasons use $_POST[] to
* get the variables as some servers do not use register_globals in there php.ini.
**/
if (!isset($_POST['username']) && !isset($_POST['password']))
{
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border = 1>
<tr>
<th>Username</th>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<th>Password</th>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan = 2 align = center>
<input type="submit" name="submit" value="Login" />
</td>
</tr>
</table>
</form>
<?php
}
else
{
/**
* If a previous submition has occured then do the following...
**/
/** connect to the database **/
//$mysql = mysql_pconnect('localhost','webauth','webauth');
$conn = OCIPLogon ("jusername","password","host");
//if(!$mysql)
if(!$conn)
{
echo "Cant connect to the database";
exit;
}
/** Select database **/
//$mysql = mysql_select_db('auth');
//if (!$mysql)
//{
//echo "Cannot select the required database";
//exit;
//}
/** Query database for specific username **/
$input_username = $_POST['username'];
//$query = "SELECT * FROM auth
//WHERE
//name = '$input_username'
//";
$query = OCIParse ($conn,"SELECT * FROM USERLOGON
WHERE
USERID = '$input_username'
");
OCIExecute ($query);
//$result = mysql_query($query);
ocifetch ($query);
$result = $query;
if (!$query)
{
echo "Cannot run query";
exit;
}
else
{
/**
* Store results of query in an array from database.
**/
//$_ARRAY = mysql_fetch_array($result);
$_ARRAY = OCIFetchinto ($result);
$stored_user = $_ARRAY['USERID'];
$stored_pass = $_ARRAY['PASSWORD'];
/**
* If users password in database matches the password submitted
* allow access else just deny.
**/
if($stored_pass == $password)
{
echo "Hello $stored_user you are logged on! ";
}
else
{
echo "That account does not exist!";
}
}
}
?>
</body>
</html>
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Northumbria books</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
/**
* Check to see if username and password have already been submitted from a previous
* form if has not then display the login form. For security reasons use $_POST[] to
* get the variables as some servers do not use register_globals in there php.ini.
**/
if (!isset($_POST['username']) && !isset($_POST['password']))
{
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border = 1>
<tr>
<th>Username</th>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<th>Password</th>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan = 2 align = center>
<input type="submit" name="submit" value="Login" />
</td>
</tr>
</table>
</form>
<?php
}
else
{
/**
* If a previous submition has occured then do the following...
**/
/** connect to the database **/
//$mysql = mysql_pconnect('localhost','webauth','webauth');
$conn = OCIPLogon ("jusername","password","host");
//if(!$mysql)
if(!$conn)
{
echo "Cant connect to the database";
exit;
}
/** Select database **/
//$mysql = mysql_select_db('auth');
//if (!$mysql)
//{
//echo "Cannot select the required database";
//exit;
//}
/** Query database for specific username **/
$input_username = $_POST['username'];
//$query = "SELECT * FROM auth
//WHERE
//name = '$input_username'
//";
$query = OCIParse ($conn,"SELECT * FROM USERLOGON
WHERE
USERID = '$input_username'
");
OCIExecute ($query);
//$result = mysql_query($query);
ocifetch ($query);
$result = $query;
if (!$query)
{
echo "Cannot run query";
exit;
}
else
{
/**
* Store results of query in an array from database.
**/
//$_ARRAY = mysql_fetch_array($result);
$_ARRAY = OCIFetchinto ($result);
$stored_user = $_ARRAY['USERID'];
$stored_pass = $_ARRAY['PASSWORD'];
/**
* If users password in database matches the password submitted
* allow access else just deny.
**/
if($stored_pass == $password)
{
echo "Hello $stored_user you are logged on! ";
}
else
{
echo "That account does not exist!";
}
}
}
?>
</body>
</html>