Jump to content

monim20

New Members
  • Posts

    4
  • Joined

  • Last visited

monim20's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. can you please tell me syntactically how can i trim it as i am new to php
  2. I have this function which uses ajax ,but this function is not working ,I tried a lot ,but not able to figure out where is the problem ,I am trying to create alert if user inserts duplicate entry in database using check-box selection <script> function func(e,eid,emprid) { if(document.getElementById(e).checked){ var dataString = 'eid='+eid +'&emprid='+emprid ; $.ajax({ type:"POST", url: "mylistcheck.php", data: dataString, success: function(result){ if(result!='0') { modal.open({content: "<span style=\"color:red\" ><h2>You have already selected candidate </h2></span>"}); document.getElementById(e).checked=false; } } }); } } </script> mylistcheck.php file <?php require_once("includes/session.php"); ?> <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php $eid=$_POST['eid']; echo "eid".$eid; $emprid=$_POST['emprid']; echo "rid".$emprid; $sqlchecklist="SELECT * FROM selected_candidate WHERE eid='{$eid}' AND rid='{$emprid}' "; $checklistres=mysql_query($sqlchecklist); $list_check=mysql_num_rows($checklistres); echo "numrows listcheck".$list_check; if($list_check>0) { echo "1"; } else { echo "0"; } ?> check-box code echo "<td><input id=\"select_candi{$i}\" onclick=\"javascript:func(this.id,{$data_set['eid']},{$emprid})\" type=\"checkbox\" name=\"check_candi[]\" value=\"{$data_set['eid']},{$emprid}\"/></td>";
  3. I am using given bellow php code for inserting data into database ,i have made "eid" and "rid" columns unique so that user is restricted to insert duplicate entry,I am getting error when user try to insert duplicate values ,but i want to alert user at the time of check-box selection itself,so how can i achieve this <?php //insert selected candidate in table //echo "checkcandi".$_POST['check_candi']; if(isset($_POST['select_candidate']) && logged_in()) { $checkcandi_sel = $_POST['check_candi']; if(empty($checkcandi_sel)) { echo("You didn't select any Candidate."); } else { $N = count($checkcandi_sel); echo("You selected $N Candidate(s) "); /*for($i=0; $i < $N; $i++) { echo($checkcandi_sel[$i] . " "); $eid=$checkcandi_sel; echo "candi id".$eid; }*/ if($N > 0) { foreach($checkcandi_sel as $csel) { $excsel = explode(",",$csel); //echo($checkcandi_sel[$i] . " "); $eid=$excsel[0]; $emprid=$excsel[1]; //echo($emplyrid . " "); $selected_val="1"; $query = "INSERT INTO selected_candidate ( eid,rid,selected_val ) VALUES ( '{$eid}','{$emprid}','{$selected_val}' )"; $result = mysql_query($query, $connection) or die(mysql_error()); } } } } ?> and this is the chechbox code echo "<td><input id=\"select_candi{$i}\" onclick=\"javascript:func(this.id,{$data_set['eid']})\" type=\"checkbox\" name=\"check_candi[]\" value=\"{$data_set['eid']},{$emprid}\"/></td>";
×
×
  • 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.