Page 1 of 1

Why doesn't this work?

Posted: Mon Mar 03, 2003 6:20 pm
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?

Posted: Mon Mar 03, 2003 6:32 pm
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");

Posted: Mon Mar 03, 2003 6:36 pm
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"]')");

Posted: Mon Mar 03, 2003 6:38 pm
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.

Posted: Mon Mar 03, 2003 6:48 pm
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!

Posted: Mon Mar 03, 2003 7:00 pm
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.