By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,081 Members | 1,885 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,081 IT Pros & Developers. It's quick & easy.

Unable to catch dropdownlist value, error in SQL statement

P: 7
[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
Share this Question
Share on Google+
9 Replies


ak1dnar
Expert 100+
P: 1,584
[PHP]$schName=$_GET['select']; [/PHP]
May 11 '07 #2

P: 7
[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
Expert 5K+
P: 5,821
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
Expert 100+
P: 1,584
[PHP]$_Get [/PHP]is wrong
[PHP]$_GET[/PHP] is the correct way.
May 11 '07 #5

ak1dnar
Expert 100+
P: 1,584
pbmods has posted before me. Thanks.:)
Valeberry did you solve the problem.
May 11 '07 #6

P: 7
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
Expert 100+
P: 1,584
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

P: 7
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
Expert 100+
P: 1,584
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

Post your reply

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