(Replaced back-ticks with [code]...[/code] tags ~ MOD)

I have depended dropdown but this error occur

<select id="alphaid" name="alphaid" onchange="getalpha(this.value)">
<option>Select Alphabit</option>
<?php 
mysqli_query($conn, "Select * from verbs");
$alphabits	=	range('A', 'Z');
foreach($alphabits as $alphabit)
{
?>
<option value="<?php echo $alphabit; ?>"><?php echo $alphabit; ?> </option>
<?php } ?> </select> </div></div>
			    <select class="form-control" name="verbid" id="verbid" onChange="getverb(this.value)">
							<option>------- Select Verb --------</option>
								</select>
===============================
<script>
 $(document).ready(function(){
 });
 function getalpha(alphaid)
 {
 $.post("get_verb.php", { alphaid:alphaid }, function(data){
 $("#verbid").html(data);
 });
 }
 
 function getverb(verbid)
 {
 $.post("get_verb.php", { verbid:verbid }, function(data){
 });
 }
 
 </script>
 =========================
 Get_verb.php

if (isset($_POST['alphaid'])){
$alphaid = $_POST['alphaid'];
$query = mysqli_query($conn, "Select * from verb_translation where start_with = ".$alphaid." order by eng_translation");
	if(mysqli_num_rows($query) > 0) 
	{
		echo '<option value="">------- Select verbs -------</option>';
		while($row = mysqli_fetch_assoc($query))
		{
			echo '<option value="'.$row->fkverbid.'">'.$row->eng_translation.'</option>';	
		}
	} else {
		echo '<option value="">No Record</option>';
	}

} 

    i have dependend dropdown A to Z alphabet on ist dropdown when click A on second dd all relvent data load on the dropdown

      That error almost always means that your DB query failed do to work, causing the database to reject it as invalid. Therefore you should test if $query is false, and if so, maybe output/log some debug info and find out what the problem was.

      For quick-and-dirty debug code that you do not want in the final version:

      $sql = "Select * from verb_translation where start_with = ".$alphaid." order by eng_translation";
      $query = mysqli_query($conn, $sql);
      if($query == false) {
        die("<pre>Query failed:\n$sql\n".mysqli_error($conn)."</pre>");
      }
      

      PS: At a wild guess, the value used in the where clause needs to be quoted, perhaps? (That would best be worked around by using a prepared statement with a bound parameter there, which would also make it more secure.)

      NogDog PS: At a wild guess, the value used in the where clause needs to be quoted, perhaps?

      Reckon so, otherwise it would be finding rows where the value in the column named start_with is the same as the value in the column named <whatever was in $alphaid at the time>.

      Yeah: mysqli_error would have something to say about that.

      I'm also starting to suspect that the start_with column exists to avoid using LIKE.

        NogDog Query failed: Select * from verb_translation where fkverbid = A order by eng_translation Unknown column 'C' in 'where clause'

        /T1/ pkverbid , inspanish , start_with ,,, verbs
        /T2/ pktranslationid , fkverbid , eng_translation --- verb_translation

          See my previous post. And NogDog's.

            In other words, this...

            "Select * from verb_translation where start_with = ".$alphaid." order by eng_translation"

            ...needs to be...

            "Select * from verb_translation where start_with = '".$alphaid."' order by eng_translation"

            ...or better yet, rewrite it to use a prepared statement with a bound parameter: https://www.php.net/manual/en/mysqli.prepare.php and https://www.php.net/manual/en/mysqli-stmt.bind-param.php and https://www.php.net/manual/en/mysqli-stmt.execute.php

              2 months later
              Write a Reply...