Jump to content

Recommended Posts

Why isnt this working It does check the fields for being empty but if any field is not empty it puts it in the data base what am I doing wrong and please show me a good site so I can learn because Im not finding one!!

 

<?php
// Define form variablesand checks

$message = "Please do NOT leave any fields empty Thank You!!";
// Start the process of creation
	$username = $_POST['username'];
	$email = $_POST['email'];
	$password = $_POST['password'];
	$sex = $_POST['sex'];
	$race = $_POST['race'];
	$fclass = $_POST['fclass'];

if (empty($_POST['username'])){
	echo $message;
}

elseif (empty($_POST['email'])){
	echo $message;
}
elseif (empty($_POST['password'])){
	echo $message;
}
elseif (empty($_POST['sex'])){
	echo $message;
} 
elseif (empty($_POST['race'])){
	echo $message;
} 
elseif (empty($_POST['fclass'])){
	echo $message;
}

// connect to database
include('includes/db_config.php');

// Test for duplicate Username. If True then back to form. If not continue.
$sql = "select * from $tbl_name where username='" . $_POST['username'] . "'"; 
$result = mysql_query($sql);
if (mysql_num_rows($result) >= 1) { 
	echo "That Username is already taken please choose another!";
	}

// continue if all these checks are ok Im hoping
else {

// Encrypt Password
$encrypted_passwd=md5($password);
$password=($encrypted_passwd);

// These variables below are added as starting resource's for each player
$roomid = 1;
$armor = "Leather Outfit";
$armor_bonus = 0;
$weapon = "Big Club";
$attack_bonus = 0;
$advance = 1;
$level = 1;
$skill_name1 = "None";
$skill_bonus1 = 0;
$skill_name2 = "None";
$skill_bonus2 = 0;
$skill_name3 = "None";
$skill_bonus3 = 0;
$special_item = "None";
$special_bonus = 0;
$hitpoints = 15;
$onhand = 2000;
$diamond = 5;
$dbalance = 5;
$rubie = 10;
$rbalance = 5;
$rations = 1;
$bank = 5000;

// Populate table from form and defined info
mysql_query("INSERT INTO cr_diamond (username, roomid, email, password, sex, race, fclass, armor, armor_bonus, weapon, attack_bonus, advance, level, skill_name1, skill_bonus1, skill_name2, skill_bonus2, skill_name3, skill_bonus3, special_item, special_bonus, hitpoints, onhand, diamond, dbalance, rubie, rbalance, rations, bank) Values('$username','$roomid','$email','$password','$sex','$race','$fclass','$armor','$armor_bonus','$weapon','$attack_bonus','$advance','$level','$skill_name1','$skill_bonus1','$skill_name2','$skill_bonus2','$skill_name3','$skill_bonus3','$special_item','$special_bonus','$hitpoints','$onhand','$diamond','$dbalance','$rubie','$rbalance','$rations','$bank')");

// Close Database
	mysql_close();

// Direct on Creation Success
//echo "<META HTTP-EQUIV=\"Refresh\"CONTENT=\"0; URL=create_success.php\">";
echo "The Initial test has worked check database for confirmation!";
}
?>

 

This is just testing my old form use to work and now for some reason its passing empty fields??

 

Grrrr

Link to comment
https://forums.phpfreaks.com/topic/121077-solved-here-we-go-with-another-one/
Share on other sites

if (empty($_POST['username'])){
	echo $message;
}

 

You echo an error message for each one of these "little tests" but don't do anything else. Your code just keeps on processing until it is inserted into the database.

You must change each one of those to something like this:

 

if (empty($_POST['username'])){
	echo $message;
                exit();
}

 

Try this: http://devzone.zend.com/node/view/id/627

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.