quick help with my tag board script.

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
synix
Forum Newbie
Posts: 6
Joined: Sun Apr 27, 2003 2:02 pm
Location: medford, ma

quick help with my tag board script.

Post by synix »

Code: Select all

<? 
$xname = "$name"; 
$xmsg = "$msg"; 
$xemail = "$email"; 
$xurl = "$url"; 
$glog = "guestlog.php"; 
$fp = fopen ($glog, "a"); 
$split = " - "; 
if (!$xname || !$xmsg) { 
echo("one or more required fields were left blank."); 
fputs ($fp,"<a href="mailto:$xemail">$xname</a>$split<a href="$xurl">www</a>$split$xmsg<br><br>"); 
exit; 
} 
if ($xname || $xmsg) { 
echo("thank you, <b>$xname</b>, for your comment.<br><br>"); 
include("guestlog.php"); 
exit; 
} 
?>
this is my script... as u can tell i am a beginner. the problem i am having is that when someone submits a comment with no name or message the fputs () statement still writes onto the file and all that shows up is - www - for the website link. does any1 know how i can end the fputs () statement if no name nor message has been provided in the fields? if u need more knowlege of my problem my aim sn is 'discipline card'. thanks.
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Re: quick help with my tag board script.

Post by []InTeR[] »

Code: Select all

<? 
$xname = "$name"; 
$xmsg = "$msg"; 
$xemail = "$email"; 
$xurl = "$url"; 
$glog = "guestlog.html"; // this was a huge security risk. 
$fp = fopen ($glog, "a"); 
$split = " - "; 
if (!$xname || !$xmsg) { 
echo("one or more required fields were left blank."); 
unset($output);
if($xemail!="") $output.= "<a href="mailto:$xemail">";
if($xname!="") $output.= $xname;
if($xemail!="") $output.= "</a>";
$output .= $split; // ?
if($xurl!="") $output.= "<a href="$xurl">www</a>";
$output.= $split.$split.$xmsg."<br><br>"; 
fputs ($fp,$output);
fclose($fp);
exit; 
} 
if ($xname || $xmsg) { 
echo "thank you, <b>$xname</b>, for your comment.<br><br>"; 
include("guestlog.html"); 
exit; 
} 
?>
Something like this, but it's late so there i a change it's not working :P
synix
Forum Newbie
Posts: 6
Joined: Sun Apr 27, 2003 2:02 pm
Location: medford, ma

nice try inter

Post by synix »

i appreciate ur efforts to help but that didn't work the - www - still shows up. = \.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

http://www.devnetwork.net/forums/viewtopic.php?t=511
would be something to look at which would make your script something like the code below (haven't tested it, it's quite late here) - provided you use POST in your form. If you use GET change $_POST to $_GET.

Code: Select all

<?php

$xname = $_POST["name"];
$xmsg = $_POST["msg"];
$xemail = $_POST["email"];
$xurl = $_POST["url"];
$glog = "guestlog.html"; // this was a huge security risk.
$fp = fopen ($glog, "a");
$split = " - ";
if (!$_POST["xname"] || !$_POST["xmsg"]) {
echo("one or more required fields were left blank.");
unset($output);
if($_POST["xemail"]) 
   {$output.= "<a href="mailto:".$_POST["xemail"]."">";}
if($_POST["xname"]) 
   {$output.= $xname;}
if($_POST["xemail"]) 
   {$output.= "</a>";}
$output .= $split; // ?
if($_POST["xurl"]) 
   {$output.= "<a href="".$_POST["xurl"]."">www</a>";}
$output.= $split.$split.$_POST["xmsg"]."<br><br>";
fputs ($fp,$output);
fclose($fp);
exit;
}
if ($_POST["xname"] || $_POST["xmsg"]) {
echo "thank you, <b>".$_POST["xname"]."</b>, for your comment.<br><br>";
include("guestlog.html");
exit;
}

?>
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Actually, to check if the text boxs have something inside, simply do a

if(!empty($xname)) { // add in name }
Image Image
synix
Forum Newbie
Posts: 6
Joined: Sun Apr 27, 2003 2:02 pm
Location: medford, ma

thanks

Post by synix »

ty for all of your help guys.
Post Reply