Sabha Sabha - 5 months ago 7
PHP Question

correct syntax in a php/mysql code

I am struggling with the syntax if someone can help me.

Condition1 = if the value of

$ncha['p_no_contacts']-$ncha['r_cnt']
is 1 then add an extra echo in the
h1
section saying that, "You are viewing last contact details and have exhausted your membership. Please renew your membership" If the above value is more than 1 then let that one echo statement be as it is.

next thing is to update the payments table or delete the row from payments table if
$inc1
is equal to
$ncha['p_no_contacts']


I need a correct syntax if someone can help.

EDIT:

This is what I tried but I get error
Parse error: syntax error, unexpected '>' on line 51
which is the
h1
line of
else
statement.

Thanks

<div class="modal-dialog yoyo-large">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
</button>





if $ncha['p_no_contacts']-$ncha['r_cnt'] = 1
{
<h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (
<?php echo ($ncha['p_no_contacts']-$ncha['r_cnt']);?>)
</h1>
}
else
{
<h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (
<?php echo ($ncha['p_no_contacts']-$ncha['r_cnt']) <br> You are viewing last contact details and have exhausted your membership. Please renew your membership;?>)
</h1>





</div>
<div class="modal-body">
<div class="col-sm-12 form-group">
<div class="col-sm-6" style="font-size:13px;">
<table class="table table-hover table-striped">
<tr height="30">
<td width="80">
<strong>Matri ID :
</strong>
</td>
<td>
<?php echo $fet['matri_id']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Name :
</strong>
</td>
<td>
<?php echo $fet['username']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Address :
</strong>
</td>
<td>
<?php echo $fet['address']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Phone :
</strong>
</td>
<td>
<?php echo $fet['phone']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Mobile :
</strong>
</td>
<td>
<?php echo $fet['mobile']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Email :
</strong>
</td>
<td>
<?php echo $fet['email']; ?>
</td>
</tr>
</table>
</div>
</div>
<?php
$chk1=$ncha['r_cnt'];
$inc1=$chk1+1;





If $inc1 = $ncha['p_no_contacts']
(
$dele="delete from payments where (pemail='$mid' or pmatri_id='$mid')";
$de=mysql_query($dele) or die(mysql_error());
}
else
{
$upda="update payments SET r_cnt='$inc1' where (pemail='$mid' or pmatri_id='$mid')";
$up=mysql_query($upda) or die(mysql_error());
}





$ex=mysql_query("select id from today_contact where who='$mid' and whose='$from_id'");
if(mysql_num_rows($ex)==0)
{
mysql_query("insert into today_contact (who,whose,on_date) values ('$mid','$from_id',now())");
}
else
{
mysql_query("update today_contact set on_date=now() where who='$mid' and whose='$from_id'");
}
?>
</div>
</div>
</div>

Answer

You are mixing HTML and PHP code together.
You also forgot parentheses around the condition on the first line of this code fragment.

Change:

  if $ncha['p_no_contacts']-$ncha['r_cnt'] = 1
  {                                 
  <h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (
    <?php echo ($ncha['p_no_contacts']-$ncha['r_cnt']);?>) 
  </h1>
  }
  else
  {                                       
  <h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (

to:

<?php
  if ($ncha['p_no_contacts']-$ncha['r_cnt'] = 1)
  {
 ?>                             
  <h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (
    <?php echo ($ncha['p_no_contacts']-$ncha['r_cnt']);?>) 
  </h1>
 <?php
  }
  else
  {                                       
  ?>
  <h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (

Other important things:
- mysql_* functions in PHP are all deprecated, and removed from the last version of PHP (PHP 7). You should use mysqli_* or PDO functions instead
- it seems you are using unescaped variables in your queries. This is very insecure and may cause your code to fail, or be the target of SQL injections. Read How can I prevent SQL-injection in PHP? for more information.