Jump to content

[SOLVED] HTML form to database with php


mbrown

Recommended Posts

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
Share on other sites

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
Share on other sites


<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

[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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.