473,396 Members | 1,942 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,396 software developers and data experts.

Unable to catch dropdownlist value, error in SQL statement

[PHP]index
<?php
include ("conn.php");
require_once("tabs.php");
?>
<html>
<head>
<?php tabs_header(); ?>
</head>
<body>
<div style="width:600px;">
<?php tabs_start(); ?>
<?php tab( "Junior Colleges" ); ?>
<form id="form1" name="form1" method="post" action="dd2.php">
<?PHP
$query = 'SELECT DISTINCT schName FROM schools';
//$query2='SELECT DISTINCT schLocation FROM schools';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "<select name=select value='' ><option>Please select</option>";
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[schName]>$nt[schName]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box

echo '<input type="submit" value="Yes" />';



?></form>
<?php tab( "PolyTechnic" ); ?>
This is the second tab.
<?php tabs_end(); ?>
</div>
</body>
</html>
[/PHP]

[PHP]Display result
<?PHP
include ("conn.php");
?>
<?PHP
$schName=$_Get['select'];

$query = "SELECT schName FROM schools where schName='$schName'";

$numresults = mysql_query($query) or die ("<center>Couldn't execute query</center>");
$row= mysql_fetch_array($numresults);
echo $numresults;
echo $row;
print $schName;
echo '<br>';

echo "<center><h1>Search results for: " . $schName ." </h1></center>";


?>
[/PHP]

Error Message when supposed to display result:
Couldn't execute query
"); $row= mysql_fetch_array($numresults); echo $numresults; echo $row; print $schName; echo '
'; echo "
Search results for: " . $schName ."
"; ?>


Any1 knows what is wrong with my statement??
May 11 '07 #1
9 2069
ak1dnar
1,584 Expert 1GB
[PHP]$schName=$_GET['select']; [/PHP]
May 11 '07 #2
[PHP]$schName=$_GET['select']; [/PHP]
What shld i do to solve this error?
Do i use $_Request to get the schName from drop downlist?
May 11 '07 #3
pbmods
5,821 Expert 4TB
What shld i do to solve this error?
Do i use $_Request to get the schName from drop downlist?
Ajaxrand was pointing out that it s/b $_GET instead of $_Get.

At this line:

[PHP]
$numresults = mysql_query($query) or die ("<center>Couldn't execute query</center>");
[/PHP]

Try this instead:
[PHP]
$numresults = mysql_query($query) or die (mysql_error());
[/PHP]

Also, try running your query manually in MySQL. Make sure you're actually getting results.
May 11 '07 #4
ak1dnar
1,584 Expert 1GB
[PHP]$_Get [/PHP]is wrong
[PHP]$_GET[/PHP] is the correct way.
May 11 '07 #5
ak1dnar
1,584 Expert 1GB
pbmods has posted before me. Thanks.:)
Valeberry did you solve the problem.
May 11 '07 #6
pbmods has posted before me. Thanks.:)
Valeberry did you solve the problem.
Yup. Thanks.
However, I'm still unable to display full name of the school from drop dwnlist. I'm getting from the database.
I hav insert the values.

[PHP]dd1
<?PHP
$query = 'SELECT DISTINCT schName FROM schools';
//$query2='SELECT DISTINCT schLocation FROM schools';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "<select name= 'select' value='' ><option>Please select</option>";
while($nt=mysql_fetch_array($result))
{
//Array or records stored in $nt
echo "<option value=$nt[schName]>$nt[schName]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box

echo '<input type="submit" value="Yes" />';



?>


[/PHP]

Is there anything wrong with the logic with the follwin statement?
echo "<option value=$nt[schName]>$nt[schName]</option>";


[PHP]dd2
<?PHP
include ("conn.php");
?>
<?PHP
$schName= $_GET['select'];
echo $_REQUEST[$schName];
$query = "SELECT schName FROM schools where schDesc='$schName'";

$numresults = mysql_query($query) or die ('Query failed: ' . mysql_error());
$row= mysql_fetch_row($numresults);
$row[0] =$schName ;


echo "<center><h1>Search results for: " . $schName ." </h1></center>";



?>

[/PHP]

From the following codes:
$row= mysql_fetch_row($numresults);
$row[0] =$schName ;

I can display Victoria instead of Victoria Junior College.

How shld I resolve the problem to display Victoria Junior College instead of Victoria?
May 11 '07 #7
ak1dnar
1,584 Expert 1GB
You are still printing this variable
[PHP] $schName= $_GET['select']; [/PHP]

Not the Table value.Use like this.

[PHP]<?PHP
include ("conn.php");
$schName= $_GET['select'];
//echo $_REQUEST[$schName];
$query = "SELECT schName FROM schools where schDesc='$schName'";
$numresults = mysql_query($query) or die ('Query failed: ' . mysql_error());
$row= mysql_fetch_row($numresults);
//$row[0] =$schName ;
echo "<center><h1>Search results for: " . $row[0] ." </h1></center>";
?> [/PHP]
May 11 '07 #8
You are still printing this variable
[PHP] $schName= $_GET['select']; [/PHP]

Not the Table value.Use like this.

[PHP]<?PHP
include ("conn.php");
$schName= $_GET['select'];
//echo $_REQUEST[$schName];
$query = "SELECT schName FROM schools where schDesc='$schName'";
$numresults = mysql_query($query) or die ('Query failed: ' . mysql_error());
$row= mysql_fetch_row($numresults);
//$row[0] =$schName ;
echo "<center><h1>Search results for: " . $row[0] ." </h1></center>";
?> [/PHP]
It did nt display ath. =(
Output was a blank page.
May 11 '07 #9
ak1dnar
1,584 Expert 1GB
It did nt display ath. =(
Output was a blank page.
Is it working when you pass a value to $schName manually.

[PHP]<?PHP
include ("conn.php");
//$schName= $_GET['select'];
$schName= 'victoriya';
//echo $_REQUEST[$schName];
$query = "SELECT schName FROM schools where schDesc='$schName'";
$numresults = mysql_query($query) or die ('Query failed: ' . mysql_error());
$row= mysql_fetch_row($numresults);
//$row[0] =$schName ;
echo "<center><h1>Search results for: " . $row[0] ." </h1></center>";
?>[/PHP]
May 11 '07 #10

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

Similar topics

2
by: Joey | last post by:
Hi There, I am trying to get the selected value of a listbox when I click a button, everything works ok and I can bind the list and when I have a basic page and click a button to invoke a sub it...
10
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
2
by: Michael | last post by:
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP, I am unable to find out why the "Build for Debug" option within Stored Procedure Builder is not enabled on Java stored...
4
by: glenn | last post by:
Hi folks, I am getting an error "Object reference not set to an instance of an object". It seems I have everything in place but something is obviously in err. If you could take a quick peak...
4
by: ^MisterJingo^ | last post by:
Hi all, I have a web page which has a single dropdownlist containing 3 items. Below the dropdownlist are two listboxes. Depending on the option selected from the dropdownlist, the left most...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
5
by: Cirene | last post by:
I seem to remember seeing a solution where a databound dropdownlist (used as a FILTER for a gridview) had the 1st item as "ALL ITEMS". It used a query with a UNION. But I can't find the example....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.