Forum Topic: Simple script help!

(148 views • 20 replies)

This topic is 1 page long.

<< < > >>
Questioning

TheDoodleTwins

Reply To Post Reply & Quote

Posted at: 7/17/06 03:05 PM

TheDoodleTwins LIGHT LEVEL 07

Sign-Up: 06/23/06

Posts: 483

In response to gamesCool saying i should make a thread about this so somone may help, here it is!

Im having trouble with a realy simple thing!

I have 2 files, 1 with a form in with 1 text box called "name" and the form leads to testCreate.php

In testCreate.php is the script i just created of the top of my head, which is why i think it wont work xD

<?php
if($_POST['submit']){
$name = $_POST['name'];
if ($name == ""){
echo "You did not enter anything into the name feild.";
}
}
?>

Does anyone know whats wrong with it! Its probly somthing realy simple like i forgot a character or somthing.


None

DFox

Reply To Post Reply & Quote

Posted at: 7/17/06 03:07 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,270

Wait so what's wrong? What happens when you run this?


None

elbekko

Reply To Post Reply & Quote

Posted at: 7/17/06 03:07 PM

elbekko EVIL LEVEL 16

Sign-Up: 07/23/04

Posts: 6,450

if($_POST['submit']){
should be
if(isset($_POST['submit'])){

"My software never has bugs. It just develops random features. " - Unknown

[ PHP: Main | Omigod, a blog ]

BBS Signature

None

SummerCity

Reply To Post Reply & Quote

Posted at: 7/17/06 03:11 PM

SummerCity LIGHT LEVEL 09

Sign-Up: 12/08/04

Posts: 696

Nope, still doesent work, and its ment to do this,

When somone clicks submit on the form.php page and hasent entered anything into the name feild! it activates: echo "You did not enter anything into the name feild.";


None

DFox

Reply To Post Reply & Quote

Posted at: 7/17/06 03:13 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,270

Is the name of your submit button on the form page "submit"?


None

WoogieNoogie

Reply To Post Reply & Quote

Posted at: 7/17/06 03:16 PM

WoogieNoogie LIGHT LEVEL 14

Sign-Up: 06/26/05

Posts: 3,195

Does your form have the method attribute equal to "POST"?


None

TheDoodleTwins

Reply To Post Reply & Quote

Posted at: 7/17/06 03:36 PM

TheDoodleTwins LIGHT LEVEL 07

Sign-Up: 06/23/06

Posts: 483

To answer both your questions, yes! its set to post and the button is called submit


None

DFox

Reply To Post Reply & Quote

Posted at: 7/17/06 03:39 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,270

At 7/17/06 03:36 PM, GwenTheDoodle wrote: To answer both your questions, yes! its set to post and the button is called submit

Can you post the form please?


None

CyberLemming

Reply To Post Reply & Quote

Posted at: 7/17/06 03:44 PM

CyberLemming EVIL LEVEL 05

Sign-Up: 08/09/05

Posts: 224

if($_POST['submit'])
should be
if ($_POST[(nameofsubmitbutton)] == '(valueofsubmitbutton)')


None

DFox

Reply To Post Reply & Quote

Posted at: 7/17/06 03:46 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,270

At 7/17/06 03:44 PM, CyberLemming wrote: if($_POST['submit'])
should be
if ($_POST[(nameofsubmitbutton)] == '(valueofsubmitbutton)')

No, it doesn't have to be. I don't think that's the problem as if(isset($_POST['submit'])) or if($_POST['submit']) should work just fine.


None

TheDoodleTwins

Reply To Post Reply & Quote

Posted at: 7/17/06 03:51 PM

TheDoodleTwins LIGHT LEVEL 07

Sign-Up: 06/23/06

Posts: 483

Still dont work, now you see why im having trouble with what should be a simple script!


None

DFox

Reply To Post Reply & Quote

Posted at: 7/17/06 03:52 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,270

At 7/17/06 03:51 PM, GwenTheDoodle wrote: Still dont work, now you see why im having trouble with what should be a simple script!

If you post the form I'm sure we can spot the problem.


None

TheDoodleTwins

Reply To Post Reply & Quote

Posted at: 7/17/06 03:55 PM

TheDoodleTwins LIGHT LEVEL 07

Sign-Up: 06/23/06

Posts: 483

Here is the form!#

<form method="post" action="testCreate.php">

<div align="center">
<input name="name" type="text" maxlength="14" />
</div>
<p align="center">
<input type="submit" name="submit" value="Join" />
</p>
</form>


Shouting

CyberLemming

Reply To Post Reply & Quote

Posted at: 7/17/06 03:56 PM

CyberLemming EVIL LEVEL 05

Sign-Up: 08/09/05

Posts: 224

At 7/17/06 03:46 PM, GamesCool wrote: No, it doesn't have to be. I don't think that's the problem as if(isset($_POST['submit'])) or if($_POST['submit']) should work just fine.

at the risk of sounding retarded:
"O RLY?"

create test.php:

<?php
var_dump($_POST);
?>
<form method="post">
<input type="text" name="OMG" value="WTF" />
<input type="submit" name="ROFL" value="LOL" />
</form>

load it up in a browser, and hit LOL.
=)


None

DFox

Reply To Post Reply & Quote

Posted at: 7/17/06 03:58 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,270

So if you enter nothing in the name field, it's not showing that message?


None

CyberLemming

Reply To Post Reply & Quote

Posted at: 7/17/06 04:04 PM

CyberLemming EVIL LEVEL 05

Sign-Up: 08/09/05

Posts: 224

*copies form*

and when:

<?php
var_dump($_POST);
?>
<form method="post">
<div align="center">
<input name="name" type="text" maxlength="14" />
</div>
<p align="center">
<input type="submit" name="submit" value="Join" />
</p>
</form>

result of hitting Join without entering anything:

array(2) { ["name"]=> string(0) "" ["submit"]=> string(4) "Join" }

=)


None

cherries

Reply To Post Reply & Quote

Posted at: 7/17/06 04:13 PM

cherries LIGHT LEVEL 18

Sign-Up: 06/07/05

Posts: 4,561

<form action="testicals.php">
<input type="text" name="author" /><br/>
<input type="submit" value="I suck" />
</form>

Test.php:
<?
$author = $_POST['author'];
if (strlen($author) == 0) {
die('No name j00 fewl');
}
?>


None

TheDoodleTwins

Reply To Post Reply & Quote

Posted at: 7/17/06 04:54 PM

TheDoodleTwins LIGHT LEVEL 07

Sign-Up: 06/23/06

Posts: 483

Okay! non of them work, but here! dos anyone get why this wouldent wont work!

When somone clicks submit its ment to just activate the script in this code? But it does nothing!

<?php
if ($_POST[(Submit)] == '(Submit)'){
$filename="words.txt";
$words=file($filename);
shuffle($words);
$word=$words[0];
echo $word;
}
?>
<form id="form1" name="form1" method="post" action="random.php">
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</form>


None

DFox

Reply To Post Reply & Quote

Posted at: 7/17/06 05:19 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,270

At 7/17/06 04:54 PM, GwenTheDoodle wrote: <?php
if ($_POST[(Submit)] == '(Submit)'){
$filename="words.txt";
$words=file($filename);
shuffle($words);
$word=$words[0];
echo $word;
}
?>

Should be:
<?php
if (isset($_POST['Submit'])){
$filename="words.txt";
$words=file($filename);
shuffle($words);
$word=$words[0];
echo $word;
}
?>


None

Jordan

Reply To Post Reply & Quote

Posted at: 7/18/06 10:20 AM

Jordan DARK LEVEL 14

Sign-Up: 04/23/06

Posts: 2,837

*cough* are you sure your uploading the php files to a server that supports php?


None

CyberLemming

Reply To Post Reply & Quote

Posted at: 7/18/06 01:02 PM

CyberLemming EVIL LEVEL 05

Sign-Up: 08/09/05

Posts: 224

At 7/17/06 04:54 PM, GwenTheDoodle wrote: <?php
if ($_POST[(Submit)] == '(Submit)'){
$filename="words.txt";
$words=file($filename);
shuffle($words);
$word=$words[0];
echo $word;
}
?>
<form id="form1" name="form1" method="post" action="random.php">
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</form>

!!!!
the brackets weren't meant to be taken literally!
jesus...
so like so:

<?php
if ($_POST['Submit'] == 'Submit'){
$filename="words.txt";
$words=file($filename);
shuffle($words);
$word=$words[0];
echo $word;
}
?>

All times are Eastern Standard Time (GMT -5) | Current Time: 08:35 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!