Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

PHP/MySQL Problem (solved)

Started by hereticprophecy 1 reply 1k views
Original Post
hereticprophecy
hereticprophecy
Below are several snippets of code related to my current web project. I'm building the user's login panel, which will display some pertinent info, as well as their rankings in ladders throughout the site. However, I've hit a pothole: the queries I'm making are resulting in empty rows...it's returning all default values for the fields but not the data I've created inside. I created the entries with phpMyAdmin, which shows them as correct and right as rain. Display page code:

<?php
	include("_mysql.php");
	include("functions/userpanel.php");

	$userID = 1;
	
	$stat = getStats($userID);
	
	echo "Statistics for" . $stat['name'] . ":";
	echo '<ul>';
	echo '<li>' . "Level = " . $stat['level'] . '</li>';
	echo '<li>' . "Experience = " . $stat['experience'] . "/" . $stat['to_level'] . '</li>';
	echo '<li>' . "Tournament Wins = " . $stat['tourneyW'] . '</li>';
	echo '<li>' . "Tournament Losses = " . $stat['tourneyL'] . '</li>';
	echo '</ul>';
	
?>

getStats() Function:

        function getStats($userID) {
		
		//Connect to and select database
		$dbh=mysql_connect ("localhost", "supafly2_myarcad", "base2088") or die ('I cannot connect to the database because: ' . mysql_error());
		
		mysql_select_db ("supafly2_ultima");
		
		//Get information for pertinent tables
		$user = mysql_query("SELECT * FROM 'user' WHERE 'userID' = $userID");
		
		$result['name'] = $user['displayName'];
		
		//Store current level and experience to next level
		require_once("level.php");
		
		$result['level'] = getLevel($user['experience']);
		$result['experience'] = truncateExperience($user['experience']);
		$result['to_level'] = toLevel($result['level']);
		
		//Store tourneys won and tourneys lost
		$result['tourneyW'] = $user['tourneyWins'];
		$result['tourneyL'] = $user['tourneyLosses'];
		
		//Search all ladders for user records, store results
		$result['records'] = searchLadders($userID);
		
		//Store results of last match played  TODO
		
		//Store next scheduled match  TODO
		
		return $result;
						
	}

Is this an error in my syntax? Might my database be configured incorrectly? I'm at a loss, so any help would be appreciated. [Edited by - hereticprophecy on April 14, 2007 2:40:54 AM]
Colin Jeanne
Colin Jeanne
Your SQL syntax is incorrect. Dont quote table names as you do in

SELECT * FROM 'user' WHERE 'userID' = $userID

This is the correct syntax:

SELECT * FROM user WHERE 'userID' = $userID
hereticprophecy
hereticprophecy
As I found out, the syntax error was in that spot: however, the proper syntax was:

SELECT * FROM user WHERE userID = $userID

No quotes were needed anywhere.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.