PHP Newbie
Posted: Wed Feb 11, 2009 2:27 pm
Alright im very new to php and I was wondering how to make sure people fill out a form before they submit it. If they were to forget to fill something out i would like it let them know what they forgot and try again. I'm doing this off of two files, my index and a process.php file. I will put what code i have below, i believe i have everything except for the code that would check to see if it is filled out. Any help is appreciated
This is the process.php file
This is the index file
This is the process.php file
Code: Select all
<?php
// Connecting, selecting database
$linkage = mysql_connect('mrsour.fatcowmysql.com', 'username', 'password')
or die('Could not connect: ' . mysql_error());
mysql_select_db('bardok') or die('Could not select database');
// VALIDATION
// Insert Data into database
$insert = 'insert into members (username, password, age) values("'.$_POST['username'].'", "'.$_POST['password'].'", '.$_POST['age'].');';
if(mysql_query($insert)) echo 'Thank You For Voting';
else echo 'Database issue? '.mysql_error();
?>
Code: Select all
<html>
<head>
<title>Enter Ninja</title>
</head>
<body>
<font color="red">
<?php
if(empty($_GET['err'])) echo '<br><br>';
else{
if($_GET['err']=='user') echo 'Please Enter Your Name';
if($_GET['err']=='pw') echo 'Please Enter Your Favorite Movie';
}
?>
</font>
Vote for your favorite movie<br>
<br>
<form action="process.php" method="post">
Name:
<input type="text" name="fname" size="10" maxlength="12">
Favorite Movie:
<input type="password" name="movie" size="10" maxlength="50">
<input type="submit" name="submit" value="Vote">
</form>
</body>
</html>