SpikeWeb
04-19-2006, 02:17 PM
Hi all,
I'm making a guestbook for my site in PHP. I have the script working, but now I'd like to make some of the fields required. What might be the easiest way to do this. I tried putting the following line into the form, but that didn't seem to work. I got this from this link (http://www.clickfire.com/viewpoints/articles/webdevelopment/create_php_form.php) , however I'm not sure I implemented it correctly.
<input type=hidden name="required" value="name,address,city,state,zip">Below is my PHP code. When the form is submitted, the data goes into a MySQL DB. I did have one other question and that is, if I have these required fields in the DB instead of the page, this wouldn't really work since the form could still be submitted without being checked on the client-side, correct?
I think I need to make the required fields in the DB the same as the ones in the form, but I thought I'd ask anyway.
<?php
if (!isset($_POST['submit'])) {
?>
<!--HTML Form begins here-->
<?php
}
else {
$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$find = addslashes($_POST['find']);
$question = addslashes($_POST['question']);
mysql_query ("INSERT INTO `guestbook` (name, address, city, state, country, zip, phone, email, find, question)
VALUES ('$name', '$address', '$city', '$state', '$zip', '$country', '$phone', '$email', '$find', '$question')");
?>
<div align="center">
<span class="text12ptbold">
<?php
echo "Thank you! You have successfully been added to our guestbook!";
}
?>
Any insight is appreciated, thanks!
I'm making a guestbook for my site in PHP. I have the script working, but now I'd like to make some of the fields required. What might be the easiest way to do this. I tried putting the following line into the form, but that didn't seem to work. I got this from this link (http://www.clickfire.com/viewpoints/articles/webdevelopment/create_php_form.php) , however I'm not sure I implemented it correctly.
<input type=hidden name="required" value="name,address,city,state,zip">Below is my PHP code. When the form is submitted, the data goes into a MySQL DB. I did have one other question and that is, if I have these required fields in the DB instead of the page, this wouldn't really work since the form could still be submitted without being checked on the client-side, correct?
I think I need to make the required fields in the DB the same as the ones in the form, but I thought I'd ask anyway.
<?php
if (!isset($_POST['submit'])) {
?>
<!--HTML Form begins here-->
<?php
}
else {
$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$find = addslashes($_POST['find']);
$question = addslashes($_POST['question']);
mysql_query ("INSERT INTO `guestbook` (name, address, city, state, country, zip, phone, email, find, question)
VALUES ('$name', '$address', '$city', '$state', '$zip', '$country', '$phone', '$email', '$find', '$question')");
?>
<div align="center">
<span class="text12ptbold">
<?php
echo "Thank you! You have successfully been added to our guestbook!";
}
?>
Any insight is appreciated, thanks!