Page 1 of 1

quick help with my tag board script.

Posted: Sun Apr 27, 2003 6:26 pm
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.

Re: quick help with my tag board script.

Posted: Sun Apr 27, 2003 7:05 pm
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

nice try inter

Posted: Sun Apr 27, 2003 7:11 pm
by synix
i appreciate ur efforts to help but that didn't work the - www - still shows up. = \.

Posted: Sun Apr 27, 2003 8:25 pm
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;
}

?>

Posted: Sun Apr 27, 2003 9:18 pm
by phice
Actually, to check if the text boxs have something inside, simply do a

if(!empty($xname)) { // add in name }

thanks

Posted: Mon Apr 28, 2003 7:49 pm
by synix
ty for all of your help guys.