hunter85 Posted March 11, 2008 Share Posted March 11, 2008 Hello, I am totally new to mysql/php i have a marquee business and I have followed a tutorial to create a basic form for my customers to fill out to request details. The db fields are general sort of thing name address phone number etc with a couple of drop down lists on the form created in dw i have linked the db and the form together okay. All of the field types I have are varchar following the tutorial and not null. when testing the form I get error Column 'phone no' cannot be null so I thought it may have to be "int" or "bigint" didn’t make no difference and the postcode field doesn’t actually input the data typed nor does the drop down list and just puts a single number. not only this when the form is submitted it send it 6 times to the db I have done something seriously wrong or have I missed some code or what? . Can anybody link me to a good tutorial or lend a helping hand. regards Dan Quote Link to comment https://forums.phpfreaks.com/topic/95626-mysql-v5051-php-form-help/ Share on other sites More sharing options...
fenway Posted March 11, 2008 Share Posted March 11, 2008 Post your INSERT statement. Quote Link to comment https://forums.phpfreaks.com/topic/95626-mysql-v5051-php-form-help/#findComment-489587 Share on other sites More sharing options...
hunter85 Posted March 11, 2008 Author Share Posted March 11, 2008 ok right is it the following... if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text"), GetSQLValueString($_POST['postcode'], "text"), GetSQLValueString($_POST['email'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, `phone no`, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text"), GetSQLValueString($_POST['postcode'], "text"), GetSQLValueString($_POST['phone no'], "text"), GetSQLValueString($_POST['email'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, `phone no`, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text"), GetSQLValueString($_POST['postcode'], "text"), GetSQLValueString($_POST['phone no'], "text"), GetSQLValueString($_POST['email'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, `phone no`, `mobile no`, `site address`, `date of function`, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text"), GetSQLValueString($_POST['postcode'], "text"), GetSQLValueString($_POST['phone no'], "text"), GetSQLValueString($_POST['mobile no'], "text"), GetSQLValueString($_POST['site address'], "text"), GetSQLValueString($_POST['date of function'], "date"), GetSQLValueString($_POST['email'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, `date of function`, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text"), GetSQLValueString($_POST['postcode'], "text"), GetSQLValueString($_POST['date of function'], "date"), GetSQLValueString($_POST['email'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, `phone no`, `mobile no`, `site address`, `date of function`, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text"), GetSQLValueString($_POST['postcode'], "text"), GetSQLValueString($_POST['phone no'], "text"), GetSQLValueString($_POST['mobile no'], "text"), GetSQLValueString($_POST['site address'], "text"), GetSQLValueString($_POST['date of function'], "date"), GetSQLValueString($_POST['email'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) { $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, `phone no`, `mobile no`, `site address`, `date of function`, `type of function`, `no of guests`, `is the function a surprise`, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['firstName'], "text"), GetSQLValueString($_POST['lastName'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['county'], "text"), GetSQLValueString($_POST['postcode'], "text"), GetSQLValueString($_POST['phone no'], "text"), GetSQLValueString($_POST['mobile no'], "text"), GetSQLValueString($_POST['site address'], "text"), GetSQLValueString($_POST['date of function'], "date"), GetSQLValueString($_POST['type of function'], "text"), GetSQLValueString($_POST['no of guests'], "text"), GetSQLValueString($_POST['is the function a surprise'], "text"), GetSQLValueString($_POST['email'], "text")); mysql_select_db($database_lmhc, $lmhc); $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error()); } ok am i right in thinking that it is repeated several times which is where the multple entries are coming from thanks dan Quote Link to comment https://forums.phpfreaks.com/topic/95626-mysql-v5051-php-form-help/#findComment-489663 Share on other sites More sharing options...
fenway Posted March 11, 2008 Share Posted March 11, 2008 That's your ENTIRE code block -- not very helpful. And yes, no need to repeat everything! Also, there's a space in your column name... difficult to work with in the long-run. what i'd like to see if an echo of $insertSQL along with your die() statement -- and figure out which one it is. Quote Link to comment https://forums.phpfreaks.com/topic/95626-mysql-v5051-php-form-help/#findComment-489735 Share on other sites More sharing options...
hunter85 Posted March 12, 2008 Author Share Posted March 12, 2008 thanks for your reply dam im lost now! Sorry this is new to me im trying! do you mind explaining where that info is? i created the form in dreamweaver if that helps cheers Quote Link to comment https://forums.phpfreaks.com/topic/95626-mysql-v5051-php-form-help/#findComment-490092 Share on other sites More sharing options...
fenway Posted March 12, 2008 Share Posted March 12, 2008 You have line with mysql_query() and die()... just make sure you echo the SQL statement with the die(), and include some text to locate the error. Quote Link to comment https://forums.phpfreaks.com/topic/95626-mysql-v5051-php-form-help/#findComment-490385 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.