0

hi all...
pls help me... i have a problem with editing the record...
my adding and editing page are same.... adding works properly but while editing a record
for ex : if i change the emailid of a record and if the newly given emailid is already exists in the db it shows a error msg that the mailid is already exists... but while showing error msg the edit page changes to the add page.....
can any one help me to fix this problem....
tnx in advnc....

Edited by amith_ami

3
Contributors
6
Replies
7
Views
4 Years
Discussion Span
Last Post by amith_ami
0

tnx for ur reply... diafol

here is my form from where i get emailid.. addcandidates.php

<?php  
    $cnd_id= $_GET['cnd_id'];
    $sql= "SELECT * FROM tbl_candidate WHERE cnd_id='$cnd_id' ";
    mysql_query($sql)or die(mysql_error());     

 ?>

 <table align="center" border=0 width=80% cellpadding=0 cellspacing=0 class=naBrDr>
        <tr>
            <td   height="28" bgcolor="#eeeeee" align="center" ><?php if($cnd_id>0) echo '<b>Edit Candidate</b>';else echo '<b>Add New Candidate</b>';?></td>
        </tr>
     <td align="center" style="padding-top:18px">
      <form name="frm_add" id="frm_add" action="<?php echo $_SERVER['PHP_SELF']?>" method="post" onSubmit="return validate(this);" enctype="multipart/form-data">
       <table width='600' bgcolor="#cccccc" cellpadding='4' cellspacing='1' align='center'>
              <tr> 
                <td colspan="4">&nbsp;</td>
              </tr>
              <?php if($frm_server_side_error!=""){?>
              <tr> 
                <td colspan="2" align="center" class="form_error"><?php echo $frm_server_side_error;?></td>
              </tr>
              <?php }?>

              <tr> 
                <td>Email Id *</td>
                <td  align="left" colspan="2"><input type='text' id="email_id" name='email_id' size="30" maxlength="30" value="<?php echo $email_id;?>"> <label id='label4'><?php echo $msg?></label>
                </td>
              </tr>
              </table>

this is my code for action page... act_addcandidate1.php

<?php
if(isset ($_REQUEST["cnd_id"]))
{
  $cnd_id           =   $_REQUEST["cnd_id"];

}
else
{
  $cnd_id=0;
}

if($_SERVER['REQUEST_METHOD']=="POST"){
    $cnd_id             =  $_POST["cnd_id"];
    $email_id1          =  $_POST['email_id'];
?>

<?php
if($cnd_id>0){

$sql="UPDATE tbl_candidate SET email_id = '".$email_id1."' WHERE cnd_id= $cnd_id";
         $obj->query($sql) or die(mysql_error());

    }else {  

    $emailCheck = mysql_query("SELECT email_id FROM tbl_candidate WHERE email_id = '".$email_id1."'");
        if (mysql_num_rows($emailCheck) > 0) {

       $msg= "Email Address Already Exists";
       return;
        }

$sql="INSERT INTO  tbl_candidate(email_id) VALUES('$email_id1');

 $obj->query($sql) or die(mysql_error());
 }
 header("Location: ./candidatelist.php");
        exit();

        else{
    if($cnd_id>0){
        $sql="Select * from tbl_candidate where cnd_id='$cnd_id'";
        $obj->query($sql);
        if($row=$obj->query_fetch()) {
        $email_id           =  stripslashes($row['email_id']);
            }
    }
}
?>
0

Line 32: $sql="INSERT INTO tbl_candidate(email_id) VALUES('$email_id1'); has a missing quote before the semi-colon.
Line 39: else{ is missing the preceding curly brace.
Fix those, see what happens.

0

tnx for ur reply... adam.adamski.96155

i fixed that error you mentioned but its not working....

0

hi.. adam.adamski.96155
yeah i fixed them both... but its not working.
actually what i want is...
if the email address already exists it must show an error msg and also stay on the same edit page.....

tnx in advnc...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.