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!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Fatal error: Call to a member function query() on a non-object in ........ /pa_home.php on line 59
why do i keep getting the above error when i try to connect to a database using a "self executable" script and sessions?
Pleeeeeeeeeeeassssseeeeeeee heeeeeelpppppppppp meeeeeeee!!!!!!! im going insane and i WILL fail my university project if i don't get this sorted out soon!
<?php //common.php
function db_connect()
{
$result = new mysqli('www.nl-webspace.co.uk', 'unn_p921847', 'password');
if (!$result)
throw new Exception('Could not connect to database server');
else
return $result;
}
<?php //logon page
//Initiates php script containing functions all common functions
require_once('common.php');
$dbconn = db_connect();
session_start();
//outputs header info to brower with the following title
echo xhtmlheader('Personal Account Registration Form');
//outputs the main navigation bar to the browser
echo topnav_pa();
if (isset($_POST['email']) && isset ($_POST['pwd']))
{
//if the user has just tried to log in
$email = $_POST['email'];
$pwd = $_POST['pwd'];
//$db_conn = new mysqli('localhost', 'webauth', 'webauth', 'auth');
$sql = 'select * from Authourised_User'
."where userEmail='$email'"
." and userPassword='$pwd';";
$result = $dbconn->query($sql);
if ($result->num_rows >0)
{
$_SESSION['valid_user'] = $email;
}
$dbconn->close;
}
?>
<!-- main body of page -->
<div id="main">
<h1>My Pub Crawl Planner</h1>
<?php
if (isset($_SESSION['valid_user']))
{
echo 'You are logged in as: '.$_SESSION['valid_user'].' <br />';
echo '<a href="logout.php">Log out</a><br />';
}
else
{
if (isset($email))
{
// if they've tried and failed to log in
echo 'Could not log you in.<br />';
}
else
{
// they have not tried to log in yet or have logged out
echo 'You are not logged in.<br />';
}
}
?>
<p>Member Login </p>
<form action="index.php<?php echo strip_tags(SID); ?>" method="post" class="login">
<table>
<tr>
<td>E-mail:</td>
<td class="table"> <input type="text"
name="email"
value=""
tabindex="1"/></td>
</tr>
<tr>
<td>Password:</td>
<td class="table"> <input type="text"
name="pwd"
value=""
tabindex="2"/></td>
</tr>
</table>
<!-- submit button -->
<input type="submit"
name="login"
value="Login"
tabindex="7"/>
</form>
<br/>
<br/>
<
</div>
</body>
</html>
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
the previous error was actually for another db_connect() function that i tried:
Warning: mysql_query() [function.mysql-query]: Access denied for user 'apache'@'localhost' (using password: NO) in /.........../pa_home.php on line 38
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /........../pa_home.php on line 38
2047
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
thanks for replying, volka.
i now get the following error regardless of what's in the login form when i submit it (i think there may be something wrong with the session which i'm trying to forward in the url):
Notice: Trying to get property of non-object in /home/unn_p921847/public_html/index.php on line 24
<?php
//Initiates php script containing functions all common functions
session_start();
require_once('common.php');
$dbconnect = db_connect();
//outputs header info to brower with the following title
echo xhtmlheader('Personal Account Registration Form');
//outputs the main navigation bar to the browser
echo topnav_pa();
if (isset($_POST['email']) && isset ($_POST['pwd']))
{
//if the user has just tried to log in
$email = $_POST['email'];
$pwd = $_POST['pwd'];
$sql = "select * from Authourised_User where userEmail='$email' and userPassword='$pwd'";
$result=$dbconnect->query($sql); /*****line 24 *****/
if ($result->num_rows >0 )
{
$_SESSION['valid_user'] = $email;
}
$dbconnect->close();
}
?>
<!-- main body of page -->
<div id="main">
<h1>My Pub Crawl Planner</h1>
<?php
if (isset($_SESSION['valid_user']))
{
echo 'You are logged in as: '.$_SESSION['valid_user'].' <br />';
echo '<a href="logout.php">Log out</a><br />';
}
else
{
if (isset($email))
{
// if they've tried and failed to log in
echo 'Could not log you in.<br />';
}
else
{
// they have not tried to log in yet or have logged out
echo 'You are not logged in.<br />';
}
}
?>
<p>Member Login </p>
<form action="index.php" method="post" class="login"> /****form action *****/
<table>
<tr>
<td>E-mail:</td>
<td class="table"> <input type="text"
name="email"
value=""
tabindex="1"/></td>
</tr>
<tr>
<td>Password:</td>
<td class="table"> <input type="text"
name="pwd"
value=""
tabindex="2"/></td>
</tr>
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
thanks for replying, volka.
i now get the following error regardless of what's in the login form when i submit it (i think there may be something wrong with the session which i'm trying to forward in the url):
Notice: Trying to get property of non-object in /home/unn_p921847/public_html/index.php on line 24
<?php
//Initiates php script containing functions all common functions
session_start();
require_once('common.php');
$dbconnect = db_connect();
//outputs header info to brower with the following title
echo xhtmlheader('Personal Account Registration Form');
//outputs the main navigation bar to the browser
echo topnav_pa();
if (isset($_POST['email']) && isset ($_POST['pwd']))
{
//if the user has just tried to log in
$email = $_POST['email'];
$pwd = $_POST['pwd'];
$sql = "select * from Authourised_User where userEmail='$email' and userPassword='$pwd'";
$result=$dbconnect->query($sql); /*****line 24 *****/
if ($result->num_rows >0 )
{
$_SESSION['valid_user'] = $email;
}
$dbconnect->close();
}
?>
<!-- main body of page -->
<div id="main">
<h1>My Pub Crawl Planner</h1>
<?php
if (isset($_SESSION['valid_user']))
{
echo 'You are logged in as: '.$_SESSION['valid_user'].' <br />';
echo '<a href="logout.php">Log out</a><br />';
}
else
{
if (isset($email))
{
// if they've tried and failed to log in
echo 'Could not log you in.<br />';
}
else
{
// they have not tried to log in yet or have logged out
echo 'You are not logged in.<br />';
}
}
?>
<p>Member Login </p>
<form action="index.php" method="post" class="login"> /****form action *****/
<table>
<tr>
<td>E-mail:</td>
<td class="table"> <input type="text"
name="email"
value=""
tabindex="1"/></td>
</tr>
<tr>
<td>Password:</td>
<td class="table"> <input type="text"
name="pwd"
value=""
tabindex="2"/></td>
</tr>
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
[url=http://forums.devnetwork.net/faq.php?mode=bbcode]bbcode tags[/url][/b].[/quote]
and please post the current code of your function db_connect(), too.
garry27, I've had to edit every single one of your posts. Please do not make me, or any other moderator, have to do that by starting to use the highlighting tags as volka has so kindly asked.
function db_connect()
{
$result = new mysqli('www.nl-webspace.co.uk', 'unn_p921847', 'password');
if (!$result)
throw new Exception('Could not connect to database server');
else
return $result;
}
<?php
//Initiates php script containing functions all common functions
session_start();
require_once('common.php');
$dbconnect = db_connect();
//outputs header info to brower with the following title
echo xhtmlheader('Personal Account Registration Form');
//outputs the main navigation bar to the browser
echo topnav_pa();
if (isset($_POST['email']) && isset ($_POST['pwd']))
{
//if the user has just tried to log in
$email = $_POST['email'];
$pwd = $_POST['pwd'];
$sql = "select * from Authourised_User where userEmail='$email' and userPassword='$pwd'";
if (!is_object($dbconnect)) {
die ('dbconnect is not an object. '.var_dump($dbconnect));
}
$result=$dbconnect->query($sql);
if ( false===$result) {
die($dbconnect->error . ': '.$sql);
}
if ( $result->num_rows > 0 )
{
$_SESSION['valid_user'] = $email;
}
$dbconnect->close();
}
?>
...
doesn't return a valid mysql result resource. It returns false if the query fails, i.e. no database connection or permission denied or syntax errors in sql statement.
doesn't the "new"
$result=$dbconnect->query($sql);
if ( false===$result) {
die($dbconnect->error . ': '.$sql);
}