Web Hosting Talk







View Full Version : (PHP) Script Help


kmb999
11-10-2001, 09:19 AM
I'm trying to create a form using php (I'm just learning php). I wanted to know what I should enter into the script so that when users submit the form their IPs and the current time and date are automatically logged and submited with the form.

Dahlia
11-10-2001, 10:42 AM
you could try this:

<?php
$time = date("H:i");
$date = date("m-d-y");
?>

<input type="hidden" name="ipaddress" value="<?php echo $HTTP_SERVER_VARS["REMOTE_ADDR"] ?>">
<input type="hidden" name="date" value="<?php echo $date ?>">
<input type="hidden" name="time" value="<?php echo $time ?>">


you can find time and date values at the php.net site (http://www.php.net/manual/en/function.date.php), so you can set those up how you like em'

hope that helps, i'm barely learning php myself.. :)

Randy
11-10-2001, 10:44 AM
I'm not sure where your form is being sent, so here's a basic form to email...


<?
if ($submit) {
$message = "Hostname: $REMOTE_HOST\n";
$message .= "Date: " . date("m/d/y g:ia") . ":\n";
$message .= "Name: $name\n";
$message .= "Email: $email\n";
$message .= "URL: $url\n";
$mailto = "SERVER_ADMIN"; //Change to your email address if needed.
mail($mailto,"Form Submission",$message,"From: $name <$email>");
echo "Submission Sent!";
exit;
}
?>
<form action="<? echo $SCRIPT_NAME; ?>" method="post">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>
URL: <input type="text" name="url"><br>
<input type="submit" name="submit" value="Submit!">

kmb999
11-10-2001, 03:37 PM
I did a bit of editing, so this is what I have now...


if ($submit) {
$message = "Logged IP $REMOTE_ADDR \n";
$message .= "Time/Date " . date("g:ia m/d/y") . "\n";
$message .= "Name $name\n";
$message .= "Email $email\n";
$message .= "Domain $domain\n";
$message .= "Plan $plan\n";
$message .= "FrontPage $frontpage\n";
$message .= "Subdomains $subdomains\n";
$message .= "User $user\n";
$message .= "Pass $pass\n";
$message .= "Other $other\n";
$mailto = "kb@cinqq.net";
mail($mailto,"Form Output",$message,"From: $name <$email>");
echo "Submission Sent!";
exit;
}

echo "<FORM ACTION=\"$SCRIPT_NAME\" METHOD=\"post\">";
echo "<INPUT TYPE=\"text\" NAME=\"name\" SIZE=\"30\">";
echo "<BR>&nbsp;<BR>";
echo "<INPUT TYPE=\"text\" NAME\"email\" SIZE=\"30\">";
echo "<BR>&nbsp;<BR>&nbsp;<BR>";
echo "<INPUT TYPE=\"text\" NAME=\"domain\" SIZE=\"30\">";
echo "<BR>&nbsp;<BR>";
echo "<INPUT TYPE=\"text\" NAME=\"plan\" SIZE=\"30\">";
echo "<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>";
echo "<INPUT TYPE=\"text\" NAME=\"frontpage\" SIZE=\"15\">";
echo "<BR><INPUT TYPE=\"text\" NAME=\"subdomains\" SIZE=\"15\">";
echo "<BR>&nbsp;<BR>&nbsp;<BR>";
echo "<INPUT TYPE=\"text\" NAME=\"user\" SIZE=\"30\">";
echo "<BR><INPUT TYPE=\"text\" NAME=\"pass\" SIZE=\"30\">";
echo "<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>";
echo "<TEXTAREA NAME=\"other\" ROWS=\"6\" COLS=\"40\"></TEXTAREA>";
echo "<BR>&nbsp;<BR>";
echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Submit\">";
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE=\"reset\" NAME=\"reset\" VALUE=\"Reset\">";
echo "</FORM>";


The problems...
- The email address part doesn't submit
- I get an error (even though the form submits and I recieve it)
The error says 'Object Expected'. It's not a PHP error, though. It's one of the yellow exclamation points it the bottom left-hand corner.

What can I do to fix these errors?

Thank you! :)

kmb999
11-10-2001, 04:04 PM
Also, instead of the...


echo "Submission Sent!";


What should I put there to have it redirect to another page upon submission?

kmb999
11-10-2001, 08:18 PM
Please help. I need to finish this asap.

JTY
11-10-2001, 08:50 PM
BTW: Why did you echo every line of the form?

greengunboat
11-10-2001, 09:36 PM
to get the ip address use this: $ip = getenv ("REMOTE_ADDR");

kmb999
11-10-2001, 10:18 PM
Why do I echo every line?
Because I have too much time on my hands. :)

As far as the ip address part, I tested it and what I currently have works fine.

delemtri
11-11-2001, 02:13 AM
Header("Location: redirect_to_this.page");