|
-
Jun 3rd, 2009, 05:32 AM
#1
Thread Starter
New Member
Problem in PHP..
I have created a form that sends data in my database sql. Thats goes well only if the fields are empty, data is transmitted in the base. I try to use the empty but it not work, My friend told me to use the trim but that also didn't work.
Here are the coding so that you can know better
php Code:
<? php
mysql_connect ( "localhost", "root", "") OR die ( 'Error selecting database');
mysql_select_db ( "camping") or die ( 'Error selecting database');
/ / (=> Useless
$ name = $ _POST [ 'name'];
$ first_name = $ _POST [ 'firstname'];
$ address = $ _POST [ 'address'];
$ PostalCode = $ _POST [ 'PostalCode'];
$ city = $ _POST [ 'city'];
$ telephone = $ _POST [ 'telephone'];
$ mail = $ _POST [ 'mail'];
$ message = $ _POST [ 'message'];
if (empty ($ name) & & ($ firstname) & & empty ($ address) & & empty ($ PostalCode) & & empty ($ city) & & empty ($ telephone) & & empty ($ mail) & & empty ($ message))
(
echo ( "There is an empty field");
) else
(
echo ( "fields filled");
)
$ req = mysql_query ( 'INSERT INTO clients (name, surname, address, Postcode, city, telephone, mail, message) VALUES ("'.$ name.' "" '. $ firstname.' "" '. $ address. ' ""'. $ PostalCode. ' ""'. $ city. ' ""'. $ telephone. ' ""'. $ mail. ' ""'. $ message. ") ') or die (mysql_error ());
if ($ req)
(
echo 'enregisttrement reussi';
)
else
(
echo 'There was a problem <br/>. $ req;
)
mysql_close ();
>
Can someone help me ?
Thanks
edit by admin: no commercial URLs on the forum please
Last edited by Hack; Jun 3rd, 2009 at 09:25 AM.
Reason: Added PHP Code Tags
-
Jun 3rd, 2009, 03:06 PM
#2
Re: Problem in PHP..
use "||" (OR) instead of "&&" (AND). your check using empty() is checking if -all- fields are empty because AND requires all of those to return true; OR only requires one to return true.
PHP Code:
if(empty($name) || ($firstname) || empty($address) || empty($PostalCode) || empty($city) || empty ($telephone) || empty($mail) || empty ($message)){
//there was an empty field echo "some field was empty";
}else{
//no empty fields //your mysql insert stuff should go here
}
-
Jun 18th, 2009, 05:50 AM
#3
Junior Member
Re: Problem in PHP..
For security I suggest you use classes to put your sql stuff in and never use die(mysql_error()) for production
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|