Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[NEED HELP] PHP Form post, get, echo
#1
Hey guys. I ran into some trouble with some PHP and I need some help.
If anyone is experienced with this, please add my contact info because I need help ASAP.

AIM: kthfhdf1901
Skype: kthfhdf1901

If you can help me I'd even be willing to pay a little.

I basically need to capture the data from four text fields and echo it into a URL. From my understanding it can easily be done by someone who knows PHP.

Thanks!
Reply
#2
PHP Code:
<?PHP
if(isset($_POST['go'])){
$text1 $_POST['text1'];
$text2 $_POST['text2'];
$text3 $_POST['text3'];
$text4 $_POST['text4'];
header("location: page.php?VAR1=$text1&VAR2=$text2&VAR3=$text3&VAR4=$text4");
}
?>
<form action='' METHOD='POST'>
Text1: <input type='text' name='text1'>
<br>
Text2: <input type='text' name='text2'>
<br>
Text3: <input type='text' name='text3'>
<br>
Text4: <input type='text' name='text4'>
<br>
<input type='submit' name='go' Value='go'>
</form> 
[Image: cooldude.png]

(09-05-2011, 08:36 AM)Orgy Wrote: If you understand what you're doing, you aren't learning anything. ;)
Reply
#3
(12-22-2011, 07:00 AM)★Cooldude★ Wrote:
PHP Code:
<?PHP
if(isset($_POST['go'])){
$text1 $_POST['text1'];
$text2 $_POST['text2'];
$text3 $_POST['text3'];
$text4 $_POST['text4'];
header("location: page.php?VAR1=$text1&VAR2=$text2&VAR3=$text3&VAR4=$text4");
}
?>
<form action='' METHOD='POST'>
Text1: <input type='text' name='text1'>
<br>
Text2: <input type='text' name='text2'>
<br>
Text3: <input type='text' name='text3'>
<br>
Text4: <input type='text' name='text4'>
<br>
<input type='submit' name='go' Value='go'>
</form> 

If you would like to modify the URL on form submit, you must use the GET method in your forms. However you must always ensure you apply sanitisation upon said $_GET['']; variables to prevent SQL injections on your website. Here is an example on how to build a custom URL using the GET method from a form:

PHP Code:
<?php
if(isset($_GET['action']))
{
    
$submit $_GET['action'];
    
$phone_number intval($_GET['phone_number']);
    if(
$phone_number)
    {
        
//continue with form submittion
    
}
    else
    {
            die(
'phone number is not numerical');
    }
}
?>

<html>
<body>
<form method="GET">
Phone Number: <input type="text" name="phone_number" /><br />
<input type="submit" name="action" value="submit" />
</form>
</body>
</html> 
On form submit, this should give the URL:
get.php?phone_number=(number_here)&action=submit

A very basic, yet secure URL that is not susceptible to SQL injection attacks because i have made sure that if the phone number being entered is not numerical, the page will output an error only. This is done by using the function intval upon the phone number entered in the form, and if the function returns false, a NULL value is given to $phone_number causing the next IF statement to return FALSE.
Reply
#4
^Why not use integer typecasting?
[Image: cooldude.png]

(09-05-2011, 08:36 AM)Orgy Wrote: If you understand what you're doing, you aren't learning anything. ;)
Reply
#5
Type casting will give the exact same result. Its just the way i like to do things.
PHP Code:
$id intval($_GET['id']);
//is the equivalent of type casting: 
$id = (int) $_GET['id']; 
Reply
#6
^There's less typing required for typecasting, but okay. Tongue
[Image: cooldude.png]

(09-05-2011, 08:36 AM)Orgy Wrote: If you understand what you're doing, you aren't learning anything. ;)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP Framework List: An Ultimate Guide to 102 PHP Frameworks for Web Developers tk-hassan 0 941 07-27-2020, 11:26 PM
Last Post: tk-hassan
  PHP echo contents of folder help DAMINK™ 3 1,248 06-01-2012, 04:07 PM
Last Post: DAMINK™
  PHP email input form - having trouble getting the form to work... abayindi 4 2,733 03-19-2012, 10:02 AM
Last Post: RainbowDashFTW
  How to make a form. HB Virus 10 3,634 12-30-2011, 08:03 PM
Last Post: BreShiE
  PHP Video Tutorials (PHP For Beginners) Eleqtriq 4 3,667 10-10-2011, 01:00 PM
Last Post: Greyersting

Forum Jump:


Users browsing this thread: 1 Guest(s)