PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
g3ckO
Forum Contributor
Posts: 117 Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:
Post
by g3ckO » Tue Jul 27, 2004 9:32 pm
This is the form: addform.php
Code: Select all
<?php
function user_form()
{
?>
<b>Username:</td><td><input type="text" name="username"></td></tr>
<b>Password:</td><td><input type="text" name="password"></td></tr>
<form action="add_user_func.php" method="POST">
<input type="submit" value="SAVE" name="submit"></form>
<?
}
user_form();
?>
add_user_func.php:
Code: Select all
<?php
require_once 'addform.php';
include("database.php");
include("login.php");
define('HOST', 'localhost');
define('USER', 'root');
define('PASS', '');
define('DB', 'db1');
if ($REQUEST_METHOD=="POST")
{
if (!$_POST['username'] || !$_POST['password'])
{
echo("YOU DIDN'T FILL IN ALL THE REQUIRED FIELDS.");
}
$username = $_POST['username'];
$md5pass = md5($_POST['password']);
global $conn;
$q = "INSERT INTO employee VALUES ('$username', '$md5pass')";
return mysql_query($q,$conn);
$result = mysql_query($q, $conn);
if (!$result)
{
echo("ERROR: " . mysql_error() . "\n$q\n");
}
echo("DATA SUCCESSFULY ADDED\n");
}
?>
Here is the problem:
I have fill in all the field in the form but why it still show the message ("YOU DIDN'T FILL IN ALL THE REQUIRED FIELDS.")
litebearer
Forum Contributor
Posts: 194 Joined: Sat Mar 27, 2004 5:54 am
Post
by litebearer » Tue Jul 27, 2004 9:58 pm
Try changing this line
Code: Select all
if (!$_POSTї'username'] || !$_POSTї'password'])
to this
Code: Select all
if (!isset($_POSTї'username']) || !isset($_POSTї'password']))
g3ckO
Forum Contributor
Posts: 117 Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:
Post
by g3ckO » Tue Jul 27, 2004 10:01 pm
Still doesn't work..
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Tue Jul 27, 2004 10:01 pm
Also look at your tag order in your form. <form> should suround the form items as they are part of the form:
Code: Select all
<form action="add_user_func.php" method="POST">
<b>Username:</td><td><input type="text" name="username"></td></tr>
<b>Password:</td><td><input type="text" name="password"></td></tr>
<input type="submit" value="SAVE" name="submit">
</form>
g3ckO
Forum Contributor
Posts: 117 Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:
Post
by g3ckO » Tue Jul 27, 2004 10:13 pm
So the form is wrong...
Tq guys... problem solved..