473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Error: Not a valid sql result

I am trying to populate a dropdown, but cannot get the sql to return what I want. Can someone please help me with this error that I am getting in case 1? I am not using case 2 or the default case yet.

"<br />
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/home/user21/public_html/mp3/enterjob_2.php</b> on line <b>23</b><br />
<br />
<b>Notice</b>: Undefined variable: temp in <b>/home/user21/public_html/mp3/enterjob_2.php</b> on line <b>26</b><br />

"
Ultimately, I want to use the results to populate a dropdown, and am trying to get the data in a format that I can use in javascript, but keep getting the error. I am trying to make a name:value pair, so I can move over to the javascript side and manipulate the string and insert values into an existing dropdown. If there is a better way, please let me know. Thank you.

My php code is:
[php]
<?php
$host="localhost"; // Host name
$username="mysqlusername"; // Mysql username
$password="mysqlpassword"; // Mysql password
$db_name="testdb"; // Database name

if($_GET['action'] == 'getOptions'){
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

switch($_GET['jobtype']){
case 0:

break;

case 1:
error_reporting(E_ALL);
ini_set('display_errors', True);

$sql="Select id, yardtype From YardTypes";

while ($row = mysql_fetch_array($sql) )
$temp = $temp.$row[id].":".$row[yardtype].";";

echo ($temp);

break;

case 2: //Internet
break;

default: //User has selected all required information...save job
$jobtype=$_POST['jobtype'];
$jobdescription=$_POST['jobdescription'];

$sql="INSERT INTO $tbl_name (userid, jobtype, jobdescription) VALUES('$userid', '$jobtype', '$jobdescription')";

if (mysql_query($sql))
header("location:thankyou.php");
else
echo "The server is temporarily unavailable. We apologize for the inconvenience.";

break;
}
}
?>
[/php]
Oct 21 '07 #1
3 1377
pbmods
5,821 Expert 4TB
Heya, Mike.

Before calling mysql_fetch_array(), you must first execute your SQL query and generate a result resource by using mysql_query():

Expand|Select|Wrap|Line Numbers
  1. $sql="Select id, yardtype From YardTypes";
  2.  
  3. $res = mysql_query($sql);
  4.  
  5. if( empty($res) )
  6. {
  7.     echo $sql, '<br /><br />', mysql_error();
  8. }
  9.  
  10. while( $row = mysql_fetch_assoc($res) )
  11. {
  12.     .
  13.     .
  14.     .
  15.  
Oct 21 '07 #2
Heya, Mike.

Before calling mysql_fetch_array(), you must first execute your SQL query and generate a result resource by using mysql_query():

Expand|Select|Wrap|Line Numbers
  1. $sql="Select id, yardtype From YardTypes";
  2.  
  3. $res = mysql_query($sql);
  4.  
  5. if( empty($res) )
  6. {
  7.     echo $sql, '<br /><br />', mysql_error();
  8. }
  9.  
  10. while( $row = mysql_fetch_assoc($res) )
  11. {
  12.     .
  13.     .
  14.     .
  15.  

That worked great...thank you very much for the second set of eyes. I guess I have been working too much today.
Oct 21 '07 #3
pbmods
5,821 Expert 4TB
Heya, Mike.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, well, you know... :)
Oct 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: sky2070 | last post by:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in c:\inetpub\wwwroot\session.php on line 19 can anyone tell me what is wrong with this code??? <? // Define the Session...
1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
3
by: Dave | last post by:
Hello all, I found Herb Sutter's article regarding error handling in the most recent CUJ to be very, very good. However, in trying to apply what I learned from the article, I am left with some...
6
by: WindAndWaves | last post by:
Hi Gurus The page below has a strange error. It seems to be working very well, just when you enter 8 or 9 for day, month or year then you get an error. I really have no idea where that is...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
10
by: jeff regoord | last post by:
A user inputs a float value. The scanf() function gets the value. However, I need to create an error handler with an if else statement saying invalid input if the input is not a number. Does...
3
by: jer006 | last post by:
Hi I am writing a select statement that has an arithmetic function inside a case statement that uses logic to decide whether to divide or multiply and when I run the arithmetic statements outside...
9
by: 2DIL | last post by:
hello all experts, basically, i have a very small project, in which 97% of the work is complete. yet there is an issue which i cannot solve and i have no error to indicate what the problem...
2
by: FutureShock | last post by:
I am using a registration class to process a registration form and need some opinions on returning error messages. I am self referring the page on submit. I would like to send each form field...
1
by: chienee | last post by:
here is the code <?php session_cache_limiter('private,must-revalidate'); session_start(); require_once("config.php"); include ("classes/db_functions.php"); include ("classes/display.php");
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.