Why doesn't this work?

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!

Moderator: General Moderators

Post Reply
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Why doesn't this work?

Post by nigma »

Code: Select all

<html>

<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>

<?php

	$csname = $_GET&#1111;"memName"];

	$db = mysql_connect("localhost", "chris");
	mysql_select_db("mc0",$db);
	$result = mysql_query("Select * from users where (csName = '$csname')");
	
	printf("First  Name: %s<br>\n", mysql_result($result,0,"fName"));
	printf("Last   Name: %s<br>\n", mysql_result($result,0,"lName"));
	printf("CSName Name: %s<br>\n", mysql_result($result,0,"CSName"));
	printf("Favorite weapon: %s<br>\n", mysql_result($result,0,"gun"));
	printf("Current Rank: %s<br>\n", mysql_result($result,0,"rank"));
	printf("Curent OS: %s<br>\n", mysql_result($result,0,"os"));

?>

</body>
</html>
All I get is a page that says:

First Name:
Last Name:
CSName:
Favorite Weapon:
etc.

But non of the variables.

Can someone please assist me with this one?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Is msql_result() a user-defined function? If so, you forgot to include the file where it's defined, ie:

include("path_to_file/filename.php");
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

I dont know enough about this to know if it is or isn't a user-defined function. I just got this stuff off a basic tutorial. They never said if it was or wasn't a user-defined func. But I found out the problem is with the var $csname. See when I replace the spot that would contain $csname with a value I know exists in the mysql table it works fine but when I use $csname it doesn't work.

So basically I need help with this line:
$result = mysql_query("Select * from users where (CSName = '$_GET["mName"]')");
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Hey! Got it to work. It was just a matter of me having this wrong:

$csname = $_GET["memName"];

It was mName not memName.

Thanks so much for the help.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

A user-defined function is just something you defined yourself like

function myFunction($argument1, $argument2) {
.............
.............
}

I've just realised that mysql_result() is a native php function though - duh!
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Lol, I cant belive I didn't know what a user-defined function is, probably just didn't think bout it. I use functions ( besides printf() and stuff ) when I am messin with Perl or C.
Post Reply