46 users online (0 members and 46 guests)  


  Results 1 to 2 of 2

Related

  1. Question about if condition    Forum: PHP Forum
    Replies: 2
  2. Confused in using if condition    Forum: PHP Forum
    Replies: 0
  3. Replies: 2
  4. Moving Site (maybe)    Forum: Graphics Forum
    Replies: 1
  5. moving navigation bar    Forum: Website Scripts Forum
    Replies: 1
  1. #1
    newphpcoder's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Sep 2010
    Posts
    52

    If condition for moving to another page

    Good day!

    I want to know what is wrong in my code that's why when i choose in select option it did not go to another page...Like when I select "Incoming" nothing happen also when I choose "Outgoing" nothing also happen.

    Here is my code:

    PHP Code:
    <?php
    include ("config.php");

    $call_type $_POST['call_type'];

    $query=mysql_query("SELECT `call_type` FROM `tbl_calltype` WHERE `call_type` = '{$call_type}'") or die(mysql_error());
    $result mysql_num_rows($query);

    if (
    $result == 1){

    if(
    $call_type == 'Incoming'){
        
    header ('Location:incoming.php');
    }
    elseif(
    $call_type == 'Outgoing'){
        
    header ('Location:outgoing.php');
    }
    else{
        
    header('Location:index.php');
    }
    }
    ?>
    <html>
    <body>
    <form id="form1" name="form1" method="post" action="">
      <select name="call_type">
        <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>
    </form>
    </body>
    </html>
    Thank you

  2. #2
    hairtreatment's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2011
    Posts
    8

    Re: If condition for moving to another page

    <?php
    include ("config.php");

    $call_type = $_POST['call_type'];

    $query=mysql_query("SELECT `call_type` FROM `tbl_calltype` WHERE `call_type` = '{$call_type}'") or die(mysql_error());
    $result = mysql_num_rows($query);

    if ($result == 1){

    if($call_type == 'Incoming'){
    header ('Location:incoming.php');
    }
    elseif($call_type == 'Outgoing'){
    header ('Locationutgoing.php');
    }
    else{
    header('Location:index.php');
    }
    }
    ?>
    <html>
    <body>
    <form id="form1" name="form1" method="post" action="">
    <select name="call_type">
    <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>
    </form>
    </body>
    </html>
    Replace that code.

    <?php
    $call_type = $_POST['call_type'];
    if(isset($call_type))
    {
    if($call_type == 'Incoming')
    header('Location: incoming.php');
    else if($call_type == 'Outgoing')
    header('Location: outgoing.php');
    else
    header('Location: index.php');
    }
    else
    header('Location: index.php');
    ?>
    No need to call the mysql query. you are coding a dynamic script.
    Last edited by HTML; 04-29-2011 at 06:03 AM.