Page 1 of 5
MySQL Error
Posted: Sat Mar 20, 2004 10:44 am
by bawla
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"));
?>
Posted: Sat Mar 20, 2004 11:01 am
by Illusionist
mysql_result()
Your using the function wrong. You need a row number, try
mysql_result($result,0,"username")
Posted: Sat Mar 20, 2004 11:16 am
by bawla
same error even with the row number
Posted: Sat Mar 20, 2004 11:20 am
by coreycollins
This may sound pretty basic but if you run the Select statement as a MySql query itself does it work?
Posted: Sat Mar 20, 2004 11:25 am
by bawla
wut do you mean?
like this?
Code: Select all
$result = mysql_query("SELECT * FROM stats");
Posted: Sat Mar 20, 2004 11:27 am
by coreycollins
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.
Posted: Sat Mar 20, 2004 11:33 am
by coreycollins
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?
Posted: Sat Mar 20, 2004 11:46 am
by bawla
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
Posted: Sat Mar 20, 2004 11:50 am
by bawla
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>";
?>
Posted: Sat Mar 20, 2004 1:04 pm
by coreycollins
I saw that you said you have phpmyadmin. Run this in the Query window and tell me what you get:
Posted: Sat Mar 20, 2004 2:24 pm
by bawla
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
Posted: Sat Mar 20, 2004 2:33 pm
by markl999
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";
}
?>
Posted: Sat Mar 20, 2004 3:24 pm
by coreycollins
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.
Posted: Sat Mar 20, 2004 3:40 pm
by bawla
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
Posted: Sat Mar 20, 2004 3:44 pm
by markl999
Check the case of it too, eg make sure it's krunk_gstat and stats and not something like Krunk_Gstat, Stats etc..