Jump to content

If condition for moving to another page

- - - - -

  • Please log in to reply
7 replies to this topic

#1
newphpcoder

newphpcoder

    Programming Professional

  • Members
  • PipPipPipPipPipPip
  • 479 posts
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

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
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
  • Location:New York, NY
You need an <input type="submit" /> before you close your </form>, so users can submit the form.

#3
newphpcoder

newphpcoder

    Programming Professional

  • Members
  • PipPipPipPipPipPip
  • 479 posts

John said:

You need an <input type="submit" /> before you close your </form>, so users can submit the form.

I tried this code:

<?php

include ("config.php");


//ob_start();

//header ('Location:incoming.php'); 

if (isset($_POST['call_type'])) { // Check if form has been submitted

$call_type = mysql_real_escape_string($_POST['call_type']); // SECURE THE FECKING CONTENT!!!!!!!!!!!!!!!!!!!!!!


echo $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);

echo '<br />' . $result;

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>

  

  <input type="submit" name = "Submit" value="Submit">

</form>

</body>

</html>


And when I choose Incoming and I press submit button the output is:
Incoming
1
Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\OJT\mae_ann\index.php:9) in D:\xampp\htdocs\OJT\mae_ann\index.php on line 17

Thank you

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
You cannot echo anything before you send a header. See PHP forums FAQ about headers already sent errors.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
newphpcoder

newphpcoder

    Programming Professional

  • Members
  • PipPipPipPipPipPip
  • 479 posts
I remove this code:

if ($result == 1){


if($call_type == 'Incoming'){

    header ('Location:incoming.php');

}

elseif($call_type == 'Outgoing'){

    header ('Location:outgoing.php');

}

else{

    header('Location:index.php');

}

}


And the warning was remove and Incoming 1 was appear but with the same page. I want to happen is when I choose Incoming and I press submit it will go to the incomiong.php

Thank you

#6
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
You were fine before, I meant remove the echo, you are printing to the screen before you call header() which is not allowed. Try that.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#7
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
also, your action attribute to the form tag is empty...
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#8
newphpcoder

newphpcoder

    Programming Professional

  • Members
  • PipPipPipPipPipPip
  • 479 posts
I tried this code:


<?php 

include ("config.php"); 


$call_type = mysql_real_escape_string($_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" 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> 


What code shoud i put on form?

I only wnat is if I choose Incoming in select option and I press Submit button it will redirect to incoming.php and If I choose outgoing it will go to outgoing.php

Thank you so much




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users