Page 1 of 1

PHP MYSQL SOMEONE PLEASE HELP ME!!

Posted: Thu Feb 12, 2004 10:42 am
by phpnovice
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.

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();



?>
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

Posted: Thu Feb 12, 2004 11:01 am
by JayBird
ad this line after you create the query to see what the query that you generate actually looks like, then post the result back here

Code: Select all

print $custentQuery;
Mark

Posted: Thu Feb 12, 2004 4:49 pm
by phpnovice
thanks. i found the problem when i ran that. i was being stupid. just missed one bracket. sorry.

:oops: James

Posted: Thu Feb 12, 2004 8:25 pm
by Cruzado_Mainfrm
i don't think that's being stupid... being stupid doesn;t have anything to do with that