Page 1 of 1
whats wrong in this code
Posted: Thu Feb 26, 2009 8:06 am
by naeem1984
Code: Select all
$query = "insert into client set name='$_POST[name]', email='$_POST[email]', address='$_POST[address]',
web_programming='1',
desktop_programming='2',
hosting/registration='3' ";
this code could not insert data in database.
if we write the following code it works.
Code: Select all
$query = "insert into client set name='$_POST[name]', email='$_POST[email]', address='$_POST[address]',
but when we write full code it not works.
Re: whats wrong in this code
Posted: Thu Feb 26, 2009 8:21 am
by jayshields
It's not really a good idea to put forward slashes in field names, but if it actually works, then it should work fine in your query if you use backticks. Also, you should be putting string array indices in single quotes. Change your initial query to this:
Code: Select all
$query = "INSERT INTO `client` SET `name`= '{$_POST['name']}', `email` = '{$_POST['email']}', `address` = '{$_POST['address']}', `web_programming` = '1', `desktop_programming` = '2', `hosting/registration` = '3'";
I assume all your fields are strings, because the last 3 values should be without single quotes if they are to be taken as integers. I also advise you to use the original INSERT syntax, it makes more sense than to use this syntax which looks like an UPDATE query. You can see the original INSERT syntax in the first example in the
manual.