-3

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>
Sabha
  • 621
  • 10
  • 32
  • 3
    So what, you're asking how to do an [if](http://php.net/if)? – Jonnix Jun 20 '16 at 15:02
  • yes.. i have tried but i guess syntax is going wrong may be issues with brace brackets or commands within the syntax itself. Unhappy to see a downvote :( I know the logic but not understanding the syntax. – Sabha Jun 20 '16 at 15:04
  • 1
    Well we can't help you if you don't provide something we can help with. The downvote is probably because you're effectively asking for us to do this work for you. – Jonnix Jun 20 '16 at 15:06
  • With help from users out here, google research and php documentation, I have somehow managed to complete the code but struggling at couple of places. I have provided what I have done so far and i also know what is to be done because i have understood the variable and know the logic. The problem is putting things into place with correct syntax. – Sabha Jun 20 '16 at 15:11
  • Right? So _try_ first, then if you get stuck / hit a problem you can't resolve _yourself_ first, then ask a question on SO, but provide what you've done yourself to get towards your goal, what issues you've hit and any error messages. You've not provided any sort of attempt yet. We can't help put your syntax right if you don't provide the syntax you've tried. – Jonnix Jun 20 '16 at 15:14
  • You should read this first. http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php Don’t use mysql_* functions if You don’t have a very good reason. – Michas Jun 20 '16 at 15:56
  • Yes I know about the sqli and pdo alternatives and i am going to convert everything later once the project is bug free. – Sabha Jun 20 '16 at 18:16
  • I have edited my question and shown you guys what I did. Please help me with correct syntax. Thanks – Sabha Jun 20 '16 at 18:16

2 Answers2

1

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.

Community
  • 1
  • 1
Jocelyn
  • 11,209
  • 10
  • 43
  • 60
  • Got it! I was able to bypass the first condition using your suggestion but now it show error `Parse error: syntax error, unexpected ';' in /home/abc/public_html/chk/contact.php on line 105` and line 105 is `$dele="delete from payments where (pemail='$mid' or pmatri_id='$mid')";` I had also missed parenthesis which I corrected in the line `If $inc1 = $ncha['p_no_contacts']` just two lines above the error line. Please give me some idea how to solve this. Thanks ! – Sabha Jun 21 '16 at 04:20
  • I updated my answer. – Jocelyn Jun 21 '16 at 07:32
  • sorry but i did not understand. If you see my original code that i posted, there are issues in two parts, the first part is now fine with your kind help. I am getting proper echo statements. The issues now is in the second part. if you scroll down in my code, you will see a delete query in `if` statement and update query in `else` statement <<`If $inc1 = $ncha['p_no_contacts']`>>. I am getting an error here that I mentioned my above comment. the delete query is line no. 105. And yes, I am going to look for pdo / sqli alternatives later. – Sabha Jun 21 '16 at 08:02
  • I got the answer to my above comment. Thanks for your help ! – Sabha Jun 23 '16 at 08:10
0

I got the answer. By mistake I added a parenthesis instead of brace bracket in the second line of the below code. Phew! It took me almost two days to figure this out. Thanks @Jocelyn for your kind assistance.

        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());
        }
Sabha
  • 621
  • 10
  • 32