Kryllster Posted August 24, 2008 Share Posted August 24, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/121077-solved-here-we-go-with-another-one/ Share on other sites More sharing options...
thecard Posted August 24, 2008 Share Posted August 24, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/121077-solved-here-we-go-with-another-one/#findComment-624171 Share on other sites More sharing options...
Kryllster Posted August 24, 2008 Author Share Posted August 24, 2008 Thanks for the reply and now I feel really dumb cause I was gonna try that but thought it wouldn't help but it works great now Thank You! Peace Quote Link to comment https://forums.phpfreaks.com/topic/121077-solved-here-we-go-with-another-one/#findComment-624178 Share on other sites More sharing options...
thecard Posted August 24, 2008 Share Posted August 24, 2008 Your Welcome. Quote Link to comment https://forums.phpfreaks.com/topic/121077-solved-here-we-go-with-another-one/#findComment-624316 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.