Hi All,

Help if you can,

The following script wont insert a row into my table.

There is an auto increment field at the start of the table called "ID".

<?php
	// this is processed when the form is submitted
	// back on to this page (POST METHOD)
	if ($_SERVER['REQUEST_METHOD'] == "POST") {

		// double-up apostrophes
		$firstname = $_POST['firstname'];
		$lastname = $_POST['lastname'];
		$email = $_POST['email'];
		$add1 = $_POST['add1'];
		$add2 = $_POST['add2'];
		$town = $_POST['town'];
		$statecounty = $_POST['statecounty'];
		$postzip = $_POST['postzip'];

		// setup SQL statement
		$SQL = " INSERT INTO tbl_sellers";
		$SQL = $SQL . " '', sellerFirstName, sellerLastName, email, Address1, Address2, sellerTownCity, sellerStateProvince, zipPostCode) VALUES ";
		$SQL = $SQL . " ('', '$firstname', '$lastname', '$email','$add1','$add2', '$town', '$statecounty', '$postzip') ";

		//execute SQL statement
		$result = mysql_db_query($db,"$SQL",$cid);

		// check for error
		if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");	}

		echo ("<p><b>New Link Added</b></p>\n");

	}

?>

You have a syntax error, you're missing the beginning parenthesis before the field list. Which this line will tell you.

if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");	}

Hi,

Thanks for your response.

The error i am getting is:
INSERT INTO tbl_sellers (ID, sellerFirstName, sellerLastName, email, Address1, Address2, sellerTownCity, sellerStateProvince, zipPostCode) VALUES ('', 'kjh', '', '','','', '', '', '')

This was a huffy random entry, but the error is in the sql statement???

The columns here match the database, which is what i dont understand.

If ID is autoincrement don't include it in the field or value list.

I have tried it with and without any reference to ID, whatever i do i get the same error message.

i even tried removing the autoincrement from inside the database, and remove ID all together from everything....... but the same.... baffled!

Don't remove ID from the database, just remove it from the field list. Also, what was the error that you got (Not the query, the actual text from ERROR: blah)

Hi,

The exact error, copied from the screen is:
ERROR: INSERT INTO tbl_sellers (sellerFirstName, sellerLastName, email, Address1, Address2, sellerTownCity, sellerStateProvince, zipPostCode) VALUES ('h', 'h', 'j','k','hg', 'g', 'ug', 'h')

which is also wierd!

ive checked through some syntax of other times ive done this and its all the same. Ive a boogie man in my code

What is the value of $db by the way. I don't see you setting it anywhere. Or $cid for that matter.

ive just put an echo into my connection string and its showing Resource id #1

that is the form.

here it is

<?php

	// insert_link.phps from blazonry.com
	// part of the web database tutorial for MySQL and PHP 


	$usr = "*******";
	$pwd = "*******";
	$db = "*******";
	$host = "localhost";

	// connect to database
	echo $cid = mysql_connect($host,$usr,$pwd);
	if (!$cid) { echo("ERROR: " . mysql_error() . "\n");	}

?>
<html>
<head>
   <title>blazonry.com database tutorial - Insert Data lesson</title>

</head>
<body bgcolor="#ffffff">

<p><font size=5><b> Add Link </b> </font></p>



<form name="fa" action="insert_link.php" method="post">
<table>
<tr><td><b>First Name: </b> </td><td><input type="text" name="firstname" size=40></td></tr>
<tr><td><b>Surname:</b> </td><td><input type="text" name="lastname" size=40></td></tr>
<tr><td><b>Email: </b> </td><td><input type="text" name="email" size=40></td></tr>
<tr><td><b>Address 1:</b> </td><td><input type="text" name="add1" size=40></td></tr>
<tr><td><b>Address 2: </b> </td><td><input type="text" name="add2" size=40></td></tr>
<tr><td><b>Town:</b> </td><td><input type="text" name="town" size=40></td></tr>
<tr><td><b>County: </b> </td><td><input type="text" name="statecounty" size=40></td></tr>
<tr><td><b>Post Code:</b> </td><td><input type="text" name="postzip" size=40></td></tr>

<tr><th colspan=2><p><input type="submit" value="submit"></p></th></tr>
</table>
</form>


</body>
</html>

that is the form.

here it is

<?php

	// insert_link.phps from blazonry.com
	// part of the web database tutorial for MySQL and PHP 


	$usr = "*******";
	$pwd = "*******";
	$db = "*******";
	$host = "localhost";

	// connect to database
	echo $cid = mysql_connect($host,$usr,$pwd);
	if (!$cid) { echo("ERROR: " . mysql_error() . "\n");	}

?>
<html>
<head>
   <title>blazonry.com database tutorial - Insert Data lesson</title>

</head>
<body bgcolor="#ffffff">

<p><font size=5><b> Add Link </b> </font></p>



<form name="fa" action="insert_link.php" method="post">
<table>
<tr><td><b>First Name: </b> </td><td><input type="text" name="firstname" size=40></td></tr>
<tr><td><b>Surname:</b> </td><td><input type="text" name="lastname" size=40></td></tr>
<tr><td><b>Email: </b> </td><td><input type="text" name="email" size=40></td></tr>
<tr><td><b>Address 1:</b> </td><td><input type="text" name="add1" size=40></td></tr>
<tr><td><b>Address 2: </b> </td><td><input type="text" name="add2" size=40></td></tr>
<tr><td><b>Town:</b> </td><td><input type="text" name="town" size=40></td></tr>
<tr><td><b>County: </b> </td><td><input type="text" name="statecounty" size=40></td></tr>
<tr><td><b>Post Code:</b> </td><td><input type="text" name="postzip" size=40></td></tr>

<tr><th colspan=2><p><input type="submit" value="submit"></p></th></tr>
</table>
</form>


</body>
</html>

i had a thought that it could be lack of a database name, so i used dot notation in the sql, but to no avail and same error

Is all of this code on the same page? If the connection isn't opened on the same page as the one that executes it then it isn't defined.

it doesnt, the form.php uses the php code, defined in the top of the form.

It has to be sending it accross, as the error contains what i input into the form

it doesnt, the form.php uses the php code, defined in the top of the form.

It has to be sending it accross, as the error contains what i input into the form

If the only way the two are connect is because one page POSTs to the other then you need to have the connection code in both places.

Your query keeps morphing so it's difficult for someone to keeps up.
For test purposes, why not stick with a single query and get THAT working. move on to the next issue?
Put the auto -increment ID back and:

INSERT INTO tbl_sellers (sellerFirstName, sellerLastName, email, Address1, Address2, sellerTownCity, sellerStateProvince, zipPostCode) VALUES ('h', 'h', 'j','k','hg', 'g', 'ug', '12345')

What is the table structure?
If zip is cast to int, the 'h' wont fly.

champion!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

3 points

champion!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

3 points

Great! Please mark as solved...
Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.