MSUK1 Posted March 28, 2012 Share Posted March 28, 2012 Hello i am trying to submit members information into a database, i have checked the form variables and all the data is being passed. i can get my errors in the data returned, but i cant get a succes or fail error that i setup it just refreshes the page :/ but i still am not getting the data into my DB i will provide below the specific code related to this query starting with php form. Form HTML <? if(isset($_SESSION['regsuccess'])){ /* Registration was successful */ if($_SESSION['regsuccess']){ echo "<h3>Registered!</h3>"; echo "<p>Thank you, your new member has been added to the database.</p>"; } /* Registration failed */ else{ echo "<h3>Registration Failed</h3>"; echo "<p>We're sorry, but an error has occurred and your registration for the new user</b>, " ."could not be completed.<br>Please try again at a later time.</p>"; } unset($_SESSION['regsuccess']); } ?> <form action="system/process.php" method="post"> <div class="column-left"> <p> <input type="text" id="fname" name="fname" placeholder="First Name" class="{validate:{required:true, minlength:3}}" /> <span style="color:red;"><? echo $form->error("fname"); ?></span> </p> <p> <select name="prefix" id="prefix" placeholder="Prefix" class="{validate:{required:true}}"> <option>Mr</option> <option>Mrs</option> <option>Miss</option> <option>Master</option> </select> <span style="color:red;"><? echo $form->error("prefix"); ?></span> </p> <div class="combined"> <p class="large"> <input type="text" id="address1" name="address1" placeholder="Address Line 1" class="{validate: {required:true}}" /> </p> <p class="small"> <input type="text" id="postcode" name="postcode" placeholder="Post Code" class="{validate: {required:true}}" /> </p> </div> <p> <span style="color:red;"><? echo $form->error("address1"); ?></span> </p> <p> <span style="color:red;"><? echo $form->error("postcode"); ?></span> </p> <div class="column-left"> <p> <input type="checkbox" name="gender" id="female" value="female" /> <label for="female">Female</label> </p> </div> <div class="column-right"> <p> <input type="checkbox" name="gender" id="male" value="male" /> <label for="male">Male</label> </p> </div> <p> <span style="color:red;"><? echo $form->error("gender"); ?></span> </p> <div class="clear"></div> <p> <input type="text" name="dob" class="datepicker" id="date" placeholder="Date of Birth" /> <span class="icon calendar"></span> <span style="color:red;"><? echo $form->error("dob"); ?></span> </p> </div> <div class="column-right"> <p> <input type="text" id="lname" name="lname" placeholder="Last Name" class="{validate:{required:true, minlength:3}}" /> <span style="color:red;"><? echo $form->error("lname"); ?></span> </p> <p> <input type="text" id="email" name="email" placeholder="Email Address" class="{validate:{required:true, minlength:3}}" /> <span style="color:red;"><? echo $form->error("email"); ?></span> </p> <h6>Notes</h6> <p> <textarea id="notes" name="notes" class="{validate:{required:true}}"></textarea> <span style="color:red;"><? echo $form->error("notes"); ?></span> </p> <div class="bottom"> <p class="warning"> Warning: All fields are required. </p> </div> </div> <div class="clear"></div> <div class="action_bar"> <input type="submit" class="button blue" value="Submit Post" /> <a href="#modal" class="modal button">Cancel</a> </div> <input type="hidden" name="leadername" value="<? echo"$session->username";?>" /> <input type="hidden" name="newmem" value="1" /> </form> process.php page include("include/session.php"); this is used to define what function to follow /* Add new Leader Member */ else if(isset($_POST['newmem'])){ $this->procNewLMember(); } /** * procNewLMember **/ function procNewLMember(){ global $session, $form; /* Registration attempt */ $retval = $session->newmemb($_POST['fname'], $_POST['lname'], $_POST['email'], $_POST['prefix'], $_POST['address1'], $_POST['postcode'], $_POST['gender'], $_POST['dob'], $_POST['notes'], $_POST['leadername']); /* Registration Successful */ if($retval == 0){ $_SESSION['regsuccess'] = true; header("Location: ".$session->referrer); } /* Error found with form */ else if($retval == 1){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } /* Registration attempt failed */ else if($retval == 2){ header("Location: ".$session->referrer); } } session.php page include("database.php"); include("mailer.php"); include("form.php"); /** * register new member - register a new leaders member */ function newmemb($subfname, $sublname, $subemail, $subprefix, $subaddress1, $subpostcode, $subgender, $subdob, $subnotes, $subleadername){ global $database, $form, $mailer; //The database, form and mailer object /* First Name error checking */ $field = "fname"; //Use field name for first name if(!$subfname || strlen($subfname = trim($subfname)) == 0){ $form->setError($field, "* First Name not entered"); } else{ /* Spruce up username, check length */ $subfname = stripslashes($subfname); if(strlen($subfname) < 5){ $form->setError($field, "* First Name below 5 characters"); } else if(strlen($subfname) > 30){ $form->setError($field, "* First Name above 30 characters"); } } /* Last Name error checking */ $field = "lname"; //Use field name for first name if(!$sublname || strlen($sublname = trim($sublname)) == 0){ $form->setError($field, "* Last Name not entered"); } else{ /* Spruce up username, check length */ $sublname = stripslashes($sublname); if(strlen($sublname) < 5){ $form->setError($field, "* Last Name below 5 characters"); } else if(strlen($sublname) > 30){ $form->setError($field, "* Last Name above 30 characters"); } } /* Address 1 error checking */ $field = "address1"; //Use field name for first name if(!$subaddress1 || strlen($subaddress1 = trim($subaddress1)) == 0){ $form->setError($field, "* Address not entered"); } else{ /* Spruce up username, check length */ $sublname = stripslashes($sublname); if(strlen($subaddress1) < 5){ $form->setError($field, "* Address below 5 characters"); } else if(strlen($subaddress1) > 30){ $form->setError($field, "* Address above 30 characters"); } } /* Postcode error checking */ $field = "postcode"; //Use field name for first name if(!$subpostcode || strlen($subpostcode = trim($subpostcode)) == 0){ $form->setError($field, "* Post Code not entered"); } else{ /* Spruce up username, check length */ $subpostcode = stripslashes($subpostcode); if(strlen($subpostcode) < 5){ $form->setError($field, "* Postcode below 5 characters"); } else if(strlen($subpostcode) > 30){ $form->setError($field, "* Postcode above 30 characters"); } } /* Prefix error checking */ $field = "prefix"; //Use field name for first name if(!$subprefix || strlen($subprefix = trim($subprefix)) == 0){ $form->setError($field, "* Please select a prefix"); } else{ } /* Gender error checking */ $field = "gender"; //Use field name for first name if(!$subgender || strlen($subgender = trim($subgender)) == 0){ $form->setError($field, "* Please select a gender"); } else{ } /* DOB error checking */ $field = "dob"; //Use field name for first name if(!$subdob || strlen($subdob = trim($subdob)) == 0){ $form->setError($field, "* Please enter a D.O.B"); } else{ } /* Notes error checking */ $field = "notes"; //Use field name for first name if(!$subnotes || strlen($subnotes = trim($subnotes)) == 0){ $form->setError($field, "* Please enter some notes"); } else{ } /* Email error checking */ $field = "email"; //Use field name for email if(!$subemail || strlen($subemail = trim($subemail)) == 0){ $form->setError($field, "* Email not entered"); } else{ /* Check if valid email address */ $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$subemail)){ $form->setError($field, "* Email invalid"); } $subemail = stripslashes($subemail); } /* Errors exist, have user correct them */ if($form->num_errors > 0){ return 1; //Errors with form } /* No errors, add the new account to the */ else{ if($database->addNewLMember($subfname, $sublname, $subemail, $subprefix, $subaddress1, $subpostcode, $subgender, $subdob, $subnotes, $subleadername)){ return 0; //New user added succesfully }else{ return 2; //Registration attempt failed } } } database.php include("constants.php"); class MySQLDB { var $connection; //The MySQL database connection var $num_active_users; //Number of active users viewing site var $num_active_guests; //Number of active guests viewing site var $num_members; //Number of signed-up users /* Note: call getNumMembers() to access $num_members! */ /* Class constructor */ function MySQLDB(){ /* Make connection to database */ $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error()); mysql_select_db(DB_NAME, $this->connection) or die(mysql_error()); /** * addNewLMember - Inserts the given to member database */ function addNewLMember($fname, $lname, $email, $prefix, $address1, $postcode, $gender, $dob, $notes, $leadername){ $q = "INSERT INTO ".TBL_MEMBERS." VALUES ('$fname', '$lname', '$email', '$prefix', '$address1', '$postcode', '$gender', '$dob', '$notes', '$leadername')"; return mysql_query($q, $this->connection); } /** * query - Performs the given query on the database and * returns the result, which may be false, true or a * resource identifier. */ function query($query){ return mysql_query($query, $this->connection); } }; /* Create database connection */ $database = new MySQLDB; constant.php /** * Database Constants - these constants are required * in order for there to be a successful connection * to the MySQL database. Make sure the information is * correct. */ define("DB_SERVER", "XX"); define("DB_USER", "XX"); define("DB_PASS", "XX"); define("DB_NAME", "XX"); /** * Database Table Constants - these constants * hold the names of all the database tables used * in the script. */ define("TBL_USERS", "users"); define("TBL_MEMBERS", "members"); define("TBL_ACTIVE_USERS", "active_users"); define("TBL_ACTIVE_GUESTS", "active_guests"); define("TBL_BANNED_USERS", "banned_users"); i have blanked out my database information but it is their and does connect, another form process of mine does work just not this one :? all help appreciated Quote Link to comment https://forums.phpfreaks.com/topic/259883-simple-php-form-submission-not-working-mind-boggling/ Share on other sites More sharing options...
MSUK1 Posted March 28, 2012 Author Share Posted March 28, 2012 just a heads up, i this was my database structure # Column Type Collation Attributes Null Default Extra Action 1 memberid int( latin1_general_ci no autoincrement Change Drop More 2 firstname varchar(50) latin1_general_ci No None Change Drop More 3 lastname varchar(50) latin1_general_ci No None Change Drop More 4 email varchar(50) latin1_general_ci No None Change Drop More 5 prefix varchar(20) latin1_general_ci No None Change Drop More 6 address1 varchar(20) latin1_general_ci No None Change Drop More 7 postcode varchar(50) latin1_general_ci No None Change Drop More 8 gender varchar(20) latin1_general_ci No None Change Drop More 9 dob varchar(20) latin1_general_ci No None Change Drop More 10 notes varchar(2000) latin1_general_ci No None Change Drop More 11 leader varchar(50) latin1_general_ci No None Change Drop More Quote Link to comment https://forums.phpfreaks.com/topic/259883-simple-php-form-submission-not-working-mind-boggling/#findComment-1331991 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.