Jump to content

I have a problem, not sure what kind cuz it's confusing, but i need help.


yakoup46

Recommended Posts

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">

<html>

 

<head>

<title></title>

</head>

<body>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

First name: <input type="text" name="first_name"><br>

Last name: <input type="text" name="last_name" style="position: relative; left: 1px;">

<input type="submit" value="Submit">

</form>

<?php

$first = @$_POST['first_name'];

$last = @$_POST['last_name'];

$charecter = array("is gay", "is cool", "is a funny", "is a wierdo", "is just dumb");

$doing =  array("farts alot", "runs in circles", "...", "and loves strawberry shortcake");

$number = range('0','9');

$test = ($number[rand(0,9)]) . ($number[rand(0,9)]);

 

if(!empty($first) && ($last))

echo $first . " " . $last . " " . $charecter[rand(0,4)] . " and " . $doing[rand(0,3)] . "<br /> Lucky Number: " . $test . ".";

 

if($test < 99 && $test > 50)

echo "That is a great number!";

 

?>

 

</body>

</html>

 

So my problem is that when i load the page a number is immediately generated before i press submit and the echo "that is a great number" may show up before i press submit because it is as if the random number was generated before i pressed submit. So what i am asking is can i make the script wait until i press submit before it decides whether or not it is a lucky number?

Link to comment
Share on other sites

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>

   <head>
      <title></title>
   </head>
   <body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
First name: <input type="text" name="first_name"><br>
Last name: <input type="text" name="last_name" style="position: relative; left: 1px;">
<input type="submit" value="Submit">
</form>
<?php

$first = $_POST['first_name'];
$last = $_POST['last_name'];
$charecter = array("is gay", "is cool", "is a funny", "is a wierdo", "is just dumb");
$doing =  array("farts alot", "runs in circles", "...", "and loves strawberry shortcake");
$number = range('0','9');
$test = ($number[rand(0,9)]) . ($number[rand(0,9)]);

if($_POST['submit'])
{
    if(!empty($first) && ($last))
    {
        echo $first . " " . $last . " " . $charecter[rand(0,4)] . " and " . $doing[rand(0,3)] . "<br /> Lucky Number: " . $test . ".";
    }

    if($test < 99 && $test > 50)
    {
        echo "That is a great number!";    
    }
}

?>

Link to comment
Share on other sites

Put your random generator in to a function call it what ever you like and the you need to change your sumbit button to call that function

 

Soo

 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

 

Turns into

 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return yourfunction();">

 

function yourfunction () {
    if(!empty($first) && ($last))
    {
        echo $first . " " . $last . " " . $charecter[rand(0,4)] . " and " . $doing[rand(0,3)] . "<br /> Lucky Number: " . $test . ".";
    }

    if($test < 99 && $test > 50)
    {
        echo "That is a great number!";    
    }
}

Link to comment
Share on other sites

Still nothing it returns blank. I did exactly everything you said. I even copied exactly what you had into a new document and still nothing. ???

 

Question for you the other guy before me change your

 

$first = @$_POST['first_name'];
$last = @$_POST['last_name'];

 

to

 

$first = $_POST['first_name'];
$last = $_POST['last_name'];

 

did you keep that change and you might want to try a $_REQUEST instead of post

 

or and just saw this

 

function yourfunction () {
    if(!empty($first) && ($last))

 

Should be

 

function yourfunction () {
    if(empty($first) && ($last))

Link to comment
Share on other sites

still nothing. and when i remove the @ i get the stupid 'Undefined index' error.

 

I almost got it and then my damn server failed but this will get you way start

 

Pretty much it only checks to see if the first name is filled in not first and last

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>

   <head>
      <title></title>
   </head>
   <body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
First name: <input type="text" name="first_name"><br>
Last name: <input type="text" name="last_name" style="position: relative; left: 1px;">
<input type="submit" value="Submit">
</form>
<?php
$first = @$_POST['first_name'];
$last = @$_POST['last_name'];
$charecter = array("is gay", "is cool", "is a funny", "is a wierdo", "is just dumb");
$doing =  array("farts alot", "runs in circles", "...", "and loves strawberry shortcake");
$number = range('0','9');
$test = ($number[rand(0,9)]) . ($number[rand(0,9)]);

if(empty($first))

echo "Please Enter Your First and Last Name";

elseif($first=$first)

echo $first . " " . $last . " " . $charecter[rand(0,4)] . " and " . $doing[rand(0,3)] . "<br /> Lucky Number: " . $test . ".";

elseif($test < 99 && $test > 50)

echo "That is a great number!";

?>

   </body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.