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
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sat Mar 20, 2004 10:44 am
im trying to get some info from a database and i keep getting this error
Code: Select all
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/krunk/public_html/gtthing/gtthing3.php on line 25
Username:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/krunk/public_html/gtthing/gtthing3.php on line 29
Percentage:
this is the code that im using
Code: Select all
<?php
$db = mysql_connect("localhost", "database", "password");
mysql_select_db("database",$db);
$result = mysql_query("SELECT * FROM stats",$db);
printf("Username: %s<br>\n", mysql_result($result,"username"));
printf("Percentage: %s<br>\n", mysql_result($result,"percent"));
?>
line 25 is
Code: Select all
printf("Username: %s<br>\n", mysql_result($result,"username"));
and line 29 is
Code: Select all
printf("Percentage: %s<br>\n", mysql_result($result,"percent"));
?>
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Sat Mar 20, 2004 11:01 am
mysql_result()
Your using the function wrong. You need a row number, try
mysql_result($result,0,"username")
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sat Mar 20, 2004 11:16 am
same error even with the row number
coreycollins
Forum Commoner
Posts: 67 Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan
Post
by coreycollins » Sat Mar 20, 2004 11:20 am
This may sound pretty basic but if you run the Select statement as a MySql query itself does it work?
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sat Mar 20, 2004 11:25 am
wut do you mean?
like this?
Code: Select all
$result = mysql_query("SELECT * FROM stats");
coreycollins
Forum Commoner
Posts: 67 Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan
Post
by coreycollins » Sat Mar 20, 2004 11:27 am
Do you know how to run a MySQL query in MySQL itself, either with the MySql control center or at the shell level?
I'm thinking maybe you don't have a stats table or something to that matter.
coreycollins
Forum Commoner
Posts: 67 Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan
Post
by coreycollins » Sat Mar 20, 2004 11:33 am
I just ran your modified script from Illusionist's suggestion and it appears to work fine.
You have a problem with your MySQL database. Some things to look at are:are you giving the correct database name on the line
and does the sites table exist?
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sat Mar 20, 2004 11:46 am
im using this code to send info to the database
Code: Select all
<html>
<head>
</head>
<body>
<?php
if ($submit) {
// process form
$db = mysql_connect("localhost", "krunk_gtstat", "password");
mysql_select_db("krunk_gtstat",$db);
$sql = "INSERT INTO stats (username,percent) VALUES ('$username','$percent')";
$result = mysql_query($sql);
} else{
// display form
} // end if
?>
<form method="GET" action="gtthing.php">
<font size=1 face="verdana" color=#000000>
Username:<br>
<input type"text" name="username" size="20" style="font-family: Arial; font-size: 8pt; color: #000000"><br>
Games Won<br>
<input type"text" name="value1" size="20" style="font-family: Arial; font-size: 8pt; color: #000000"><br>
Games lost by someone reaching 100 mojo<br>
<input type"text" name="value2" size="20" style="font-family: Arial; font-size: 8pt; color: #000000"><br>
Games lost by zero<br>
<input type"text" name="value3" size="20" style="font-family: Arial; font-size: 8pt; color: #000000"><br>
Games played<br>
<input type"text" name="value4" size="20" style="font-family: Arial; font-size: 8pt; color: #000000"><br>
<input type="reset" value="Reset Form" name="reset" style="font-family: verdana; font-size: 8pt; color: #000000">
<input type="submit" value="Submit" name="send" style="font-family: verdana; font-size: 8pt; color: #000000">
</font>
</body>
</html>
it might be that its not sending the info and my database is empty so the error comes up
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sat Mar 20, 2004 11:50 am
and this is the file with the code to get the values and username and percent
Code: Select all
<?php
$value1=$_GETї'value1'];
$value2=$_GETї'value2'];
$value3=$_GETї'value3'];
$value4=$_GETї'value4'];
$username=$_GETї'username'];
$total=(($value1 + $value2 + $value3) / $value4);
$percent=$total * 10;
echo "<font face=verdana size=2 color=red>{$_GETї'username']}</font><br>";
echo "<font face=verdana size=2>Games Won </font><br>";
echo "<font face=verdana size=2 color=red>{$_GETї'value1']}</font><br>";
echo "<font face=verdana size=2>Games lost by someone reaching 100 mojo</font> <br>";
echo "<font face=verdana size=2 color=red>{$_GETї'value2']}</font><br>";
echo "<font face=verdana size=2>Games lost by zero </font> <br>";
echo "<font face=verdana size=2 color=red>{$_GETї'value3']}</font><br>";
echo "<font face=verdana size=2>Games Played</font> <br>";
echo "<font face=verdana size=2 color=red>{$_GETї'value4']}</font><br>";
echo "<font face=verdana size=2>Percent of the time you/someone quit </font><br>";
echo "<font face=verdana size=2 color=red>{$percent}%</font>";
?>
coreycollins
Forum Commoner
Posts: 67 Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan
Post
by coreycollins » Sat Mar 20, 2004 1:04 pm
I saw that you said you have phpmyadmin. Run this in the Query window and tell me what you get:
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sat Mar 20, 2004 2:24 pm
Code: Select all
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/krunk/public_html/gtthing/gtthing3.php on line 25
Username:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/krunk/public_html/gtthing/gtthing3.php on line 29
Percentage:
same thing happens
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Mar 20, 2004 2:33 pm
Try this version, it should at least tell you what's wrong.
Code: Select all
<?php
$db = mysql_connect('localhost', 'database', 'password') or die(mysql_error());
mysql_select_db('database') or die(mysql_error());
$sql = "SELECT * FROM stats";
$result = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($result)){
$row = mysql_fetch_assoc($result);
echo 'Username: '.$row['username']."<br>\n";
echo 'Percentage: '.$row['percent']."<br>\n";
}
?>
coreycollins
Forum Commoner
Posts: 67 Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan
Post
by coreycollins » Sat Mar 20, 2004 3:24 pm
You shouldn't get the same thing if you run what i said in the Phpmyadmin query window. The phpmyadmin query window is totally seperate from your page. If it is set up correctly you should get all the results in the table.
In the mean time, I agree with mark. Try what he has set up and tell us what you get.
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sat Mar 20, 2004 3:40 pm
i got this when i did marks code
Code: Select all
Table 'krunk_gtstat.stats' doesn't exist
but the table does exist, and both username and percent exist
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Mar 20, 2004 3:44 pm
Check the case of it too, eg make sure it's krunk_gstat and stats and not something like Krunk_Gstat, Stats etc..