Jtech inc. Posted May 26, 2010 Share Posted May 26, 2010 Hello. I am new to PHP and have recently been asked to make a small PHP program to insert data in a mysql server. After several days i am unable to get it to work, I've checked several online resources but still cannot find the error. I was hoping someone here could point me in the right direction. This is my form <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><title></title> <meta name="GENERATOR" content="MSHTML 8.00.6001.18904"> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff"> <form method="post" action="Insert3.php"> <table border="0" cellspacing="0" cellpadding="1"> <tbody> <tr> <td class="text">FIRST NAME*</td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="fname"></td></tr> <tr> <td class="text">LAST NAME* </td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="lname"></td></tr> <tr> <td class="text">DATE OF BIRTH* </td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="dob"></td></tr> <tr> <td class="text">SEX* </td> <td class="field"> <p><input value="Male" type="radio" name="sex"> Male<input value="Female" type="radio" name="sex"> Female</p></td></tr> <tr> <td class="text">STREET1</td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="adress1"></td></tr> <tr> <td class="text">STREET2</td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="adress2"></td></tr> <tr> <td class="text">CITY</td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="city"></td></tr> <tr> <td class="text">PROVENCE</td> <td class="field"><select size="1" name="provence"> <option selected value="NL">NL</option> <option value="AB">AB</option> <option value="BC">BC</option> <option value="MB">MB</option> <option value="NB">NB</option> <option value="NS">NS</option> <option value="NT">NT</option> <option value="NU">NU</option> <option value="ON">ON</option> <option value="PE">PE</option> <option value="QC">QC</option> <option value="SK">SK</option> <option value="YT">YT</option></select></td></tr> <tr> <td class="text">CAREGIVER(S) </td> <td class="field"><textarea style="WIDTH: 300px; HEIGHT: 60px" class="inputField" name="caregivers"></textarea> </td></tr> <tr> <td class="text">PHONE (H)* </td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="phoneh"></td></tr> <tr> <td class="text">PHONE (W) </td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="phonew"></td></tr> <tr> <td class="text">SOCIAL WORKER </td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="sworker"></td></tr> <tr> <td class="text">SOCIAL WORKER PHONE </td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="sworkerphone"></td></tr> <tr> <td class="text">OTHER INVOLVED PROFESSIONALS </td> <td class="field"><textarea style="WIDTH: 300px; HEIGHT: 60px" class="inputField" name="otherip"></textarea> </td></tr> <tr> <td class="text">PRIMARY DIAGNOSIS (developmental disability) </td> <td class="field"><textarea style="WIDTH: 300px; HEIGHT: 60px" class="inputField" name="primarydiagnosis"></textarea> </td></tr> <tr> <td class="text">SECONDARY DIAGNOSIS (if applicable) </td> <td class="field"><textarea style="WIDTH: 300px; HEIGHT: 60px" class="inputField" name="secondarydiagnosis"></textarea> </td></tr> <tr> <td class="text">NAME OF LAST SCHOOL ATTENDED </td> <td class="field"><input style="WIDTH: 300px" class=inputLine name="lastschoolattended"></td></tr> <tr> <td class="text">HIGHEST GRADE COMPLETED </td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="highestgradecompleted"></td></tr> <tr> <td class="text">OTHER TRAINING RECIEVED </td> <td class="field"><textarea style="WIDTH: 300px; HEIGHT: 60px" class="inputField" name="othertraining"></textarea> </td></tr> <tr> <td class="text">EMPLOYMENT HISTORY (paid or sheltered) </td> <td class="field"><textarea style="WIDTH: 300px; HEIGHT: 60px" class="inputField" name="employmenthistory"></textarea> </td></tr> <tr> <td class="text">PERTINENT INFORMATION/ COMMENTS </td> <td class="field"><textarea style="WIDTH: 300px; HEIGHT: 60px" class="inputField" name="comments"></textarea> </td></tr> <tr> <td class="text">Have any assessments been done on this individual?</td> <td class="field"> <p><input value="Yes" type="radio" name="assessments"> Yes<input value="No" type="radio" name="assessments"> No</p></td></tr> <tr> <td class="text">REFERRED BY </td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="referredby"></td></tr> <tr> <td class="text">REFERRER PHONE </td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="referredphone"></td></tr> <tr> <td class="text">DATE </td> <td class="field"><input style="WIDTH: 300px" class="inputLine" name="date"></td></tr> <tr> <td class="text"> </td> <td class="text" align="right">* mandatory</td></tr> <tr> <td class="text"> </td> <td class="field"><input style="WIDTH: 100px" class="inputButton" value="Send" type="submit" name="Submit"> </td></tr></tbody></table></form></body></html> and this is the php program for it <?php $fname = $_POST['fname']; $lname = $_POST['lname']; $dob = $_POST['dob']; $sex = $_POST['sex']; $adress1 = $_POST['adress1']; $adress2 = $_POST['adress2']; $city = $_POST['city']; $prov = $_POST['Provence']; $caregivers = $_POST['caregivers']; $phoneh = $_POST['phoneh']; $phonew = $_POST['phonew']; $sworker = $_POST['sworker']; $sworkerphone = $_POST['sworkerphone']; $otherprofectionals = $_POST['otherip']; $primarydiagnosis = $_POST['primarydiagnosis']; $secondarydiagnosis = $_POST['secondarydiagnosis']; $lastschoolattended = $_POST['lastschoolattended']; $highestgrade = $_POST['highestgradecompleted']; $othertraining = $_POST['othertraining']; $employmenthistory = $_POST['employmenthistory']; $comments = $_POST['comments']; $assessments = $_POST['assessments']; $referredby = $_POST['referredby']; $referredphone = $_POST['referredphone']; $datesigned = $_POST['date']; mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("referral"); mysql_query("INSERT INTO referral ( Employee_num, fname, lname, date_of_birth, sex, street1, street2, city, prov, Caregivers, phone_h, phone_w, social_worker, social_worker_phone, other_personal, primary_diagnosis, secondary_diagnosis, last_school_attended, highest_grade, other_training, employment_history, comments, assessment, referred_by, referred_phone, date ) VALUES( 'NULL', $fname, $lname, $dob, $sex, $adress1, $adress2, $city, $prov, $caregivers, $phoneh, $phonew, $sworker, $sworkerphone, $otherprofectionals, $primarydiagnosis, $secondarydiagnosis, $lastschoolattended, $highestgrade, $othertraining, $employmenthistory, $comments, $assessments, $referredby, $referredphone, $date) "; mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
Maq Posted May 26, 2010 Share Posted May 26, 2010 Please use tags around your code. After several days i am unable to get it to work How doesn't it work? I've checked several online resources but still cannot find the error. How do you know there is an error? I was hoping someone here could point me in the right direction. You can start by debugging the PHP code. Put these lines directly after your opening PHP tags: ini_set ("display_errors", "1"); error_reporting(E_ALL); This will temporarily set error_reporting and display to maximum. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 26, 2010 Share Posted May 26, 2010 A) You did not state what it does do when you try it (to narrow down which of the dozen or so possible things could prevent it from working.) B) If you were developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini, you would know that your code produces a fatal parse error on line 94 due to a missing ). Edit: C) If you formed your query in a variable and then just put that variable into the mysql_query() statement, the error in B) would be easier to find because your php code/syntax needed to execute the query would be separate from your sql syntax making up the query. Edit2: D) Because you are going to need to work on the sql syntax (missing single-quotes around string values.) Edit3: E) And the NULL keyword should not be enclosed in single-quotes. F) And you have at least three form fields being referenced that don't exist and your date variable name does not match between where it is set and where it is used. **** Most of the above problems were detected by trying the code on a system with error_reporting set to E_ALL and display_errors set to ON. Quote Link to comment 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.