0

$POST['query'] is an AJAX used variable which is a search box value... $plan will be the exact plan of the search customer. Based on the $plan variable the URL's must change according to the if statements. However regardless of $plan being changed the URL remains the same for all as "planA"..

I need PHP to jump according to the $Plan variable and pick up the right URL.

Please Help me!!

$conn=mysqli_connect("localhost","****","****","*****"); 
$query = "SELECT * FROM `create_customer` WHERE `Customer Id` LIKE '{$_POST['query']}%' LIMIT 6";
$result = mysqli_query($conn, $query);
$plan = $user['Plan'];

 if ($plan = "planA") {
  
 while ($user = mysqli_fetch_array($result)) {
 
  echo "<h2>".$user['Customer Name']."</h2>";
  
  echo "<h4><a href='http://smjw.phatake.in/admin/cc.php?recordID=".$user['id']."'>Update Profile Details</a></h4>";
  
echo $user['Plan'];
  echo "<h4><a href='http://smjw.phatake.in/admin/planA_details.php?recordID=".$user['Customer Id']."'>Receive Payment</a></h4>";
  
 }

}
 
  if ($plan = "planB") {
 while ($user = mysqli_fetch_array($result)) {
 
  echo "<h2>".$user['Customer Name']."</h2>";
  
  echo "<h4><a href='http://smjw.phatake.in/admin/cc.php?recordID=".$user['id']."'>Update Profile Details</a></h4>";
  

  echo "<h4><a href='http://smjw.phatake.in/admin/planB_details.php?recordID=".$user['Customer Id']."'>Receive Payment</a></h4>";
  
 }
  }


      if ($plan = "planC") {
 while ($user = mysqli_fetch_array($result)) {
 
  echo "<h2>".$user['Customer Name']."</h2>";
  
  echo "<h4><a href='http://smjw.phatake.in/admin/cc.php?recordID=".$user['id']."'>Update Profile Details</a></h4>";
  

  echo "<h4><a href='http://smjw.phatake.in/admin/planC_details.php?recordID=".$user['Customer Id']."'>Receive Payment</a></h4>";
  
 } 
      }
 
 
           if ($plan = "planA1") {
 while ($user = mysqli_fetch_array($result)) {
 
  echo "<h2>".$user['Customer Name']."</h2>";
  
  echo "<h4><a href='http://smjw.phatake.in/admin/cc.php?recordID=".$user['id']."'>Update Profile Details</a></h4>";
  

  echo "<h4><a href='http://smjw.phatake.in/admin/planA1_details.php?recordID=".$user['Customer Id']."'>Receive Payment</a></h4>";
  
 } 
           
 
 
           }

 
else {
echo "<p style='color:red'>User not found...</p>";
}
16
  • 2
    You are using =. This is the assignment operator. Use ==. This is the comparison operator. For eg, in the code above, if($plan = "planA") should be if($plan == "planA"). Commented Mar 24, 2021 at 18:51
  • Now after updating the code to == the last else statement is being executed by default @KishenNagaraju Commented Mar 24, 2021 at 18:55
  • Have you changed in all if statements ? Commented Mar 24, 2021 at 19:03
  • Yes @KishenNagaraju Commented Mar 24, 2021 at 19:04
  • That means the $plan variable is containing value other than which is mentioned in the if statements. Print out the $plan variable and check what is the value coming in that ? Also check the value in the database for that user as well. Commented Mar 24, 2021 at 19:05

1 Answer 1

1

Rather than multiple very similar pieces of code you could simplify to be more generic. I should point out this is an untested idea and added here only to illustrate the comment I made previously.

So, rather then calling if ($plan = "planA") { - which is incorrect anyway as you need to use == to test for equality - you should be able to do like this.

Use a single endpoint to handle all different plans and use some method ( querystring in this instance ) to differentiate which plan is being called. Note that below planA_details.php (same for B,C,A1) is now simply plan_details.php so you can, within that file, use $_GET['plan'] to identify the plan selected. As with all user-supplied input care should be taken...

// previous & subsequent code remains "as-was"

$plan = $user['Plan'];

if( in_array( $plan, array('planA','planB','planC','planA1') ) ){
    
    while( $user=mysqli_fetch_array( $result ) ){
        $letter=str_replace('plan','',$plan);
        printf('
            <h2>%s</h2>
            <h4><a href="//smjw.phatake.in/admin/cc.php?recordID=%s">Update Profile Details</a></h4>
            <h4><a href="//smjw.phatake.in/admin/plan_details.php?recordID=%s&plan=%s">Receive Payment</a></h4>',
            $user['Customer Name'],
            $user['id'],
            $user['Customer Id'],
            $letter
        );
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.