Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
(Help Needed) To Disable Posting Null Comments in Guestbook
Old 03-25-2009, 03:48 AM (Help Needed) To Disable Posting Null Comments in Guestbook
Haris's Avatar
Novice Talker

Posts: 11
Name: Ali Haris
Trades: 0
Hello..!!

I created a Guestbook. But people can submit comments without writing any thing in the field. I mean they can submit null (empty) comments. Can anyone help me to fix this?? I tried to fix this.. but I couldn't

Here is the source code of form action file (addguestbook.php)

Code:
<?php
include("config.php");
$tbl_name="xxx"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$dbname")or die("cannot select DB");


$datetime=date("y-m-d h:i:s"); //date time

$name = htmlentities($name);
$email = htmlentities($email);
$comment = htmlentities($comment);

$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysql_query($sql);

//check if query successful
if($result){
header ("Location:comments.php");
}

else {
echo "ERROR";
}

mysql_close();
?>
Haris is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-25-2009, 03:52 AM Re: (Help Needed) To Disable Posting Null Comments in Guestbook
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
check for the comments field being empty and if it is ...


... don't add it to the database
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-25-2009, 03:54 AM Re: (Help Needed) To Disable Posting Null Comments in Guestbook
Haris's Avatar
Novice Talker

Posts: 11
Name: Ali Haris
Trades: 0
It automatically adds the comments to Database..!! i want disable submitting empty comments through PHP we can do it.. But I dont know how to apply it
Haris is offline
Reply With Quote
View Public Profile
 
Old 03-25-2009, 05:41 AM Re: (Help Needed) To Disable Posting Null Comments in Guestbook
dark_lord's Avatar
Experienced Talker

Posts: 41
Name: Parijat Roy
Location: INDIA-KOLKATA
Trades: 0
here the above modified code
PHP Code:
<?php
include("config.php");
$tbl_name="xxx"// Table name

// Connect to server and select database.
mysql_connect("$host""$username""$password")or die("cannot connect server ");
mysql_select_db("$dbname")or die("cannot select DB");


$datetime=date("y-m-d h:i:s"); //date time

$name htmlentities($name);
$email htmlentities($email);
$comment htmlentities($comment);


$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
if(
$comment!="")
$result=mysql_query($sql);

//check if query successful
if($result){
header ("Location:comments.php");
}

else {
echo 
"ERROR";
}

mysql_close();
?>
just put this
if($comment!="")
before inserting the comment into the database as shown above
__________________
I AM THE BEAUTIFUL NIGHTMARE

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
dark_lord is offline
Reply With Quote
View Public Profile Visit dark_lord's homepage!
 
Old 03-25-2009, 05:42 AM Re: (Help Needed) To Disable Posting Null Comments in Guestbook
Extreme Talker

Posts: 189
Trades: 0
this code might work the way you want.

PHP Code:
<?php
include("config.php");
$tbl_name="xxx"// Table name

// Connect to server and select database.
mysql_connect("$host""$username""$password")or die("cannot connect server ");
mysql_select_db("$dbname")or die("cannot select DB");


$datetime=date("y-m-d h:i:s"); //date time

$name htmlentities($name);
$email htmlentities($email);
$comment htmlentities($comment);

if (empty(
$comment)) {
mysql_close();
echo 
"ERROR";
}
else {
$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysql_query($sql);

//check if query successful
if($result){
header ("Location:comments.php");
}

else {
echo 
"ERROR";
}

mysql_close();
}
?>
simster is offline
Reply With Quote
View Public Profile
 
Old 03-25-2009, 10:08 AM Re: (Help Needed) To Disable Posting Null Comments in Guestbook
Haris's Avatar
Novice Talker

Posts: 11
Name: Ali Haris
Trades: 0
Thanks simster.. It works

and thanks every for replies
Haris is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to (Help Needed) To Disable Posting Null Comments in Guestbook
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 3.17935 seconds with 12 queries