Re: Code Issue
Posted: Fri Apr 13, 2012 12:34 pm
Already recommended a couple.TheHappyPeanut wrote:Any books you'd recommend?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Already recommended a couple.TheHappyPeanut wrote:Any books you'd recommend?
Code: Select all
Fatal error: Call to a member function fetch_assoc() on a non-object in C:\xampp\htdocs\Tracker\login.php on line 10Code: Select all
$result = $mysqli->query($query)->fetch_assoc();Code: Select all
$result = $mysqli->query($query);
$user = $result->fetch_assoc();The good news is that line 10 no longer has that issue. The bad news is that now line 11 has it.Celauran wrote:Undo the method chaining.
Code: Select all
$result = $mysqli->query($query); $user = $result->fetch_assoc();
Code: Select all
<?php
if (!empty($_POST))
{
if (isset($_POST['username']) && isset($_POST['password']))
{
$mysqli = new mysqli('localhost', 'root', '', 'tracker');
$username = $mysqli->real_escape_string($_POST['username']);
$query = "SELECT id, password FROM 'tracker' WHERE username='$username'";
$result = $mysqli->query($query);
$user = $result->fetch_assoc();
}
else
die('Unable to proceed');
}
?>Code: Select all
Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\Tracker\login.php on line 9Code: Select all
<?php
if (!empty($_POST))
{
if (isset($_POST['username']) && isset($_POST['password']))
{
$mysqli = new mysqli('localhost', 'root', '', 'tracker');
$username = $mysqli->real_escape_string($_POST['username']);
$query = SELECT id, password FROM 'tracker' WHERE username='$username';
$result = $mysqli->query($query);
$user = $result->fetch_assoc();
}
else
die('Unable to proceed');
}
?>Code: Select all
$query = "SELECT id, password FROM tracker WHERE username='$username'";Code: Select all
Fatal error: Call to a member function fetch_assoc() on a non-object in C:\xampp\htdocs\Tracker\login.php on line 11Code: Select all
<?php
if (!empty($_POST))
{
if (isset($_POST['username']) && isset($_POST['password']))
{
$mysqli = new mysqli('localhost', 'root', '', 'tracker');
$username = $mysqli->real_escape_string($_POST['username']);
$query = "SELECT id, password FROM tracker WHERE username='$username'";
$result = $mysqli->query($query);
$user = $result->fetch_assoc();
}
else
die('Unable to proceed');
}
?>Code: Select all
SELECT id, password FROM tracker WHERE username = 'replace_this_with_username'