Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
If condition for moving to another page
Old 03-10-2011, 01:30 AM If condition for moving to another page
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
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
newphpcoder is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-11-2011, 06:52 PM Re: If condition for moving to another page
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
There's nothing in your current code to submit the form - but better still, add an onChange handler to the SELECT tag. Not sure why you have a db query. And always put an exit() after header calls.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 03-13-2011, 09:54 PM Re: If condition for moving to another page
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
Quote:
Originally Posted by PaulW View Post
There's nothing in your current code to submit the form - but better still, add an onChange handler to the SELECT tag. Not sure why you have a db query. And always put an exit() after header calls.

I tried this code:
PHP 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'); 
    exit();

elseif(
$call_type == 'Outgoing'){ 
    
header ('Location:outgoing.php'); 
    exit();

else{ 
    
header('Location:index.php'); 
    exit();


?> 

<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>
I add submit button and I put onchange and I also add exit() after header location but when I run my code and I choose Incoming and I click submit button nothing was change, i mean it did not go to incoming.php


Thank you...
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 03-13-2011, 10:09 PM Re: If condition for moving to another page
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
You've set it to go to a javascript function - good. Where have you defined that function?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 03-13-2011, 10:21 PM Re: If condition for moving to another page
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
I put function but it did not work again..
PHP Code:
<?php 

include ("config.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!!!!!!!!!!!!!!!!!!!!!! 
$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> 
<script type="text/javascript">                
function handleEnter (field, event) {
        var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
        if (keyCode == 13) {
            var i;
            for (i = 0; i < field.form.elements.length; i++)
                if (field == field.form.elements[i])
                    break;
            i = (i + 1) % field.form.elements.length;
            field.form.elements[i].focus();
            return false;
        } 
        else
        return true;
    }      
</script>
<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>
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 03-14-2011, 06:06 AM Re: If condition for moving to another page
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
Okay, simpler method:

Code:
<form name=testform">
<select name="id" onchange="window.location=(this.options[this.selectedIndex].value +'.html')">
 <optgroup label="pages">
  <option value="thispage">select</option>
  <option value="aaaa">go to page a</option>
  <option value="bbbb">go to page b</option>
 </optgroup>
</select>
</form>
This assumes we have three .html pages, thispage, aaaa and bbbb - so the values on the select match the page names. Note: no submit button needed in this method.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE

Last edited by PaulW; 03-14-2011 at 06:09 AM..
PaulW is online now
Reply With Quote
View Public Profile
 
Old 03-16-2011, 08:32 PM Re: If condition for moving to another page
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
Quote:
Originally Posted by PaulW View Post
Okay, simpler method:

Code:
<form name=testform">
<select name="id" onchange="window.location=(this.options[this.selectedIndex].value +'.html')">
 <optgroup label="pages">
  <option value="thispage">select</option>
  <option value="aaaa">go to page a</option>
  <option value="bbbb">go to page b</option>
 </optgroup>
</select>
</form>
This assumes we have three .html pages, thispage, aaaa and bbbb - so the values on the select match the page names. Note: no submit button needed in this method.
I'm not using .html I used .php file....
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 03-17-2011, 05:39 AM Re: If condition for moving to another page
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
In the select tag change '.html' to '.php'
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 03-21-2011, 04:31 AM Re: If condition for moving to another page
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
Quote:
Originally Posted by PaulW View Post
In the select tag change '.html' to '.php'


thank you
newphpcoder is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to If condition for moving to another page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.74899 seconds with 12 queries