scaleautostyle Posted July 7, 2010 Share Posted July 7, 2010 Hi!! see below a form. when I run it it doesn't work like it suppose. find attache a screenshot of the load page. here's the code <? include_once("db_connection.php"); ////////////////////////////// ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>(Type a title for your page here)</title> </head> <body > <? $todo=$_POST['todo']; if(isset($todo) and $todo=="search"){ $less=$_POST['less']; $greater=$_POST['greater']; $class=$_POST['class']; $sex=$_POST['sex']; $search_text=$_POST['search_text']; $type=$_POST['type']; $query="select * from student where "; ////////// Including mark less than field search //// if(strlen($less) > 0 ){ $query.= " mark < $less and "; } //// End of class field search /////////// ////////// Including mark less than field search //// if(strlen($greater) > 0 ){ $query.= " mark > $greater and "; } //// End of class field search /////////// ////////// Including class field search //// if(strlen($class) > 0 ){ $query.= " class='$class' and "; } //// End of class field search /////////// ////////// Checking of sex in the query //// if(strlen($sex) > 0 ){ $query.= " sex='$sex' and "; } //// End of sex field search /////////// ////////////////////////// Key word search query ///////// $search_text=ltrim($search_text); $search_text=rtrim($search_text); if(strlen($search_text)>0){ if($type<>"any"){ $query .=" name='$search_text'"; }else{ $kt=split(" ",$search_text);//Breaking the string to array of words // Now let us generate the sql while(list($key,$val)=each($kt)){ if($val<>" " and strlen($val) > 0){$query .= " name like '%$val%' or ";} }// end of while $query=substr($query,0,(strLen($query)-3)); // this will remove the last or from the string. } // end of if else based on type value $query.=" and "; }// end of if area , if search_text value is entered ///////////////End of adding key word search query ////////// $query=substr($query,0,(strLen($query)-4)); echo $query; echo "<br><br>"; $nt=mysql_query($query); echo mysql_error(); // End if form submitted }else{ echo "<form method=post action=''><input type=hidden name=todo value=search>"; $q=mysql_query("select distinct class from student"); echo "<select name=class><option value=''>Any Class</option>"; while($n=mysql_fetch_array($q)){ echo "<option value=$n[class]>$n[class]</option>"; } echo "</select>"; echo "<input type=radio name=sex value=male>Male <input type=radio name=sex value=female>Female <input type=radio name=sex value='' checked> Any<br>"; echo "<br>Name Match<br><input type=text name=search_text ><br> <input type=radio name=type value=any checked>Match any where <input type=radio name=type value=exact>Exact Match <br><br> Mark of the student <br> Less than<input type=text name=less size=2>Greater than <input type=text name=greater size=2> <br><input type=submit value=Search> </form> "; } ?> </body> </html> any help will be appreciate. I'm sure it's a stupid thing but for now I don't see it. yours sebastien [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/207003-what-is-wrong-in-this-coding/ Share on other sites More sharing options...
tomtimms Posted July 7, 2010 Share Posted July 7, 2010 I recommend changing <? to <?PHP Link to comment https://forums.phpfreaks.com/topic/207003-what-is-wrong-in-this-coding/#findComment-1082415 Share on other sites More sharing options...
scaleautostyle Posted July 7, 2010 Author Share Posted July 7, 2010 it's already done but same result sebastien Link to comment https://forums.phpfreaks.com/topic/207003-what-is-wrong-in-this-coding/#findComment-1082456 Share on other sites More sharing options...
kenrbnsn Posted July 7, 2010 Share Posted July 7, 2010 Either PHP is not enabled on your server or you've named your file something other that ".php". Ken Link to comment https://forums.phpfreaks.com/topic/207003-what-is-wrong-in-this-coding/#findComment-1082459 Share on other sites More sharing options...
scaleautostyle Posted July 7, 2010 Author Share Posted July 7, 2010 Hi tomtimms!! MAGIE.. don;t know why but now working... except for one thing I receive this message Notice: Undefined index: todo in .............search-db.php on line 16 this is the code at the line 16 $todo=$_POST['todo']; so what's the problem yours sebastien Link to comment https://forums.phpfreaks.com/topic/207003-what-is-wrong-in-this-coding/#findComment-1082460 Share on other sites More sharing options...
trq Posted July 7, 2010 Share Posted July 7, 2010 $_POST['todo'] isn't defined when you try and access it. Instead of.... $todo=$_POST['todo']; if(isset($todo) and $todo=="search"){ You should use... if (isset($_POST['todo']) && $_POST['todo'] == "search") { $todo=$_POST['todo']; // rest of code Link to comment https://forums.phpfreaks.com/topic/207003-what-is-wrong-in-this-coding/#findComment-1082463 Share on other sites More sharing options...
scaleautostyle Posted July 7, 2010 Author Share Posted July 7, 2010 thank you thorpe that's work... now I will try do cusotmize this file to met my needs. thanks to everyone sebastien Link to comment https://forums.phpfreaks.com/topic/207003-what-is-wrong-in-this-coding/#findComment-1082467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.