PHP MYSQL SOMEONE PLEASE HELP ME!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phpnovice
Forum Commoner
Posts: 25
Joined: Mon Feb 02, 2004 6:47 am
Location: england, london

PHP MYSQL SOMEONE PLEASE HELP ME!!

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
phpnovice
Forum Commoner
Posts: 25
Joined: Mon Feb 02, 2004 6:47 am
Location: england, london

Post by phpnovice »

thanks. i found the problem when i ran that. i was being stupid. just missed one bracket. sorry.

:oops: James
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

i don't think that's being stupid... being stupid doesn;t have anything to do with that
Post Reply