PHP MYSQL SOMEONE PLEASE HELP ME!!
Posted: Thu Feb 12, 2004 10:42 am
hi im wondering if anyone can help with some php for inserting from a form to a mysql db. i have done some validation but keep getting sql syntax errors reported.
can anyone see why i keep getting these errors, ive tried a 100 different ways of using single/double quotes and concatenation but cant seem to get it to work.
Cheers
James
Code: Select all
<?php
//clean posted variables
foreach($_POST as $varname => $value)
$formVars[$varname] = trim($value, 64);
//some validation is here then
//then this
//connect to mysql with some error handling
if (!($connection = @ mysql_pconnect($host, $user, $passwd)))
die("Could not connect to the database");
//select my database with some error handling
if(!(mysql_select_db($dbName, $connection)))
showerror();
//create query for insert into customer table
$custentQuery= "INSERT INTO customer(cust_name,addr1,addr2,addr3,postcode,email,passwd)values('" . $formVars["custName"] . "','" . $formVars["custAddress1"] ."','" . $formVars["custAddress2"] . "','" . $formVars["custAddress3"] . "','" . $formVars["custPostcode"] . "','" . $formVars["custEmail"] . "','" . $formvars["custPass1"] . "'";
//run query with some error handling
if(!(@ mysql_query($custentQuery,$connection)))
die(mysql_error().'<br/>'.$query);
//close connection with some error handling
if(! mysql_close($connection))
showerror();
?>Cheers
James