Jump to content

form submit and check the upcheck values


sanjeet087

Recommended Posts

these are my page. when i select atleast one option from one group. it works f9.

but when i not select any value in any group it give an error. Please Help me out and Sorry for my bad english.

 

INDEX.HTML

 

<!DOCTYPE html>

 

<html>

<head>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<SCRIPT language="javascript">

$(function(){

 

    // add multiple select / deselect functionality

    $("#selectall").click(function () {

          $('.case').attr('checked', this.checked);

    });

 

    // if all checkbox are selected, check the selectall checkbox

    // and viceversa

    $(".case").click(function(){

 

        if($(".case").length == $(".case:checked").length) {

            $("#selectall").attr("checked", "checked");

        } else {

            $("#selectall").removeAttr("checked");

        }

 

    });

});

</SCRIPT>

 

</head>

<body>

 

<form action="parse.php" method="post">

 

  Choose the items you want:<br>

  <input type="checkbox" id="selectall" name="core[]" checked="checked">All Cores <br> 

 

  <input type="checkbox" name="core[]" class="case" value="2"> Cpu Core 2 <br>

 

  <input type="checkbox" name="core[]"  class="case" value="4"> Cpu Core 4 <br>

 

  <input type="checkbox" name="core[]"  class="case" value="6"> Cpu Core 6 <br>

  

  Choose the items you want:<br>

 

  <input type="checkbox" name="thread[]" value="2"> Cpu Thread 2 <br>

 

  <input type="checkbox" name="thread[]" value="4"> Cpu Thread 4 <br>

 

  <input type="checkbox" name="thread[]" value="8"> Cpu Thread 8 <br>

 

Choose the items you want:<br>

 

  <input type="checkbox" name="ram[]" value="2"> Cpu ram 2 <br>

 

  <input type="checkbox" name="ram[]" value="4"> Cpu ram 4 <br>

 

  <input type="checkbox" name="ram[]" value="8"> Cpu ram 8 <br>

  

  Choose the items you want:<br>

 

  <input type="checkbox" name="hdd[]" value="50-100"> 50 to 100 GB <br>

 

  <input type="checkbox" name="hdd[]" value="100-150"> 100 to 150 GB <br>

 

  <input type="checkbox" name="hdd[]" value="150-200"> 150 to 200 GB <br>

  

  <input type="submit" value="Submit Form">

 

</form>

 

</body>

 

</html>

 

 

 

 

 

PARSE.PHP

 

 

 

 

<?php

$cbArray = $_POST['core'];

$cbArray1= $_POST['thread'];

$cbArray2= $_POST['ram'];

$cbArray3= $_POST['hdd'];

 

$core="";

$thread="";

$ram="";

$hdd="";

if(empty($cbArray)){

 

  $core=all;

 

} else {

 

    $count = count($cbArray);

 

    echo("You selected $count items: <br>");

 

    for($i=0; $i < $count; $i++){

if($i==0)

{

$core=$cbArray[$i];

}

 if($i>0)

 {

      $core=$core." or ".$cbArray[$i];

     }

    }

 

}

 

if(empty($cbArray1)){

 

   $thread=all;

 

} else {

 

    $count1 = count($cbArray1);

 

    echo("You selected $count1 items: <br>");

 

    for($i=0; $i < $count1; $i++){

 if($i==0)

 {

 $thread=$cbArray1[$i];

 }

 if($i>0)

 {

 $thread=$thread." or ".$cbArray1[$i];

 }

  }

  }

 

if(empty($cbArray2)){

 

   $ram=all;

 

} else {

 

    $count2 = count($cbArray2);

 

    echo("You selected $count2 items: <br>");

 

    for($i=0; $i < $count2; $i++){

 if($i==0)

 {

     $ram=$cbArray2[$i];

}

if($i>0)

 {

  $ram=$ram." or ".$cbArray2[$i];

 }

 

    }

 

}

 

if(empty($cbArray3)){

 

   $hdd=all;

 

} else {

 

    $count3 = count($cbArray3);

 

    echo("You selected $count3 items: <br>");

 

    for($i=0; $i < $count3; $i++){

if($i==0)

 {

  $hdd="'$cbArray3[$i]'";

 }

 

 

      if($i>0)

 {

 

 $hdd="$hdd"." or "."'$cbArray3[$i]'";

   

}

    }

 

}

$sql ="select * from server where cpucore=".$core." and cputhread=".$thread." and cpuram=".$ram." and cpuhdd="."$hdd";

echo $sql;

 

 

 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.