Already recommended a couple.TheHappyPeanut wrote:Any books you'd recommend?
Code Issue
Moderator: General Moderators
Re: Code Issue
-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
I completely forgot about that. Thanks for the reminder. There is one line of code giving me an error and that's the $result. I've Googled it and tried a fix, but it didn't seem to work, so I removed it. Here's the error I receive with that bit of code you gave me. Is it something I simply need to change?
Line 10:
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();Re: Code Issue
Undo the method chaining.
Code: Select all
$result = $mysqli->query($query);
$user = $result->fetch_assoc();-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
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');
}
?>Re: Code Issue
That means the query is returning false and is therefore no good.
EDIT: Remove the quotes around the table name.
EDIT: Remove the quotes around the table name.
-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
Heh... full of issues today, it seems.
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');
}
?>Re: Code Issue
Not around the query string, around the table name.
Code: Select all
$query = "SELECT id, password FROM tracker WHERE username='$username'";-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
Still has the issue. 
and here's my code:
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');
}
?>Re: Code Issue
What happens when you run the query manually?
-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
I'm not really sure how to run a manual query in phpMyAdmin... I've never done it before :/
Re: Code Issue
Log in, choose your database on the left, click the SQL tab at the top, write your query. You could also just do it from the console.
-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
[text]#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$query = "SELECT id, password FROM tracker WHERE username='$username'"' at line 1[/text]
Re: Code Issue
No, you can't paste PHP code into MySQL.
Code: Select all
SELECT id, password FROM tracker WHERE username = 'replace_this_with_username'-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
I fixed it. I was using "trackers" when I should have been using "users". Thanks for the help with that. Also, what exactly does this query do?
-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
Sent you a PM by the way.