mbrown Posted September 12, 2008 Share Posted September 12, 2008 I am trying to do this via a html form, validating with php and want to insert into the database here are the files Form <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Mike's Student Survey</title> <link href="../css/stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="508" border="0" align="center"> <tr> <td><div align="center"> <h1>Mike's Student Survey<br /> <span class="copyright">Last Updated: Saturday September 6, 2008 7:57 PM</span><br /> <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a> <img src="http://www.fijilive.com/ecards/icons/School_University.jpg" width="105" height="94" alt="School" /> <a href="http://jigsaw.w3.org/css-validator/"> <img src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" width="88" height="31" style="border:0;width:88px;height:31px" /></a> </h1> </div></td> </tr> <tr> <td> <form id="MikesStudentSurvey" name="Mikes_Student_Survey" method="post" action="validate.php"> <table width="425" border="1" align="center"> <tr> <th width="71" valign="top" class="formItems" scope="col">Name</th> <th width="190" scope="col"> <div align="left"> <input type="text" name="Name" id="Name"/> </div></th> </tr> <tr> <td valign="top" class="formItems">Age</td> <td><label> <input name="Age" type="text" maxlength="2" id="Age"/> </label> </td> </tr> <tr> <td class="formItems">D.O.B.</td> <td><label> <select name="Month" id="Month"> <option value="0" selected="selected">0</option> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="DayofBirth" id="DayofBirth"> <option value="0" selected="selected">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select name="birthYear" id="birthYear"> <option value="0" selected="selected">0</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> <option value="1988">1988</option> <option value="1987">1987</option> <option value="1986">1986</option> <option value="1985">1985</option> <option value="1984">1984</option> <option value="1983">1983</option> <option value="1982">1982</option> <option value="1981">1981</option> <option value="1980">1980</option> <option value="1979">1979</option> <option value="1978">1978</option> <option value="1977">1977</option> <option value="1976">1976</option> <option value="1975">1975</option> <option value="1974">1974</option> <option value="1973">1973</option> <option value="1972">1972</option> <option value="1971">1971</option> <option value="1970">1970</option> <option value="1969">1969</option> <option value="1968">1968</option> <option value="1967">1967</option> <option value="1966">1966</option> <option value="1965">1965</option> <option value="1964">1964</option> <option value="1963">1963</option> <option value="1962">1962</option> <option value="1961">1961</option> <option value="1960">1960</option> <option value="1959">1959</option> <option value="1958">1958</option> <option value="1957">1957</option> <option value="1956">1956</option> <option value="1955">1955</option> <option value="1954">1954</option> <option value="1953">1953</option> <option value="1952">1952</option> <option value="1951">1951</option> <option value="1950">1950</option> <option value="1949">1949</option> <option value="1948">1948</option> <option value="1947">1947</option> <option value="1946">1946</option> <option value="1945">1945</option> <option value="1944">1944</option> <option value="1943">1943</option> <option value="1942">1942</option> <option value="1941">1941</option> <option value="1940">1940</option> <option value="1939">1939</option> <option value="1938">1938</option> <option value="1937">1937</option> <option value="1936">1936</option> <option value="1935">1935</option> <option value="1934">1934</option> <option value="1933">1933</option> <option value="1932">1932</option> <option value="1931">1931</option> <option value="1930">1930</option> <option value="1929">1929</option> <option value="1928">1928</option> <option value="1927">1927</option> <option value="1926">1926</option> <option value="1925">1925</option> <option value="1924">1924</option> <option value="1923">1923</option> <option value="1922">1922</option> <option value="1921">1921</option> <option value="1920">1920</option> <option value="1919">1919</option> <option value="1918">1918</option> <option value="1917">1917</option> <option value="1916">1916</option> <option value="1915">1915</option> <option value="1914">1914</option> <option value="1913">1913</option> <option value="1912">1912</option> <option value="1911">1911</option> <option value="1910">1910</option> <option value="1909">1909</option> <option value="1908">1908</option> <option value="1907">1907</option> <option value="1906">1906</option> <option value="1905">1905</option> <option value="1904">1904</option> <option value="1903">1903</option> <option value="1902">1902</option> <option value="1901">1901</option> </select> </label> <label> </label></td> </tr> <tr> <td class="formItems">Hometown</td> <td><label> <textarea name="hometown" id="hometown" cols="30" rows="1"></textarea> </label></td> </tr> <tr> <td class="formItems">State</td> <td> <label> <select name="State" id="State"> <option value="---" selected="selected">---</option> <option value="AK">ALASKA</option> <option value="AL">ALABAMA</option> <option value="AR">ARKANSAS</option> <option value="AZ">ARIZONA</option> <option value="CA">CALIFORNIA</option> <option value="CO">COLORADO</option> <option value="CT">CONNECTICUT</option> <option value="DC">DISTRICT OF COLUMBIA</option> <option value="DE">DELAWARE</option> <option value="FL">FlORIDA</option> <option value="GA">GEORGIA</option> <option value="HI">HAWAII</option> <option value="IA">IOWA</option> <option value="ID">IDAHO</option> <option value="IL">ILLINOIS</option> <option value="IN">INDIANA</option> <option value="KS">KANSAS</option> <option value="KY">KENTUCKY</option> <option value="LA">LOUISIANA</option> <option value="MA">MASSACHUSETTS</option> <option value="MD">MARYLAND</option> <option value="ME">MAINE</option> <option value="MI">MICHIGAN</option> <option value="MN">MINNESOTA</option> <option value="MO">MISSOURI</option> <option value="MS">MISSISSIPPI</option> <option value="MT">MONTANA</option> <option value="NC">NORTH CAROLINA</option> <option value="ND">NORTH DAKOTA</option> <option value="NE">NEBRASKA</option> <option value="NH">NEW HAMPSHIRE</option> <option value="NJ">NEW JERSEY</option> <option value="NM">NEW MEXICO</option> <option value="NV">NEVADA</option> <option value="NY">NEW YORK</option> <option value="OH">OHIO</option> <option value="OK">OKLAHOMA</option> <option value="OR">OREGON</option> <option value="PA">PENNSYLVANIA</option> <option value="PR">PUERTO RICO</option> <option value="RI">RHODE ISLAND</option> <option value="SC">SOUTH CAROLINA</option> <option value="SD">SOUTH DAKOTA</option> <option value="TN">TENNESSEE</option> <option value="TX">TEXAS</option> <option value="UT">UTAH</option> <option value="VA">VIRGINIA</option> <option value="VT">VERMONT</option> <option value="WA">WASHINGTON</option> <option value="WI">WISCONSIN</option> <option value="WV">WEST VIRGINIA</option> <option value="WY">WYOMING</option> </select> </label> </td> </tr> <tr> <td class="formItems">Year of Graduation</td> <td> <input type="text" name="YearofGrad" maxlength="4" size="10" id="YearofGrad"/> </td> </tr> <tr> <td class="formItems">Type of Degree</td> <td valign="top"> <table width="200" border="0"> <tr> <td><input type="checkbox" name="Associates" id="Associates" value="1" /> Associates</td> </tr> <tr> <td><input type="checkbox" name="Bachelors" id="Bachelors" value="1"/> Bachelors </td> </tr> <tr> <td><input type="checkbox" name="Certificate" id="Certificate" value="1"/> Certificate</td> </tr> </table> </td> </tr> <tr> <td class="formItems">Field of Study</td> <td><label> <textarea name="FieldOfStudy" id="FieldOfStudy" cols="30" rows="5"></textarea> </label></td> </tr> <tr> <td class="formItems">G.P.A.</td> <td><label> <select name="GPA" id="GPA"> <option value="---" selected="selected">---</option> <option value="3.5-4.0">3.5-4.0</option> <option value="3.0-3.49">3.0-3.49</option> <option value="2.5-2.99">2.5-2.99</option> <option value="2.0-2.49">2.0-2.49</option> </select> </label></td> </tr> <tr> <td colspan="2"> <div class="c1"><label><input type="submit" name="Submit" value="Submit" /></label> <label> <input type="reset" name="Reset" id="Reset" value="Reset" /> </label> </div> </td> </tr> </table> </form></td> </tr> </table> </body> </html> Validation Code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Form Validation</title> <link href="../css/stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <?php //Date function to make sure DOB = the age that was entered function dateDiff($dformat, $endDate, $beginDate) { $date_parts1=explode($dformat, $beginDate); $date_parts2=explode($dformat, $endDate); $start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]); $end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]); return $end_date - $start_date; } //Begining of Variables $Name = $_POST['Name']; //validated september 6, 2008 $Age = $_POST['Age']; //validated september 6, 2008 $Month = $_POST['Month']; //validated september 7, 2008 $DayofBirth = $_POST['DayofBirth']; //validated september 7, 2008 $birthYear = $_POST['birthYear']; //validated september 7, 2008 $hometown = $_POST['hometown']; //validated september 6, 2008 $State = $_POST['State']; //validated september 7, 2008 $YearofGrad = $_POST['YearofGrad']; //validated september 6, 2008 $Associates = $_POST['Associates']; //validated september 7, 2008 $Bachelors = $_POST['Bachelors']; //validated september 7, 2008 $Certificate = $_POST['Certificate']; //validated september 7, 2008 $FieldOfStudy = $_POST['FieldOfStudy']; //validated september 7, 2008 $GPA = $_POST['GPA']; //validated september 7, 2008 //New Variables for validating $dob against the $age entered $dob = $Month . "/" . $DayofBirth . "/" . $birthYear; $currentDate = date("m/d/Y", time()); $numDays = 365; //Testing Purposes //echo $dob; //Other Messages $error = ""; $success = ""; //Validating the '$Name' variable if ($Name == '' || strlen($Name) > 20 ) { $error .= "Your name was not entered or is to long<br />"; } else { $success .= "Name: $Name <br />"; } //Validating the '$Age' variable if ($Age < 18 || $Age > 80) { $error .= "Your age you enetered, $Age, was invalid. Please try again<br />"; } else { $success .= "Age: $Age <br />"; } //validating the '$month' variable if ($Month == 0) { $error .= "The month you selected, $Month, is invalid. Please try again<br />"; } else { $success .= "Month: $Month<br />"; } //Validating the '$DayofBirth' variable if ($DayofBirth == 0) { $error .= "The day of birth you selected, $DayofBirth, was invalid. Please try again<br />"; } else { $success .= "Day of Birth: $DayofBirth<br />"; } //Validating the $birthyear if ($birthYear == 0) { $error .= "The birth year you selected, $birthYear, was invalid. Please try again<br />"; } else { $success .= "Birth Year: $birthYear<br />"; } //Validating that the DOB entered is the right "age" for the age entered /*/========================Testing Purposes================================ echo "Age: " .$Age; echo "Calulated Age: " . floor(dateDiff("/", $currentDate, $dob)/365); //======================================================================/*/ if ($Age != floor(dateDiff("/", $currentDate, $dob)/$numDays)) { $error .= "The age you enetered is not equal to the date of birth you entered.<br />"; } //Validating the '$hometown' variable if (strlen ($hometown) > 40 || strlen ($hometown) < 5) { $error .= "Your Hometown was invalid. Please try again<br />"; } else { $success .= "Hometown: $hometown <br />"; } //validing the '$state' variable if ($State == "---") { $error .= "The State you selected, $State, was invalid, please try again<br />"; } else { $success .= "State: $State <br />"; } //Validating the '$YearofGrad' variable if ($YearofGrad > 2009 || $YearofGrad < 1977 || strlen($YearofGrad == 4)) { $error .= "The year of graduation you selected, $YearofGrad, was invalid because you did not enter it or it is not 4 characters long. Please try again<br />"; } else { $success .= "Year of Graduation: $YearofGrad <br />"; } //validating type of degree if ($Associates + $Bachelors + $Certificate == 0) { $error .= "The selection for your degree type was not valid, Please try again<br />"; } else { $success .= "Degree Type: "; //outputing associates if associates is checked if ($Associates == 1) { $success .= "Associates"; } //putting a , between associates and bachelors if ($Associates + $Bachelors == 2) { $success .= ", "; } //outputting bachelors if bachelors is checked if ($Bachelors == 1) { $success .= "Bachelors"; } //putting a , between associates and certificate only if ($Associates + $Certificate == 2 && $Associates + $Certificate + $Bachelors != 3 ) { $success .= ", "; } //putting a , between bachelors and certificate if ($Bachelors + $Certificate == 2) { $success .= ", "; } //outputting certificate if certificate is checked if ($Certificate == 1) { $success .= "Certificate"; } $success .= "<br />"; } //validating the '$FieldOfStudy' variable if (strlen ($FieldOfStudy) < 10) { $error .= "The Field of study was not able to be accepted. Please try again<br />"; } else { $success .= "Field of Study: $FieldOfStudy<br />"; } //validating the '$GPA' variable if ($GPA == "---") { $error .= "The GPA you selected, $GPA, was invalid, please try again<br />"; } else { $success .= "GPA: $GPA <br />"; } //outputting information if ($error) { echo "<div class='success'>The following is what you have selected:<br /><br />$success</div><br /><br />"; echo "<div class='error'>$error</div>"; include 'form.html'; } else { echo "<div class='success'>The following is what you have selected:<br /><br />$success</div><br />"; //connecting to the database include 'dbconnect.php'; //inserting the information to the database include 'insert.php'; //outputting a success message to the user echo "<div class='success'>The above information has been added to the database.</div>"; } ?> <br /> <strong> Validation Updated: </strong> <!-- #BeginDate format:fcAm1a -->Friday, September 12, 2008 4:03 PM<!-- #EndDate --> </body> </html> Database Connect Script <?php $db = mysqli_connect('localhost','xxxxx', 'xxxxxxx', 'xxxxx'); //mysqi_connect('locahost'),'username', 'password', 'database'); if (!$db) { die('Could not connect: ' . mysql_error()); } else { echo 'You have connected to the database'; } ?> Insert Script <?php mysql_query( "INSERT INTO survey (Name, Age, Month, Day, Year, Hometown, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES ('$Name', '$Age', '$Month', '$DayofBirth','$birthYear', '$hometown', '$State', '$YearofGrad', '$Certificate', '$Associates', '$Bachelors', '$FieldOfStudy', '$GPA' )"); mysql_close() ?> Any help would be hot. Thank you Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/ Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 1) What's the problem in the first place? 2) Date of birth and birth year should not be two separate VARCHAR fields. They should be one single 'birthday' DATE field. Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640067 Share on other sites More sharing options...
Caesar Posted September 12, 2008 Share Posted September 12, 2008 Dude...edit out your MySQL database login info. Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640070 Share on other sites More sharing options...
Caesar Posted September 12, 2008 Share Posted September 12, 2008 Yeah...what is the error you're actually seeing? (Would save time when troubleshooting) Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640071 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 It's his localhost, it doesn't really matter right now. But I'd edit it out anyway, lol. Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640073 Share on other sites More sharing options...
mbrown Posted September 12, 2008 Author Share Posted September 12, 2008 1) What's the problem in the first place? 2) Date of birth and birth year should not be two separate VARCHAR fields. They should be one single 'birthday' DATE field. date of birth and birth year i have that for a reason for another part of the project it will not insert into the database Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640076 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 I can guarantee that whatever you're using the date of birth and birth year for can be done 1000 times better by doing it how it should be done in MySQL. Add or die(mysql_error()); right after mysql_query and post the new error. Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640078 Share on other sites More sharing options...
mbrown Posted September 12, 2008 Author Share Posted September 12, 2008 "No database selected" Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640086 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 I think it's fairly obvious that you shouldn't use mysqli_connect() with mysql_query(), right? You should use the OOP syntax for MySQLi anyway, but even if you won't, you at least need to use mysqli_query(). Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640090 Share on other sites More sharing options...
mbrown Posted September 12, 2008 Author Share Posted September 12, 2008 <?php //$db = mysqli_connect('localhost','bromic94', 'Chris123#', 'bromic94'); //mysql_select_db ("bromic94"); mysqli_query( "INSERT INTO survey (Name, Age, Month, Day, Year, Hometown, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES('$Name', '$Age', '$Month', '$DayofBirth','$birthYear', '$hometown', '$State', '$YearofGrad', '$Certificate', '$Associates', '$Bachelors', '$FieldOfStudy', '$GPA' )", ); die(mysqli_error()); mysqli_close() ?> Error: Parse error: syntax error, unexpected ')' in C:\wamp\www\CIT250\Project\Survey\insert.php on line 6 Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640097 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 If you even tried to debug it, you'd notice the , and blank space after the query. In that blank space belongs $db. Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640098 Share on other sites More sharing options...
mbrown Posted September 12, 2008 Author Share Posted September 12, 2008 I have. I looked over that quick errors: //mysqi_connect('locahost'),'username', 'password', 'database'); mysqli_query( "INSERT INTO survey (Name, Age, Month, Day, Year, Hometown, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES('$Name', '$Age', '$Month', '$DayofBirth','$birthYear', '$hometown', '$State', '$YearofGrad', '$Certificate', '$Associates', '$Bachelors', '$FieldOfStudy', '$GPA' )", $db ); You have connected to the database Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\wamp\www\CIT250\Project\Survey\insert.php on line 6 Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640106 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 My bad, I wasn't paying attention to the fact that it was mysqli_query(), lol. $db goes before the query. If you used the OOP syntax, this would be much easier because you wouldn't need to keep passing $db around. Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640110 Share on other sites More sharing options...
mbrown Posted September 12, 2008 Author Share Posted September 12, 2008 so this for my insert.php file? mysqi_connect('locahost'),'username', 'password', 'database'); mysqli_query( "INSERT INTO survey ($db, Name, Age, Month, Day, Year, Hometown, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES('$Name', '$Age', '$Month', '$DayofBirth','$birthYear', '$hometown', '$State', '$YearofGrad', '$Certificate', '$Associates', '$Bachelors', '$FieldOfStudy', '$GPA' )"); Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640113 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 No, $db has to be the first parameter to mysqli_query(). Do you understand how functions work? mysqli_query($db, "INSERT INTO survey (Name, Age, Month, Day, Year, Hometown, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES('$Name', '$Age', '$Month', '$DayofBirth','$birthYear', '$hometown', '$State', '$YearofGrad', '$Certificate', '$Associates', '$Bachelors', '$FieldOfStudy', '$GPA' )"); Learn how functions work and it'll be much easier to do this. Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640116 Share on other sites More sharing options...
mbrown Posted September 12, 2008 Author Share Posted September 12, 2008 No, $db has to be the first parameter to mysqli_query(). Do you understand how functions work? mysqli_query($db, "INSERT INTO survey (Name, Age, Month, Day, Year, Hometown, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES('$Name', '$Age', '$Month', '$DayofBirth','$birthYear', '$hometown', '$State', '$YearofGrad', '$Certificate', '$Associates', '$Bachelors', '$FieldOfStudy', '$GPA' )"); Learn how functions work and it'll be much easier to do this. Yes i know i had it copied it wrong on here. it still does not work. i will talk to my group mate about it he is much better with php Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640123 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 That's because you took the or die(mysqli_error()); part out of the query. Add it back in. And was that an insult, or were you saying that he's much better than you, or me? Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640125 Share on other sites More sharing options...
mbrown Posted September 12, 2008 Author Share Posted September 12, 2008 he is better than me. you are all wisdom. i dont know you thus i would not insult you thank you for the help thus far. now i get this one which is better than what i had i guess lol Column count doesn't match value count at row 1 Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640134 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 Add back the "or die()" thing and tell me what it says. Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640140 Share on other sites More sharing options...
mbrown Posted September 12, 2008 Author Share Posted September 12, 2008 [code] mysqli_query($db, "INSERT INTO survey (Name, Age, Month, Day, Year, Hometown, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES('$Name', '$Age', '$Month', '$DayofBirth','$birthYear', '$hometown', '$State', '$YearofGrad', '$Certificate', '$Associates', '$Bachelors', '$FieldOfStudy', '$GPA' )"); echo "<br />"; die(mysqli_error($db)); mysqli_close($db) Errors: You have connected to the database Column count doesn't match value count at row 1[/code] Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640147 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 <?php $query = "INSERT INTO survey (Name, Age, Month, Day, Year, Hometown, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES('$Name', '$Age', '$Month', '$DayofBirth','$birthYear', '$hometown', '$State', '$YearofGrad', '$Certificate', '$Associates', '$Bachelors', '$FieldOfStudy', '$GPA')"; mysqli_query($db, $query) or die(mysqli_error() . '<br />' . $query); ?> Post that output. Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640152 Share on other sites More sharing options...
mbrown Posted September 12, 2008 Author Share Posted September 12, 2008 You have connected to the database Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\wamp\www\CIT250\Project\Survey\insert.php on line 18 INSERT INTO survey (Name, Age, Month, Day, Year, Hometown, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES('blah blah', '21', 'x', 'xx','xxxx', 'xxxx', 'xx', '2009', '', '1', '', 'Network Technology', '3.5-4.0') Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640154 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 Woops, make it: <?php $query = "INSERT INTO survey (Name, Age, Month, Day, Year, Hometown, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES('$Name', '$Age', '$Month', '$DayofBirth','$birthYear', '$hometown', '$State', '$YearofGrad', '$Certificate', '$Associates', '$Bachelors', '$FieldOfStudy', '$GPA')"; mysqli_query($db, $query) or die(mysqli_error($db) . '<br />' . $query); ?> Also, why do you have blank fields? Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640155 Share on other sites More sharing options...
mbrown Posted September 12, 2008 Author Share Posted September 12, 2008 Woops, make it: <?php $query = "INSERT INTO survey (Name, Age, Month, Day, Year, Hometown, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES('$Name', '$Age', '$Month', '$DayofBirth','$birthYear', '$hometown', '$State', '$YearofGrad', '$Certificate', '$Associates', '$Bachelors', '$FieldOfStudy', '$GPA')"; mysqli_query($db, $query) or die(mysqli_error($db) . '<br />' . $query); ?> Also, why do you have blank fields? also where do i have blank fields? You have connected to the databaseColumn count doesn't match value count at row 1 INSERT INTO survey (Name, Age, Month, Day, Year, Hometown, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA) VALUES('blah blah', '21', '1', '23','1987', 'waynesbro', 'PA', '2009', '', '1', '', 'Network Technology', '3.5-4.0') Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640157 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 Btw, the problem is that you have Hometown listed twice in the query in the first set of ( ). Bachelors and Certificate are blank. Why not just make an ENUM field for their level of graduation instead of 3 different columns. Read up on database normalization. Link to comment https://forums.phpfreaks.com/topic/123987-solved-html-form-to-database-with-php/#findComment-640159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.