Jump to content

Recommended Posts

Hi all. I'm getting a "Query is empty" message on my index page.

 

Why, I do not know..

 

But here's the code:

 

index.php:

 

<html>
<head><title>Metal Detecting</title></head>
<?
<body onload="document.forms.test.s1.disabled = true;" oncontextmenu="return false;">
<style type="text/css">
a:hover{Color: #FFFFFF;text-decoration: none;}
a:link{Color: #FFFFFF;text-decoration: underline;}
a:visited{Color: #FF0000;text-decoration: underline;}
BODY{
Color: #FFFFFF;
}
.input {
padding-right: 1px; padding-left: 1px; padding-bottom: 1px; margin: 4px 0px 5px 8px; font: 11px/14px Arial, Helvetica, sans-serif; color: #5a698b; padding-top: 1px
}
#title {
font: bold 11px/18px Arial, Helvetica, sans-serif; text-transform: uppercase; width: 330px; color: #5a698b; padding-top: 10px; padding-bottom:10px; letter-spacing: 2px; height: 26px; text-align: center
}
#firstname{
margin 0.5em;
}
#lastname{
margin 0.5em;
}
#email{
margin 0.5em;
}
</style>
<table style="width: 1024; height: 50;" border="1" cellpadding="0" cellspacing="0"><td>
<a href="./itemsubmit.php">Submit Items</a><br/>
</td></table>
<script src="script01.js">
</script>
<?
$conn = "localhost";
$user = "myuser";
$pass = "mypass";
$dbname = "metaldetect01";
$tbl = "users0001";
$warning1 = "`warning`";
$banned1 = "`banned`";
$con = mysql_connect($conn,$user,$pass);
if (!$con)
  {
  die('Could not connect to database: "' . $dbname . '" because ' . mysql_error());
  }

mysql_select_db($dbname, $con);

$warning = ("SELECT $warning1 FROM $tbl;");
$banned = ("SELECT $banned1 FROM $tbl;");

$site_con = mysql_query($sql_site) or die(mysql_error());
$numrows = mysql_num_rows($site_con);

if($numrows > 0){
while($row = mysql_fetch_array($site_con))
{
if(isset($warning)){
echo "<Center><H1>Signups</H1></Center><br>\n";
echo "Please contact us!<br /><br />\n";
echo "*Please note you can submit the form ONLY once. Any double form submissions will be deleted.<br />\n";
echo "*You will be emailed depending on your statement whether or not you've been approved to the group!<br />\n";
echo "*You MUST speak FLUENT english<br />\n";
echo "<center><font Color=\"#00FF00\">You have been warned!</font></center>\n";
echo "Please contact us!<br /><br />\n";
echo "*Please note you can submit the form ONLY once. Any double form submissions will be deleted.<br />\n";
echo "*You MUST speak FLUENT english<br />\n";
echo "<form name=\"test\" id=\"test\" method=\"POST\" onsubmit=\"return checkdata(this), emailCheck(this.email.value), checkCheckBox(this)\" action=\"send.php\">\n";
echo "<div id = \"div01\" style=\"width: 100; height: 25;\">";
echo "  Phone/Cell number: <input name=\"requirednumber\" id=\"number\" type=\"text\" />\n";
echo "  Firstname: <input name=\"requiredfirstname\" id=\"firstname\" type=\"text\" />\n";
echo "  Lastname: <input name=\"requiredlastname\" id=\"lastname\" type=\"text\" />\n";
echo "  Email: <input name=\"requiredemail\" id=\"email\" type=\"text\" /><br /><br />\n";
echo "</div>\n";
echo "<textarea readonly=\"readonly\" name=\"license\" cols=\"40\" rows=\"15\" id=\"license\">Blah</textarea><br/>\n";
echo "<input onclick=\"this.form.s1.disabled=! this.checked;\" name=\"agree\" id=\"agree\" type=\"checkbox\"> I have read & agree to the above<br/>\n";
echo "  <input name=\"s1\" id=\"s1\" value=\"Submit\" type=\"submit\" /> <input type=\"reset\" name=\"rset\" value=\"Reset\" /><br/>\n";
echo "</form>\n";
}else if( isset($banned)){
echo "<font Color=\"#FF0000\">Sorry, but you have been banned!</font>";
}else if(! isset($warning) || isset($banned)){
echo "Please contact us!<br /><br />\n";
echo "*Please note you can submit the form ONLY once. Any double form submissions will be deleted.<br />\n";
echo "*You MUST speak FLUENT english<br />\n";
echo "<form name=\"test\" id=\"test\" method=\"POST\" onsubmit=\"return checkdata(this), emailCheck(this.email.value), checkCheckBox(this)\" action=\"send.php\">\n";
echo "<div id = \"div01\" style=\"width: 100; height: 25;\">";
echo "  Phone/Cell number: <input name=\"requirednumber\" id=\"number\" type=\"text\" />\n";
echo "  Firstname: <input name=\"requiredfirstname\" id=\"firstname\" type=\"text\" />\n";
echo "  Lastname: <input name=\"requiredlastname\" id=\"lastname\" type=\"text\" />\n";
echo "  Email: <input name=\"requiredemail\" id=\"email\" type=\"text\" /><br /><br />\n";
echo "</div>\n";
echo "<textarea readonly=\"readonly\" name=\"license\" cols=\"40\" rows=\"15\" id=\"license\">Blah</textarea><br/>\n";
echo "<input onclick=\"this.form.s1.disabled=! this.checked;\" name=\"agree\" id=\"agree\" type=\"checkbox\"> I have read & agree to the above<br/>\n";
echo "  <input name=\"s1\" id=\"s1\" value=\"Submit\" type=\"submit\" /> <input type=\"reset\" name=\"rset\" value=\"Reset\" /><br/>\n";
echo "</form>\n";
}
}
}
?>
</body>
</html>

 

Somehow, I need to read the record for warning and banned, already in the database

 

and i need to display the original website which is this part:

 

}else if(! isset($warning) || isset($banned)){
echo "Please contact us!<br /><br />\n";
echo "*Please note you can submit the form ONLY once. Any double form submissions will be deleted.<br />\n";
echo "*You MUST speak FLUENT english<br />\n";
echo "<form name=\"test\" id=\"test\" method=\"POST\" onsubmit=\"return checkdata(this), emailCheck(this.email.value), checkCheckBox(this)\" action=\"send.php\">\n";
echo "<div id = \"div01\" style=\"width: 100; height: 25;\">";
echo "  Phone/Cell number: <input name=\"requirednumber\" id=\"number\" type=\"text\" />\n";
echo "  Firstname: <input name=\"requiredfirstname\" id=\"firstname\" type=\"text\" />\n";
echo "  Lastname: <input name=\"requiredlastname\" id=\"lastname\" type=\"text\" />\n";
echo "  Email: <input name=\"requiredemail\" id=\"email\" type=\"text\" /><br /><br />\n";
echo "</div>\n";
echo "<textarea readonly=\"readonly\" name=\"license\" cols=\"40\" rows=\"15\" id=\"license\">Blah</textarea><br/>\n";
echo "<input onclick=\"this.form.s1.disabled=! this.checked;\" name=\"agree\" id=\"agree\" type=\"checkbox\"> I have read & agree to the above<br/>\n";
echo "  <input name=\"s1\" id=\"s1\" value=\"Submit\" type=\"submit\" /> <input type=\"reset\" name=\"rset\" value=\"Reset\" /><br/>\n";
echo "</form>\n";
}

 

i need it to read the original website code whether or not warning AND / OR banned is 0 OR 1.

 

the part that needs to be fixed, is this:

 

<?
$conn = "localhost";
$user = "myuser";
$pass = "mypass";
$dbname = "metaldetect01";
$tbl = "users0001";
$warning1 = "`warning`";
$banned1 = "`banned`";
$con = mysql_connect($conn,$user,$pass);
if (!$con)
  {
  die('Could not connect to database: "' . $dbname . '" because ' . mysql_error());
  }

mysql_select_db($dbname, $con);

$warning = ("SELECT $warning1 FROM $tbl;");
$banned = ("SELECT $banned1 FROM $tbl;");

$site_con = mysql_query($sql_site) or die(mysql_error());
$numrows = mysql_num_rows($site_con);

if($numrows > 0){
while($row = mysql_fetch_array($site_con))
{

 

as i said before though, this is the part that is causing "Query is empty" error.

 

ANY help is GREATLY appreciated! :)

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

ok, now im getting:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 55.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 56.

 

code:

 

<?
$conn = "localhost";
$user = "root";
$pass = "Gen0sis";
$dbname = "metaldetect01";
$tbl = "users0001";
$warning1 = "`warning`";
$banned1 = "`banned`";
$con = mysql_connect($conn,$user,$pass);
if (!$con)
  {
  die('Could not connect to database: "' . $dbname . '" because ' . mysql_error());
  }

mysql_select_db($dbname, $con);

$warning = ("SELECT $warning1 FROM $tbl;");
$banned = ("SELECT $banned1 FROM $tbl;");
$site1_con = mysql_query($warning) or die(mysql_error());
$site2_con = mysql_query($banned) or die(mysql_error());
$numrows1 = mysql_num_rows($warning);
$numrows2 = mysql_num_rows($banned);

if($numrows1 > 0 || $numrows2 > 0){
while($row = mysql_fetch_array($site_con))
{

$warning = ("SELECT $warning1 FROM $tbl;");
$banned = ("SELECT $banned1 FROM $tbl;");
$site1_con = mysql_query($warning) or die(mysql_error());
$site2_con = mysql_query($banned) or die(mysql_error());
$numrows1 = mysql_num_rows($warning);
$numrows2 = mysql_num_rows($banned);

 

$warning and $banned aren't queries to count the number of rows if you look at it closely.

 

Change it to this:

 

$warning = ("SELECT $warning1 FROM $tbl;");
$banned = ("SELECT $banned1 FROM $tbl;");
$site1_con = mysql_query($warning) or die(mysql_error());
$site2_con = mysql_query($banned) or die(mysql_error());
$numrows1 = mysql_num_rows($site1_con);
$numrows2 = mysql_num_rows($site2_con);

Ok, now it sorta works. BUT i cant seem to return a "1" OR "0" for $warning and $banned.

 

code:

 

<?
$conn = "localhost";
$user = "root";
$pass = "Gen0sis";
$dbname = "metaldetect01";
$tbl = "users0001";
$warning1 = "`warning`";
$banned1 = "`banned`";
$con = mysql_connect($conn,$user,$pass);
if (!$con)
  {
  die('Could not connect to database: "' . $dbname . '" because ' . mysql_error());
  }

mysql_select_db($dbname, $con);

$sql = ("SELECT $warning1 AND $banned1 FROM $tbl;");
$site_con = mysql_query($sql) or die(mysql_error());
$warning = $site_con
$banned = $site_con
$numrows = mysql_num_rows($site_con);

if($numrows > 0){
while($row = mysql_fetch_array($site_con))
{
if($warning > 0){

$sql = ("SELECT $warning1 AND $banned1 FROM $tbl;");
$site_con = mysql_query($sql) or die(mysql_error());
$warning = $site_con
$banned = $site_con
$numrows = mysql_num_rows($site_con);

 

Is not the same as your original

 

$warning = ("SELECT $warning1 FROM $tbl;");
$banned = ("SELECT $banned1 FROM $tbl;");
$site1_con = mysql_query($warning) or die(mysql_error());
$site2_con = mysql_query($banned) or die(mysql_error());
$numrows1 = mysql_num_rows($site1_con);
$numrows2 = mysql_num_rows($site2_con);

 

What's going on here?

 

Also, you can't retrieve just "1" or "0" from queries.. unless it's an UPDATE, or DELETE, or INSERT (where it returns true on success or false on failure). I suggest having a look here:

 

http://us2.php.net/manual/en/function.mysql-query.php

i decided to change back to what i had before.

 

but NONE of these debug variables return 1 or 0.

 

code:

 

<?
$conn = "localhost";
$user = "root";
$pass = "Gen0sis";
$dbname = "metaldetect01";
$tbl = "users0001";
$warning1 = "`warning`";
$banned1 = "`banned`";
$con = mysql_connect($conn,$user,$pass);
if (!$con)
  {
  die('Could not connect to database: "' . $dbname . '" because ' . mysql_error());
  }

mysql_select_db($dbname, $con);

$warning = ("SELECT $warning1 FROM $tbl;");
$banned = ("SELECT $banned1 FROM $tbl;");
$site1_con = mysql_query($warning) or die(mysql_error());
$site2_con = mysql_query($banned) or die(mysql_error());
$numrows1 = mysql_num_rows($warning);
$numrows2 = mysql_num_rows($banned);

echo "warning:".$warning."<br>\n";
echo "banned:".$banned."<br>\n";
echo "site1_con:".$site1_con."<br>\n";
echo "site2_con:".$site2_con."<br>\n";
echo "numrows1:".$numrows1."<br>\n";
echo "numrows2:".$numrows2."<br>\n";
if($numrows1 > 0 || $numrows2 > 0){
while($numrows1 = mysql_fetch_array($site1_con) && $numrows2 = mysql_fetch_array($site2_con))
{
if(isset($warning)){

 

it returns:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\myxampp\htdocs\detect\index.php on line 55

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\myxampp\htdocs\detect\index.php on line 56
warning:SELECT `warning` FROM users0001;
banned:SELECT `banned` FROM users0001;
site1_con:Resource id #3
site2_con:Resource id #4
numrows1:
numrows2:

$warning = ("SELECT $warning1 FROM $tbl;");
$banned = ("SELECT $banned1 FROM $tbl;");
$site1_con = mysql_query($warning) or die(mysql_error());
$site2_con = mysql_query($banned) or die(mysql_error());
$numrows1 = mysql_num_rows($warning);
$numrows2 = mysql_num_rows($banned);

 

$warning and $banned aren't queries to count the number of rows if you look at it closely.

 

Change it to this:

 

$warning = ("SELECT $warning1 FROM $tbl;");
$banned = ("SELECT $banned1 FROM $tbl;");
$site1_con = mysql_query($warning) or die(mysql_error());
$site2_con = mysql_query($banned) or die(mysql_error());
$numrows1 = mysql_num_rows($site1_con);
$numrows2 = mysql_num_rows($site2_con);

 

Again, fix by using the second code instead of the first before we talk about debugging >.<

a bunch of things.

 

$numrows1 = mysql_num_rows($warning);
$numrows2 = mysql_num_rows($banned);

 

neither of those variables are mysql resources. If you notice, when you echo $site_con1 and 2, they say mysql resource. You have to use those in the numrows functions, like

 

$numrows1 = mysql_num_rows($site1_con);
$numrows2 = mysql_num_rows($site2_con);

 

thats whats causing these errors


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:myxampphtdocsdetectindex.php on line 55

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:myxampphtdocsdetectindex.php on line 56

 

second, again, mysql_query only returns a mysql resource. You have to use other mysql functions to get the data out of those resources. If you want the information, you have to use mysql_fetch_array or mysql_fetch_assoc. you can also trim your queries down to 1. Try something like

 


$query = "SELECT $warning1, $banned1 FROM $tbl";

$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);

echo "$rows rows returned!<br />";
//now lets go through every row returned.
while($row = mysql_fetch_assoc($result)){
$warning = $row[$warning1];
$banned = $row[$banned1];

echo "Warning: $warning<br />";
echo "Banned: $banned<br />";
}

 

try that and see what happens

ok, ok.. i fixed it.

 

<?
$conn = "localhost";
$user = "root";
$pass = "Gen0sis";
$dbname = "metaldetect01";
$tbl = "users0001";
$warning1 = "`warning`";
$banned1 = "`banned`";
$con = mysql_connect($conn,$user,$pass);
if (!$con)
  {
  die('Could not connect to database: "' . $dbname . '" because ' . mysql_error());
  }

mysql_select_db($dbname, $con);

$warning = ("SELECT $warning1 FROM $tbl;");
$banned = ("SELECT $banned1 FROM $tbl;");
$site1_con = mysql_query($warning) or die(mysql_error());
$site2_con = mysql_query($banned) or die(mysql_error());
$numrows1 = mysql_num_rows($site1_con);
$numrows2 = mysql_num_rows($site2_con);

echo "warning:".$warning."<br>\n";
echo "banned:".$banned."<br>\n";
echo "site1_con:".$site1_con."<br>\n";
echo "site2_con:".$site2_con."<br>\n";
echo "numrows1:".$numrows1."<br>\n";
echo "numrows2:".$numrows2."<br>\n";
if($numrows1 > 0 || $numrows2 > 0){
while($numrows1 = mysql_fetch_array($site1_con) && $numrows2 = mysql_fetch_array($site2_con))
{
if(isset($warning)){

second, again, mysql_query only returns a mysql resource. You have to use other mysql functions to get the data out of those resources. If you want the information, you have to use mysql_fetch_array or mysql_fetch_assoc. you can also trim your queries down to 1. Try something like

 

This is completely untrue. http://us.php.net/manual/en/function.mysql-query.php

From php.net

 

Return Values

 

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

 

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

 

The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.

 

Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.

 

mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.

 

1 and 0 are true/false.

0 rows returned!

 

code:

 

<?
$conn = "localhost";
$user = "root";
$pass = "Gen0sis";
$dbname = "metaldetect01";
$tbl = "users0001";
$warning1 = "`warning`";
$banned1 = "`banned`";

$con = mysql_connect($conn,$user,$pass);
if (!$con)
  {
  die('Could not connect to database: "' . $dbname . '" because ' . mysql_error());
  }

mysql_select_db($dbname, $con);

$query = "SELECT $warning1, $banned1 FROM $tbl";

$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);

$query = "SELECT $warning1, $banned1 FROM $tbl";

echo "$rows rows returned!<br />";
//now lets go through every row returned.
while($row = mysql_fetch_assoc($result)){
$warning = $row[$warning1];
$banned = $row[$banned1];

echo "Warning: $warning<br />";
echo "Banned: $banned<br />";

if(isset($warning)){

...

 

Return Values

 

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

 

The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.

 

 

mysql query will return 0 when it fails any time (because of an error, an invalid connection, etc.) . it returns 1 when it preforms inserts, deletes, etc. (as specified on the quote) successfully.

 

However, in this case, he wants a 0 or 1 from his database, not from the query itself. the 0 or 1 from the query are only useful during debugging, as it tells whether or not the query you did was successful or not. However, as far as the data from the actual table the query is accessing goes, the returned value is rather useless unless you use one of the functions for use with the result tables.

 

 

But yes, I suppose I should have explained myself better.

 

When the query is SUCCESSFUL, mysql_query only returns a mysql_resource

 

0 rows returned!

 

code:

 

<?
$conn = "localhost";
$user = "root";
$pass = "Gen0sis";
$dbname = "metaldetect01";
$tbl = "users0001";
$warning1 = "`warning`";
$banned1 = "`banned`";

$con = mysql_connect($conn,$user,$pass);
if (!$con)
  {
  die('Could not connect to database: "' . $dbname . '" because ' . mysql_error());
  }

mysql_select_db($dbname, $con);

$query = "SELECT $warning1, $banned1 FROM $tbl";

$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);

$query = "SELECT $warning1, $banned1 FROM $tbl";

echo "$rows rows returned!<br />";
//now lets go through every row returned.
while($row = mysql_fetch_assoc($result)){
$warning = $row[$warning1];
$banned = $row[$banned1];

echo "Warning: $warning<br />";
echo "Banned: $banned<br />";

if(isset($warning)){

 

try

$query = "SELECT * FROM $tbl";

 

if it still returns 0 rows, then your table is empty, or you are using the wrong table name

it still returns 0..

 

but i have the database filled..

 

Field Type Collation Attributes Null Default Extra Action 
  id int(11)   No None auto_increment               
  number varchar(16) latin1_swedish_ci  No                 
  Firstname varchar(32) latin1_swedish_ci  No                 
  Lastname varchar(32) latin1_swedish_ci  No                 
  email varchar(50) latin1_swedish_ci  No                 
  statement varchar(255) latin1_swedish_ci  No                 
  warning varchar(1) latin1_swedish_ci  No 0                
  banned varchar(1) latin1_swedish_ci  No 0

Guest
This topic is now closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.