i Have written 2 php codes and one js thata are shown above. The first code selects the categories of the table and by selecting the category i want to let me select one of the product for example of the selected category. The result of these codes is by selecting one category it shows me to select product but the option in empty. could enyone help?

1st php code

<?php

ini_set('default_charset', 'UTF-8');
ini_set('display_errors',1);
error_reporting(E_ALL & E_NOTICE);
session_start();
$con = mysql_connect("localhost","root","");
mysql_query("set character set 'utf8'", $con);
if(!mysql_select_db('database')) {
echo 'problem'.mysql_error();
exit();
}

$userid=$_SESSION['userid'];

?> 
                                            <FORM action="event_2.php" name="form1" method="POST">
                                            <strong>Select Category:</strong><br><br>
                                            <?php
                                            $query= "select * from store_items where userid='".$userid."' order by cat_title asc";
                                            $r=mysql_query($query);
                                            if(mysql_num_rows($r)>=0) {
                                            ?>
                                                <td><select id="cat_title" name="cat_title" onchange="show_cat(this.value)">
                                                <option value="0">Select Category</option>
                                                <?php
                                                while ($row=mysql_fetch_array($r)) {

                                                echo '<option value='.$row['cat_title'].'>'.$row['cat_title'].'</option>';

                                                }
                                                echo '</select><span id="icon"></span></td></tr>';
                                            }
                                            ?>
                                            <br>
                                            <tr><th><span id="item_title"></span><span id="art_num"></span></th></tr>

javascript code

function show_cat( cat_title )
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("item_title").innerHTML=xmlhttp.responseText;
    document.getElementById("icon").innerHTML="";
       }  
  }
xmlhttp.open("GET","show_item_title.php?cat_title="+cat_title,true);
xmlhttp.send();
}

function show_art_num( item_title )
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("art_num").innerHTML=xmlhttp.responseText;
    document.getElementById("icon1").innerHTML="";
    }  
  }
xmlhttp.open("GET","show_item_title.php?item_title="+item_title,true);
xmlhttp.send();
}

show_item_title.php

<?php


ini_set('default_charset', 'UTF-8');
ini_set('display_errors',1);
error_reporting(E_ALL & E_NOTICE);
session_start();
$con = mysql_connect("localhost","root","");
mysql_query("set character set 'utf8'", $con);
if(!mysql_select_db('database')) {
echo 'problem'.mysql_error();
exit();
}

$userid=$_SESSION['userid'];


    if (isset($_GET['cat_title'])){

                $query="SELECT FROM store_items WHERE cat_title='".$_GET['cat_title']."'";
                $r= mysql_query($query);
                $response="";
                if(mysql_num_rows($r) >=0 ) { 

                        $response.= '<br/><th><strong>Select product:</strong></th><br/><br/>';
                        $response.= '<select name="item_title" id="item_title" onchange="show_art_num(this.value)">';
                        while ($row=mysql_fetch_array($r)) {
                        $response.='<option value="'.$row['item_title'].'">'.$row['item_title'].'</option>';
                        }
                    $response.='</select><span id="icon1"></span>';
                } 

    }
echo $response; 

?>

SELECT FROM store_items ... is missing *

still not echo-ing $row['item_title']

you can always try to see if your query running properly..

Line 21 - $r = mysql_query($query) or die ("There was an error: " . mysql_error());

Before that, you may actually want to echo out what you are passing into mysql:

Insert into line 20 - die($query); //this will exit the function of the page, and print out the
                                   //the query. You will have to remove it to make the page
                                   //function again.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.