Jump to content

Have a problem in AJAX, PHP and MySQL


kmkmahesh

Recommended Posts

i am begineer to programming, i just try for the code what should i want and make copy and paste it and i will try to use it i just have a problem while using ajax i pasting the code so plz help me where i did my mistake,

 

please consider that i dont have any technical knowledge to understand the technical terms, plz help me

 

while i selected all the options then also i not getting the next dropdown box

 

my code is here

timetableupdate.php

 

<head>

<script type="text/javascript">
function validate_form()
    {
          if(document.getElementById('reg').value=="")
            {
              alert("Please Select Regulation");
               return false; 
            }
            else
            if(document.getElementById('bcode').value=="")
            {
              alert("Please Select Branch");
               return false; 
            }else
            if(document.getElementById('year').value=="")
            {
              alert("Please Select Year");
               return false; 
            }else
            if(document.getElementById('sem').value=="")
            {
              alert("Please Select Semester");
               return false; 
            }
            //else
            //if(document.getElementById('sub_exp0').value=="")
            //{
            //  alert("Please Enter No of Times Taught");
            //   return false; 
            //}
            else
            {
             //return valid_sub();
            }    
    
    }

function showsub(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
  else
  if(document.getElementById('reg').value=="")                                //Code For Validating The Form
         {
         alert("Please Select Regulation");
          return false;
         }
    else
    if(document.getElementById('reg').value=="")                                
         {
         alert("Please Select Regulation");
          return false;
         }     
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getsemsubcode.php?sem="+str+ "&reg=" + reg + "&year=" + year + "&bcode=" + bcode,true);
xmlhttp.send();
}
</script>

<title>Time Table Updater</title></head>
<?php

include("..\dbdetails.php");
mysql_connect("$host", "$dbusername", "$dbpassword")or die("cannot connect server"); 
mysql_select_db("$dbname")or die("cannot select DB");

//Regulation display   $reg
echo "<select name=\"reg\">\n";
echo "<option value=\"\">Select Value</option>\n";
$sqla="SELECT * FROM $tbl_name group BY `Regulation` ASC ";
$resulta=mysql_query($sqla);
while($rowa = mysql_fetch_assoc($resulta))
{
$reg=$rowa['Regulation'];
echo "<option value=\"$reg\">$reg</option>";
} 
echo "</select>";


//Branch display   $bcode
echo "<select name=\"bcode\">\n";
echo "<option value=\"\">Select Value</option>\n";
$sqlc="SELECT * FROM $tbl_name group BY `Branch` ASC ";
$resultc=mysql_query($sqlc);
while($rowc = mysql_fetch_assoc($resultc))
{
$bcode=$rowc['Branch'];

if($bcode==0)  {$bname="MCA";}
elseif($bcode==1)  {$bname="CIVIL";}
elseif($bcode==2)  {$bname="EEE";}
elseif($bcode==4)  {$bname="ECE";}
elseif($bcode==5)  {$bname="CSE";}
elseif($bcode==12)  {$bname="IT";}

echo "<option value=\"$bcode\">$bname</option>";
} 
echo "</select>";

//Year display  $year
echo "<select name=\"yr\">\n";
echo "<option value=\"\">Select Value</option>\n";
$sqld="SELECT * FROM $tbl_name group BY `Year` ASC ";
$resultd=mysql_query($sqld);
while($rowd = mysql_fetch_assoc($resultd))
{
$year=$rowd['Year'];
echo "<option value=\"$year\">$year</option>";
} 
echo "</select>";

//Sem display   $sem
echo "<select name=\"sem\" onchange=\"showsub(this.value)\">\n";
echo "<option value=\"\">Select Value</option>\n";
$sqle="SELECT * FROM $tbl_name group BY `Sem` ASC ";
$resulte=mysql_query($sqle);
while($rowe = mysql_fetch_assoc($resulte))
{
$sem=$rowe['Sem'];
echo "<option value=\"$sem\">$sem</option>";
} 
echo "</select>";

//echo "<select name=\"level\" onchange=\"showsub(this.value)\">\n";

mysql_close();
?> 

 

getsemsubcode.php

 

<?php

$reg=$_GET["reg"];
$year=$_GET["year"];
$bcode=$_GET["bcode"];
$sem=$_GET["sem"];

include("..\dbdetails.php");
mysql_connect("$host", "$dbusername", "$dbpassword")or die("cannot connect server"); 
mysql_select_db("$dbname")or die("cannot select DB");


echo "<select name=\"reg\">\n";
echo "<option value=\"\">Select Value</option>\n";

$sql="SELECT * FROM user WHERE `Regulation` = '".$reg."' AND `Branch` = '".$bcode."' AND `Year` = '".$year."' AND
         `Sem` = '".$sem."'   ";


$result=mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{

$scode=$row['Subcode'];
$sname=$row['Subname'];

$sdisp="$scode"+ - +"$sname";

echo "<option value=\"$scode\">$sdisp</option>";
} 
echo "</select>";


mysql_close();
?> 

 

mysql table structure

 

Field 	Type 	Null 	Default 	
Htno 	varchar(10) 	Yes  	NULL  	  	 
Regulation 	varchar(3) 	Yes  	NULL  	  	 
level 	varchar(2) 	No  	  	  	 
Branch 	int(2) 	Yes  	NULL  	  	 
Year 	int(1) 	Yes  	NULL  	  	 
Sem 	int(1) 	Yes  	NULL  	  	 
Subcode 	varchar(5) 	Yes  	NULL  	  	 
Subname 	varchar(44) 	Yes  	NULL  	  	 
DOESERIAL 	int(2) 	No  	  	  	 
session 	varchar(2) 	No

 

plz help me, i really need help for this

 

I cant find that where i did wrong so plz help me  :rtfm:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.