[SOLVED] litlle help need..

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

Post Reply
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

[SOLVED] litlle help need..

Post by g3ckO »

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 »

Try changing this line

Code: Select all

if (!$_POST&#1111;'username'] || !$_POST&#1111;'password'])
to this

Code: Select all

if (!isset($_POST&#1111;'username']) || !isset($_POST&#1111;'password']))
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

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 »

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>
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

So the form is wrong... :wink:

Tq guys... problem solved..
Post Reply