2012-03-03 54 views
1

私はphpとmysqlを使用しています。下にコードがあります...私が '州'を選択すると、その州の都市のリストを取得する必要があります...しかし、都市を引っ張っていません... 'State'の値がプッシュされていないようです都市の質問...私は間違って何をしていますか?変数が渡されない場合の修正方法

ありがとうございます!

</head> 

<body> 
<div id="wrapper"> 

<div id="header"> 

<h1>Tomorrow's Toys Today</h1> 
</div> 
<div id="subheader"> 
</div> 

<div id="leftmenu"> 

<?php 

    include("misc.inc");           // 11 


    $connection = mysql_connect($host,$user,$password)    // 13 
     or die ("couldn't connect to server"); 
    $db = mysql_select_db($database,$connection)     // 15 
     or die ("Couldn't select database"); 


[email protected]$_GET['state']; 

[email protected]$_GET['city']; 


@$quer=mysql_query("SELECT state FROM states"); 


echo '************' , $state; 

if(isset($state) and strlen($state) > 0){ 

@$quer2=mysql_query("SELECT city FROM cities c, states s where c.state_id = s.state_id and s.state = $state "); 

}else{$quer2=mysql_query("SELECT city FROM cities c, states s where c.state_id = s.state_id and s.state = $state"); }; 



echo "<form method=post name=f1 action='dd-check.php'>"; 
echo "<table> <tr><td>"; 



echo "State"; 

echo"</td><td>"; 

echo "<select name='state' onchange=\"reload(this.form) \"><option value=''>Select one</option>"; 

while($noticia = mysql_fetch_array($quer)) { 

if($noticia['state=']==$state){ 

     echo "<option value='$noticia[state]'>$noticia[state]</option>"."<BR>";} 

    else{ 

     echo "<option value='$noticia[state]'>$noticia[state]</option><br>";} 

} 

echo "</select></td></tr><tr><td>"; 


echo "City"; 

echo "</td><td>"; 

echo "<select name='city' onchange=\"reload(this.form) \"><option value=''>Select one</option>"; 

while($noticia2 = mysql_fetch_array($quer2)) { 

if($noticia2['city=']==$city){ 

     echo "<option value='$noticia2[city]'>$noticia2[city]</option>"."<BR>";} 

    else{ 

     echo "<option value='$noticia2[city]'>$noticia2[city]</option>";} 

} 


echo "</select></td></tr><tr><td>"; 

echo "<input type=submit value=Show></td></tr></table>"; 
echo "<input type=text name=state value=$state>"; 
echo "</form>"; 
?> 


</div> 

<div id="main"> 



</div> 


</div> 
+0

'@'を使用してエラーを抑制しないでください。それだけではデバッグが不可能になります。 – PeeHaa

答えて

3

$ _GET ['state']は文字列ですか?もしそうなら、あなたは次のようなことをするべきです:

$quer2=mysql_query("SELECT city FROM cities c, states s where c.state_id = s.state_id and s.state = '".mysql_real_escape_string($state)."'"); 

文字列には引用符が必要です。 Intはしません。あなたはその入力を害するべきです。

また、すべてのものの上に@を使用するよりも、エラーを抑制することで、より良い方法... http://php.net/manual/en/function.error-reporting.php

+0

が設定されている場合、$ _GET ['state']は常に文字列ではありませんか? – Shoe

+0

@ JeffPigarelliリクエスト超大域は常に文字列です – PeeHaa

+0

@PeeHaa、ありがとう。 – Shoe

0
@$quer2=mysql_query("SELECT city FROM cities c, states s where c.state_id = s.state_id and s.state = $state "); 

}else{$quer2=mysql_query("SELECT city FROM cities c, states s where c.state_id = s.state_id and s.state = $state"); }; 

エコー "$状態" があります。あなたに出力$状態を与えるでしょう echo $ state;またはエコー "{$ state}";

あなたのケースで

@$quer2=mysql_query("SELECT city FROM cities c, states s where c.state_id = s.state_id and s.state = ".$state." "); 
}else{$quer2=mysql_query("SELECT city FROM cities c, states s where c.state_id = s.state_id and s.state = ".$state.""); }; 
+0

あなたの答えをありがとう..私は試みた:エコー "$状態"; echo "{$ state}";どちらも私に状態を示していません。私はKarolとQingによって提供された@ query2ステートメントも試しましたが、どちらも結果を返していません!その他の提案はありますか?ありがとう! –

+0

私は状態を選択した後、私はビューソースを行って、次のメッセージを取得しています..どのように私はそれを解決するのですか?私はPHPが初めてです!ありがとう.. –

0
</head> 

<body> 
<div id="wrapper"> 

<div id="header"> `enter code here` 

<h1>Tomorrow's Toys Today</h1> 
</div> 
<div id="subheader"> 
</div> 

<div id="leftmenu"> 

<form method=post name=f1 action='dd-check.php'><table> <tr><td>State</td><td><select name='state' onchange="reload(this.form) "><option value=''>Select one</option><br /> 
<b>Notice</b>: Undefined index: state= in <b>C:\xampp\htdocs\Dummies\index.php</b> on line <b>62</b><br /> 
<option value='Virginia'>Virginia</option><BR><br /> 
<b>Notice</b>: Undefined index: state= in <b>C:\xampp\htdocs\Dummies\index.php</b> on line <b>62</b><br /> 
<option value='Maryland'>Maryland</option><BR><br /> 
<b>Notice</b>: Undefined index: state= in <b>C:\xampp\htdocs\Dummies\index.php</b> on line <b>62</b><br /> 
<option value='Washington DC'>Washington DC</option><BR><br /> 
<b>Notice</b>: Undefined index: state= in <b>C:\xampp\htdocs\Dummies\index.php</b> on line <b>62</b><br /> 
<option value='Colorado'>Colorado</option><BR></select></td></tr><tr><td>City</td><td><select name='city' onchange="reload(this.form) "><option value=''>Select two</option><br /> 
<b>Warning</b>: mysql_fetch_array() expects parameter 1 to be resource, boolean given in <b>C:\xampp\htdocs\Dummies\index.php</b> on line <b>81</b><br /> 
</select></td></tr><tr><td><input type=submit value=Show></td></tr></table><input type=text name=state value=></form> 
関連する問題