Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 03-11-2009, 10:41 AM   #1 (permalink)
murdocsvan's Avatar
 
Ultra Techie

Join Date: Jun 2007

Location: Surrey, UK

Posts: 849

murdocsvan is on a distinguished road

Default PHP form

Recently i've been really getting into PHP and have been using W3Schools Online Web Tutorials as tutorials. Now im just experimenting a bit and combining what i know. JUST FOR A LAUGH(not a spambomb) i've made a form which can send out an email to a specified email address. I've also made it so that you can choose what your email address , and you can choose how many it sends.

I've now tried putting in a checkbox which allows the person doing it to randomise the email address it sends from. Howvee rim having loads of trouble trying to get this to work.

This is the HTML form:

Code:
<html>
<body>
<head>
<meta name="robots" content="noindex, nofollow" />
<meta name="robots" content="noarchive" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>:.:PHP Practise Work:.:</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<form action="form_result.php" method="post">
Email of recipiant: <input type="text" name="email" /><br />
Email of sender: <input type="text" name="semail" />
<input type="checkbox" name="random" value="random">Random?<br />

Number of emails to send: <input type="text" name="amount" /><br />
<input type="submit" value="Send" />
<input type="reset" value="Reset" />
</form>

</body>
</html>
And this is the form that the data gets sent to, using $_POST:

Code:
<?php

function = randomize()
	{
	if ($_POST["random"]="random")
		return rand(1,8) . "@" . rand(1,5) . ".com";
	else 
		return $_POST["semail"];
	}

$val=1;
while($val<=$_POST["amount"])
	{
	$to = $_POST["email"];
	$subject = "LOL";
	$message = "Ka-Pwned!!";
	$from = randomize();
	$headers = "From: $from";
	mail($to,$subject,$message,$headers);
	$val++;
	}
	
	
echo "Emails sent!";
	
?>
Whenever i've tried it, it submits, but then says it has a problem parsing on the 3rd line.
__________________

murdocsvan is offline  
Old 03-11-2009, 12:45 PM   #2 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default Re: PHP form

change

function = randomize()

to

function randomize()




it thinks you are assigning the output of randomize to the word function
office politics is offline  
Old 03-11-2009, 02:44 PM   #3 (permalink)
murdocsvan's Avatar
 
Ultra Techie

Join Date: Jun 2007

Location: Surrey, UK

Posts: 849

murdocsvan is on a distinguished road

Default Re: PHP form

Thanks a lot dude, this fixed it for me.
__________________

murdocsvan is offline  
Old 03-11-2009, 03:27 PM   #4 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,157

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: PHP form

I don't think you meant to do this either
Code:
if ($_POST["random"]="random")

__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is offline  
Old 03-11-2009, 05:42 PM   #5 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default Re: PHP form

Quote:
Originally Posted by kmote View Post
I don't think you meant to do this either
Code:
if ($_POST["random"]="random")
this should be ok.

random is a checkbox. if set, the value set in html is sent with the form data. otherwise this value will be empty.
office politics is offline  
Old 03-11-2009, 07:51 PM   #6 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: PHP form

Quote:
Originally Posted by office politics View Post
Quote:
Originally Posted by kmote View Post
I don't think you meant to do this either
Code:
if ($_POST["random"]="random")
this should be ok.

random is a checkbox. if set, the value set in html is sent with the form data. otherwise this value will be empty.
Code:
if ($_POST['random'] == true)
Should be like this.
__________________

Need website help? PM me!
CrazeD is offline  
Old 03-11-2009, 08:16 PM   #7 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default Re: PHP form

Quote:
Originally Posted by CrazeD View Post
Code:
if ($_POST['random'] == true)
Should be like this.
HTML Forms Input Type Checkbox

read value

Quote:
Here are the attributes to this input type

input * - tells the browser that this is part of the form

type * - tells the browser what input type it is

name * - when the form is submitted, this is the header the information in this field will go under

value * - this is what it the browser sends if that box is checked (can be anything)

checked - if this is included in the tag, when the page loads up it will already be checked

office politics is offline  
Old 03-11-2009, 11:00 PM   #8 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: PHP form

Quote:
Originally Posted by office politics View Post
Defining a value is optional.

PHP Code:
<?php

$check 
$_POST['checkbox'];

if (
$check == true) { echo 'true<br />'; }
if (
$check == 'on') { echo 'on<br />'; }
if (
$check) { echo '$check<br />'; }

echo 
'<br /><br /><form action="checkbox.php" method="post">
<input type="checkbox" name="checkbox" /><input type="submit" name="submit" value="submit" />
</form>'
;

?>
In this script, all of the if's work. If you give the checkbox a value, then you need to change == 'on' to the value.

In any case though, he only had one = when he should have had ==.
__________________

Need website help? PM me!
CrazeD is offline  
 
Closed Thread

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How echo works in PHP Osiris Programming Discussions 0 03-04-2009 08:34 AM
PHP - what it does and what it doesn’t Osiris Programming Discussions 1 02-16-2009 04:09 PM
Wev Development: How does PHP work? Osiris Programming Discussions 1 01-08-2009 04:31 PM
Looking for php form input and display script linux1880 Programming Discussions 3 06-03-2008 10:23 PM
Need PHP and JavaScript Form Validation Scripts aetherh4cker Programming Discussions 2 01-06-2008 04:16 PM