Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   If condition for moving to another page (http://www.go4expert.com/forums/condition-moving-page-t25206/)

newphpcoder 10Mar2011 12:06

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

shabbir 10Mar2011 12:09

Re: If condition for moving to another page
 
On selecting the option you need to make the JS code to submit the page.

newphpcoder 10Mar2011 12:45

Re: If condition for moving to another page
 
Quote:

Originally Posted by shabbir (Post 80477)
On selecting the option you need to make the JS code to submit the page.

I'm not familiar with js

Thank you

newphpcoder 10Mar2011 13:43

Re: If condition for moving to another page
 
Quote:

Originally Posted by John (Post 295547)
You need an <input type="submit" /> before you close your </form>, so users can submit the form.

I tried this code:
PHP 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


All times are GMT +5.5. The time now is 15:51.