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]
3 1377
Heya, Mike.
Before calling mysql_fetch_array(), you must first execute your SQL query and generate a result resource by using mysql_query(): -
$sql="Select id, yardtype From YardTypes";
-
-
$res = mysql_query($sql);
-
-
if( empty($res) )
-
{
-
echo $sql, '<br /><br />', mysql_error();
-
}
-
-
while( $row = mysql_fetch_assoc($res) )
-
{
-
.
-
.
-
.
-
Heya, Mike.
Before calling mysql_fetch_array(), you must first execute your SQL query and generate a result resource by using mysql_query(): -
$sql="Select id, yardtype From YardTypes";
-
-
$res = mysql_query($sql);
-
-
if( empty($res) )
-
{
-
echo $sql, '<br /><br />', mysql_error();
-
}
-
-
while( $row = mysql_fetch_assoc($res) )
-
{
-
.
-
.
-
.
-
That worked great...thank you very much for the second set of eyes. I guess I have been working too much today.
Heya, Mike.
Glad to hear you got it working! Good luck with your project, and if you ever need anything, well, you know... :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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");
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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
|
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...
| |