dmpeterson Posted April 1, 2013 Share Posted April 1, 2013 Hi all, I am very new to websites and am having difficulty getting my form data to post to my data base table. I created the form in Dreamweaver with Spry validation. Is there something special that I need to get this to post? Are there errors in my code? Please help, if you can. I thank you in advance for your response. Data Base Table is in png file below. PHP form code: <?phpinclude("dbinfo2.inc"); $dnum=$_POST['dnum']; $schname=$_POST['schname']; $schadd=$_POST['schadd']; $city=$_POST['city']; $schphone=$_POST['schphone']; $conname=$_POST['conname']; $conemail=$_POST['conemail']; $category=$_POST['category']; $projdesc=$_POST['projdesc']; $material=$_POST['material']; $approcost=$_POST['approcost']; $passwrd=$_POST['passwrd']; //Input Validationsif ($dnum == "") {$errmsg_arr[] = 'Existing Donation Number missing'; $errflag = true;} if ($schname == "") {$errmsg_arr[] = 'School Name missing'; $errflag = true;}if ($schadd == "") {$errmsg_arr[] = 'School Address missing'; $errflag= true;}if ($city == "") {$errmsg_arr[] = 'City/State missing'; $errflag= true;}if ($schphone == "") {$errmsg_arr[] = 'School Phone missing'; $errflag= true;}if ($conname == "") {$errmsg_arr[] = 'Contact Name missing'; $errflag= true;}if ($conemail == "") {$errmsg_arr[] = 'Contact Email missing'; $errflag= true;}if ($category == "") {$errmsg_arr[] = 'Project Category missing'; $errflag= true;}if ($projdesc == "") {$errmsg_arr[] = 'Project Description missing'; $errflag= true;}if ($material == "") { $errmsg_arr[] = 'Materials Needed missing'; $errflag= true;}if ($apprcost == "") { $errmsg_arr[] = 'Approximate Cost missing'; $errflag= true;}if ($passwrd == "") { $errmsg_arr[] = 'Password missing'; $errflag= true;}// If there are input validations, redirect back to submit form. if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); exit(); } mysql_connect($hostname,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); // Create INSERT query$query = "INSERT INTO contacts VALUES ('','','Change DN',$dnum','$schname','$schadd','$city','$schphone','$conname','$conemail','$category','$projdesc','$material','$apprcost','$passwrd')";mysql_query($query);$query = "INSERT INTO backup VALUES ('','','Change DN',$dnum',$schname','$schadd','$city','$schphone','$conname','$conemail','$category','$projdesc','$material','$apprcost','$passwrd')";mysql_query($query);mysql_close();?> Form: <form method="post" action="sr.php"> </p><table width="803" height="645" border="1"> <tr> <td width="246"><h3>School Name:</h3></td> <td width="541"><span id="sprytextfield1"> <label for=schname> <input name="schname" type="text" id="schname"autofocus required size="65" maxlength="70" /> </label> <span class="textfieldRequiredMsg">Please specify the school name.</span></span></td> </tr> <tr> <td><h3>School Address:</h3></td> <td><span id="sprytextfield2"> <label for=schadd> <input name="schadd" type="text" id="schadd" value="" size="65" /> </label> <span class="textfieldRequiredMsg">Please specify the school address.</span></span></td> </tr> <tr> <td><h3>City/State:</h3></td> <td><span id="sprytextfield3"> <label for=city> <input name="city" type="text" id="city" size="65" maxlength="70" /> </label> <span class="textfieldRequiredMsg">Please specify the city/state where your school is located.</span></span></td> </tr> <tr> <td><h3>School Phone #:</h3></td> <td><span id="sprytextfield4"> <label for=schphone> <input name="schphone" type="text" id="schphone" size="65" maxlength="70" /> </label> <span class="textfieldRequiredMsg">Please specify a valid phone number.</span><span class="textfieldInvalidFormatMsg">Please specify a valid school phone number.</span></span></td> </tr> <tr> <td><h3>Contact Name:</h3></td> <td><span id="sprytextfield5"> <label for=conname> <input name="conname" type="text" id="conname" size="65" maxlength="70" /> </label> <span class="textfieldRequiredMsg">Please specify the name of the contact person.</span></span></td> </tr> <tr> <td><h3>Contact Email:</h3></td> <td><span id="sprytextfield6"> <label for=conemail> <input name="conemail" type="text" id="conemail" size="65" maxlength="70" /> </label> <span class="textfieldRequiredMsg">Please provide a valid email.</span><span class="textfieldInvalidFormatMsg">Please specify a valid email address.</span></span></td> </tr> <tr> <td><h3>Project Catagory:</h3></td> <td><span id="spryselect1"> <label for=category> <select name="category"> <option value="" <?php if (@$fields["cat"] == "") echo "selected"; ?>Click on the down arrow for choices. ></option> <option value="" <?php if (@$fields["cat"] == "") echo "selected"; ?>------------------------------------- ></option> <option value="Athletic Needs" <?php if (@$fields["cat"] == "Athletic Needs") echo "selected"; ?>Athletic needs ></option> <option value="Building Improvements" <?php if (@$fields["cat"] == "Building Improvements") echo "selected"; ?>Building improvements ></option> <option value="Instructional Tools " <?php if (@$fields["cat"] == "Instructional Tools") echo "selected"; ?>Instructional tools ></option> <option value="Education Materials" <?php if (@$fields["cat"] == "Education Materials") echo "selected"; ?>Education materials ></option> <option value="Class Project" <?php if (@$fields["cat"] == "Class Project") echo "selected"; ?>Class project ></option> <option value="External Learning Experiences" <?php if (@$fields["cat"] == "External Learning Experiences") echo "selected"; ?>External learning experiences ></option> <option value="Office Supplies" <?php if (@$fields["cat"] == "Office Supplies") echo "selected"; ?>Office supplies ></option> <option value="Student Need" <?php if (@$fields["cat"] == "Student Need") echo "selected"; ?>Student need ></option> <option value="Professional Development" <?php if (@$fields["cat"] == "Professional Development") echo "selected"; ?>Professional development ></option> <option value="Transportation Needs" <?php if (@$fields["cat"] == "Transportation Needs") echo "selected"; ?>Transportation needs ></option> <option value="Extra Curricular Programs" <?php if (@$fields["cat"] == "Extra Curricular Programs") echo "selected"; ?>Extra curricular programs ></option> <option value="Other Service" <?php if (@$fields["cat"] == "Other Service") echo "selected"; ?>Other service ></option> </select> </label> <span class="selectRequiredMsg">Please select a category.</span></span></td> </tr> <tr> <td><h3>Project Description:</h3></td> <td><span id="sprytextarea1"> <label for=projdesc> <textarea name="projdesc" cols="46" rows="20" id=projdesc; maxlength="595"></textarea> </label> <span class="textareaRequiredMsg">Please provide a description for the project.</span></span></td> </tr> <tr> <td><h3>Materials Needed:</h3></td> <td><span id="sprytextarea2"> <label for=material> <textarea name="material" cols="46" rows="10" id="material" maxlength="595"></textarea> </label> <span class="textareaRequiredMsg">Please specify the materials needed.</span></span></td> </tr> <tr> <td><h3>Approximate Cost:</h3></td> <td><span id="sprytextfield7"> <label for=apprcoast> <input name="apprcost" type="text" id="apprcost" size="65" maxlength="60" /> </label> <span class="textfieldRequiredMsg">Please specify an approximate cost for the project.</span></span></td> </tr> <tr> <td><h3>Password for Bargain Prowler:</h3> <p><span class="style32">(This will not appear online, but will be used by you to change or delete a submission)</span></p></td> <td><span id="sprytextfield8"> <label for=passwrd> <input name="passwrd" type="text" id="passwrd" size="65" maxlength="60" /> </label> <span class="textfieldRequiredMsg">Please create a password for Bargain Prowler.</span></span></td> </tr></table> </h1><!-- end .content --><h2><span class="style32"><span class="style85">IMPORTANT</span>: Before clicking on "Submit", please make sure "Project Description" <span class="style65"><strong>OR</strong></span> "Materials Needed" content does not exceed 10 lines. Content over 10 lines gets deleted upon submission. Also, make sure there are no carriage returns in the "Project Description" <span class="style85">OR</span> "Materials Needed" since it will be displayed in paragraph form (just like this paragraph you are reading now).</span></h2><p> <input type="submit" value="Submit" /> </form></p> Quote Link to comment https://forums.phpfreaks.com/topic/276393-getting-form-variables-to-post-to-the-database/ 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.