Page 3 of 3 FirstFirst 123
Results 21 to 27 of 27

Thread: If condition for moving to another page

  1. #21
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    you need to remove the " incoming.php " part.
    The variable call_type should hold either the word "incoming" or "outgoing" at this point.

    PHP Code:
    header("Location: http://localhost/OJT/mae_ann/".$call_type.".php"); 

  2. #22
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by traq View Post
    you need to remove the " incoming.php " part.
    The variable call_type should hold either the word "incoming" or "outgoing" at this point.

    PHP Code:
    header("Location: http://localhost/OJT/mae_ann/".$call_type.".php"); 
    I tried the code you suggested:
    PHP Code:
    <?php
      
    include ("config.php");   

    if (isset(
    $_POST['call_type'])) {   
      
    // escape the value   
      
    $call_type mysql_real_escape_string($_POST['call_type']);   
      
    // query the database 
      
    $result mysql_query("SELECT `call_type` FROM `tbl_calltype` WHERE `call_type` = '{$call_type}' ");   
      
    // if there's one row in the result, then there was a match.   
      
    if(mysql_num_rows($result) === 1){   
        
    // send the header()   
    //here I got confused because i dont know what location should i put is it incoming.php or outgoing.php, but when I tried this code nothig was happened.  

    // at this point, since we've gotten a match from the database,  
    // we know that the variable 'call_type' holds a value of either "incoming" or "outgoing", 
    // so we use the variable instead of hard-coding the filename. 

        
    header("Location: http://localhost/OJT/mae_ann/".$call_type.".php");     
      }
      
    //else{ header("Location: http://localhost/OJT/mae_ann/outgoing.php"); }  
    }  
    ?>
    <html>  
    <body>  
    <form id="form1" name="form1" method="post" action="">  
      <select name="call_type" onchange="return handleEnter(this, event)">  
        <option value="Select Call Type">Select Call Type</option>  
        <option value="Incoming" <?php if($_POST['call_type'] == 'Incoming') echo "selected='selected'"?>>Incoming</option>  
        <option value="Outgoing" <?php if($_POST['call_type'] == 'Outgoing') echo "selected='selected'"?>>Outgoing</option>  
      </select>  
        <input type="submit" name = "Submit" value="Submit"> 
    </form>  
    </body>  
    </html>
    And the output is still it did not go to incoming.php when I choose incoming .
    :confused:

    Thank you

  3. #23
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    hmm... where is it going? do you get a 404? do you get anything?

    does this work?
    PHP Code:
    header("Location: http://localhost/OJT/mae_ann/incoming.php"); 
    ?
    try this
    PHP Code:
    print call_type
    so we can see if the value is getting passed on correctly.

  4. #24
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by traq View Post
    hmm... where is it going? do you get a 404? do you get anything?

    does this work?
    PHP Code:
    header("Location: http://localhost/OJT/mae_ann/incoming.php"); 
    ?
    try this
    PHP Code:
    print call_type
    so we can see if the value is getting passed on correctly.
    this code:
    PHP Code:
    header("Location: http://localhost/OJT/mae_ann/incoming.php"); 
    did not work and when i print $call_type
    no output was display

    Thank you

  5. #25
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    try this and let me know what it tells you.

    PHP Code:
    <?php 

    include ("config.php");

    if(isset(
    $_POST['call_type'])){
        
    $call_type mysql_real_escape_string($_POST['call_type']);
        
    $result mysql_query("SELECT `call_type` FROM `tbl_calltype` WHERE `call_type` = '{$call_type}' ");
        if(!
    $result){ print 'the query did not execute properly: '.mysql_error().'<br>'; }

    // if the line below doesn't work, try commenting it out and using the commented line instead
        
    if(mysql_num_rows($result) === 1){
    //    if(mysql_num_rows($result) > 0){

            
    header("Location: http://localhost/OJT/mae_ann/".$call_type.".php");
        }else{
            
    var_dump($call_type);
        }
    }else{ print 
    '$_POST[call_type] is not set<br>'; }

    ?> 
    <html>
    <head>
    </head>
    <body>   
    <form id="form1" name="form1" method="post" action="">   
      <select name="call_type" onchange="return handleEnter(this, event)">   
        <option value="Select Call Type">Select Call Type</option>   
        <option value="incoming">Incoming</option>   
        <option value="outgoing">Outgoing</option>   
      </select>   
      <input type="submit" name = "Submit" value="Submit">  
    </form>   
    </body>   
    </html>

  6. #26
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by traq View Post
    try this and let me know what it tells you.

    PHP Code:
    <?php 

    include ("config.php");

    if(isset(
    $_POST['call_type'])){
        
    $call_type mysql_real_escape_string($_POST['call_type']);
        
    $result mysql_query("SELECT `call_type` FROM `tbl_calltype` WHERE `call_type` = '{$call_type}' ");
        if(!
    $result){ print 'the query did not execute properly: '.mysql_error().'<br>'; }

    // if the line below doesn't work, try commenting it out and using the commented line instead
        
    if(mysql_num_rows($result) === 1){
    //    if(mysql_num_rows($result) > 0){

            
    header("Location: http://localhost/OJT/mae_ann/".$call_type.".php");
        }else{
            
    var_dump($call_type);
        }
    }else{ print 
    '$_POST[call_type] is not set<br>'; }

    ?> 
    <html>
    <head>
    </head>
    <body>   
    <form id="form1" name="form1" method="post" action="">   
      <select name="call_type" onchange="return handleEnter(this, event)">   
        <option value="Select Call Type">Select Call Type</option>   
        <option value="incoming">Incoming</option>   
        <option value="outgoing">Outgoing</option>   
      </select>   
      <input type="submit" name = "Submit" value="Submit">  
    </form>   
    </body>   
    </html>
    When i run this code this is the output:

    $_POST[call_type] is not set

    And when I choose incoming, Finally I redirected to incoming.php

    Thank you

  7. #27
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    glad it worked! just FYI, the following lines are solely for testing purposes and can/should be commented or removed:

    PHP Code:
    if(!$result){ print 'the query did not execute properly: '.mysql_error().'<br>'; } 
    PHP Code:
    else{
            
    var_dump($call_type);
        } 
    PHP Code:
    // if the line below doesn't work, try commenting it out and using the commented line instead 
    //    if(mysql_num_rows($result) > 0){ 
    PHP Code:
    else{ print '$_POST[call_type] is not set<br>'; } 

  8. The Following User Says Thank You to traq For This Useful Post:

    rhodarose (03-22-2011)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •