Jump to content

(Beginner) Writing to MySQL from form input


nathansizemore

Recommended Posts

Hello, all!

I am trying to learn PHP and MySQL on my own, and need some debugging help.  What exactly is going wrong here?  I am following a tutorial and trying to write the code as it says, but am still having trouble with syntax.

Running a WAMP, PHP5.3, and MySQL5.5.  This is my code:

<html>
<body>
<form 	name = "newVenue" method = "post">

	Establishment name: <input  type = "text" name = "name">
	<br>
	Street Address:	<input	type = "text" name = "streetAddress">
	<br>
	City:	<input 	type = "text" name = "city">
	<br>
	State: <select name="state">
				<option value="AL">AL</option>
				<option value="AK">AK</option>
				<option value="AZ">AZ</option>
				<option value="AR">AR</option>
				<option value="CA">CA</option>
				<option value="CO">CO</option>
				<option value="CT">CT</option>
				<option value="DE">DE</option>
				<option value="DC">DC</option>
				<option value="FL">FL</option>
				<option value="GA">GA</option>
				<option value="HI">HI</option>
				<option value="ID">ID</option>
				<option value="IL">IL</option>
				<option value="IN">IN</option>
				<option value="IA">IA</option>
				<option value="KS">KS</option>
				<option value="KY">KY</option>
				<option value="LA">LA</option>
				<option value="ME">ME</option>
				<option value="MD">MD</option>
				<option value="MA">MA</option>
				<option value="MI">MI</option>
				<option value="MN">MN</option>
				<option value="MS">MS</option>
				<option value="MO">MO</option>
				<option value="MT">MT</option>
				<option value="NE">NE</option>
				<option value="NV">NV</option>
				<option value="NH">NH</option>
				<option value="NJ">NJ</option>
				<option value="NM">NM</option>
				<option value="NY">NY</option>
				<option value="NC">NC</option>
				<option value="ND">ND</option>
				<option value="OH">OH</option>
				<option value="OK">OK</option>
				<option value="OR">OR</option>
				<option value="PA">PA</option>
				<option value="RI">RI</option>
				<option value="SC">SC</option>
				<option value="SD">SD</option>
				<option value="TN">TN</option>
				<option value="TX">TX</option>
				<option value="UT">UT</option>
				<option value="VT">VT</option>
				<option value="VA">VA</option>
				<option value="WA">WA</option>
				<option value="WV">WV</option>
				<option value="WI">WI</option>
				<option value="WY">WY</option>
			</select>
	<br>
	Zip: 	<input	type = "text" name = "zip">
	<br>
	email:	<input	type = "text" name = "email">
	<br>
	password: <input type  = "text" name = "password">
	<br>
	<input  type="submit" name="Submit"  value="Submit">
</form>

<?php

//If the form isn't empty, assign the value to a variable
if (!empty($_POST['name']))
{
	$name = $_POST['name'];
	$address = $_POST['streetAddress'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$zip = $_POST['zip'];
	$email = $_POST['email'];
	$password = $_POST['password'];

	//Connect to the 'Users' database and store the new bar into the 'Venue' table...
	mysql_connect ("localhost", "newbar", "Jpr5HJ2K5fWvPLXq") or die ('Oh, fuck: '.mysql_error());
	mysql_select_db ("users");
	$query = "INSTERT INTO venues VALUES ('NULL', 'testPic.jpg', '".$name."', '".$address."', '".$city."', '".$state."', '".$zip."', '".$email."', '".$password."', 0)";
	mysql_query($query) or die ('Oh, fuck: '.mysql_error());
	echo "Damn, Nathan.  This shit actually worked...";
}
?>
</body>
</html>

This is the error I receive:

Oh, fuck: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSTERT INTO venues VALUES ('NULL', 'testPic.jpg', 'Nathan's house', '666', 'DAY' at line 1

This is my table:

id              INT PRIMARY KEY
pic_location    VARCHAR
name            VARCHAR
address         VARCHAR
city            VARCHAR
state           VARCHAR
zip             VARCHAR
email           VARCHAR
password        VARCHAR
event_name      INT

 

Any thoughts as to what is causing this error?  Thanks in advance...

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.