zc1 Posted January 18, 2008 Share Posted January 18, 2008 Hi, I am trying to get this form to work however I am getting now where. Part of HTML Form code <form action="<? echo $PHP_SELF; ?>" method="post"> <input type="text" size="60" name="Title" value="<? echo $Title; ?>"> <input type="hidden" name="Returned" value="1"> <input type="hidden" name="CalendarDetailsID" value=""> <input type="hidden" name="LocationID" value="<? echo $LocationID; ?>"> <input type="submit" value="Add Event >>"></form> Then I have some PHP code which is if ($Returned == 1 AND !$Title) { ...... Also } elseif ($Returned == 1) { Every time I don't fill in the title it loops back to a blank form, instead of getting an error If I do fill in the title it still loops back to the form and does not submit to database What I am trying to do is use the hidden Returned code with the value 1, to submit the form to the database or give an error, but it is just looping Has anyone got any ideas of the problem ? I am running PHP 5.2.5 I think or that what phpinfo tells me, but cPanel tells me 5.2.3. Regards, Garry Quote Link to comment https://forums.phpfreaks.com/topic/86628-solved-php_self-if-and-html-form/ Share on other sites More sharing options...
adam291086 Posted January 18, 2008 Share Posted January 18, 2008 we need to see more code. I.e the loop Quote Link to comment https://forums.phpfreaks.com/topic/86628-solved-php_self-if-and-html-form/#findComment-442660 Share on other sites More sharing options...
zc1 Posted January 18, 2008 Author Share Posted January 18, 2008 Hi, The code I didn't write it a script that doesn't work so the php code for the daily event is below, hope this is what you wanted if ($Returned == 1 AND !$Title) { commonHeader($glbl_SiteTitle); echo "<center><font color=\"red\"><b>You did not specify an EVENT NAME OR TITLE. Please complete the form below.</b></font></center><p>\n\n"; // the common data checks out, lets check our other data } elseif ($Returned == 1) { // set the Active state based on the config option if ($glbl_ApprovePublicSubmission != 1) { $Active = 1; } else { $Active = 0; } // START CHECKS FOR DAILY EVENTS if ($EventType == "Daily") { // check the start date if (!checkdate($DailyStartMonth, $DailyStartDay, $DailyStartYear)) { commonHeader("Add an item"); echo "<center><font color=\"red\"><b>You specified an INVALID START DATE. Please complete the form below.</b></font></center><p>\n\n"; $Stop = 1; // check the end date } elseif ($DailyStopMonth AND (!checkdate($DailyStopMonth, $DailyStopDay, $DailyStopYear))) { commonHeader($glbl_SiteTitle); echo "<center><font color=\"red\"><b>You specified an INVALID END DATE. Please complete the form below.</b></font></center><p>\n\n"; $Stop = 1; } // Compile the dates $StartDate = $DailyStartYear."-".$DailyStartMonth."-".$DailyStartDay; $StopDate = $DailyStopYear."-".$DailyStopMonth."-".$DailyStopDay; // make sure the start comes before the stop if ($DailyStopYear) { $result = mysql("$DBName","SELECT (TO_DAYS('$StopDate') - TO_DAYS('$StartDate'))") or die(mysql_error()); while ($row = mysql_fetch_row($result)) { $dateDiff = $row[0]; } } else { $dateDiff = 0; } // somebody was trying to trick by making a stop date // before it was started if ($dateDiff < 0) { commonHeader($glbl_SiteTitle); echo "<center><font color=\"red\"><b>Your END DATE COMES BEFORE YOUR START DATE. Please complete the form below.</b></font></center><p>\n\n"; // all of our checks on the surface data was good } elseif ($Stop != 1) { // check to see if the CalendarLocation already exists if (!$EventLocationID) { $result = mysql("$DBName","SELECT EventLocationID FROM phpCalendar_EventLocations WHERE LocationID = '$LocationID' AND Title = '$CLTitle' AND Address1 = '$Address1' AND Address2 = '$Address2' AND City = '$City' AND State = '$State'") or die(mysql_error()); $CountLocations = mysql_num_rows($result); } else { $CountLocations = 99; } if ($CountLocations > 0 AND $CountLocations < 99) { while($row = mysql_fetch_row($result)) { $EventLocationID = $row[0]; } } elseif ($CountLocations != 99 AND $CLTitle) { mysql("$DBName","INSERT INTO phpCalendar_EventLocations VALUES ( '$CLTitle','$Address1','$Address2','$City','$State','$Zip','$LocationID','')") or die(mysql_error()); $result = mysql("$DBName","SELECT LAST_INSERT_ID() FROM phpCalendar_EventLocations") or die(mysql_error()); while ($row = mysql_fetch_row($result)) { $EventLocationID = $row[0]; } } // if the web address doesn't begin with http:// if ($ContactWeb AND !eregi("http://",$ContactWeb)) { $ContactWeb = "http://".$ContactWeb; } // format the times if ($StartPeriod == PM AND $StartHour != 12) { $StartHour += 12; } elseif ($StartPeriod == AM AND $StartHour == 12) { $StartHour = 0; } if ($EndPeriod == PM AND $EndHour != 12) { $EndHour += 12; } elseif ($EndPeriod == AM AND $EndHour == 12) { $EndHour = 0; } $StartTime = $StartHour.":".$StartMinute; $EndTime = $EndHour.":".$EndMinute; // we can insert now mysql("$DBName","INSERT INTO phpCalendar_Details VALUES ( '$Title','$Details','$ContactName','$ContactPhone','$ContactEmail','$ContactWeb', '$EventLocationID','$StartTime','$EndTime','$ShowStart','$ShowEnd', '$LocationID','$CalendarDetailsID')") or die(mysql_error()); $result = mysql("$DBName","SELECT LAST_INSERT_ID() FROM phpCalendar_Details") or die(mysql_error()); while ($row = mysql_fetch_row($result)) { $CalendarDetailsID = $row[0]; } mysql("$DBName","INSERT INTO phpCalendar_Daily VALUES( '$StartDate','$StopDate','$Active','$LocationID','$CalendarDetailsID')") or die(mysql_error()); // do we send a notification and to whom? if ($glbl_ApprovePublicSubmission == 1 AND ($glbl_ApprovalBySiteAdmin == 1 OR !$LocationID)) { $MailTo = $glbl_AdminEmail; $AddrVar = $glbl_AdminRoot; } elseif ($glbl_ApprovePublicSubmission == 1) { $result = mysql("$DBName","SELECT Email FROM phpCalendar_AdminUsers WHERE LocationID = '$LocationID'") or die(mysql_error()); while ($row = mysql_fetch_row($result)) { $MailTo = $row[0]; } $AddrVar = $glbl_WebAdminRoot; } // what if we still don't have an address? if (!$MailTo) { $MailTo = $glbl_AdminEmail; $AddrVar = $glbl_AdminRoot; } $Message = " A request has been generated from your web site for a calendar submission to be approved. Visit the address: ".$glbl_WebAddress.$AddrVar." Once logged in, select the \"Pending event administration\" link. Thank you. "; mail($MailTo, $glbl_EmailSubject, $Message, "From: $glbl_MailFrom", "-f$MailTo"); Header("Location: ./thankyou.php?LocationID=$LocationID"); exit; } // END CHECKS FOR DAILY EVENTS Regards, Garry Quote Link to comment https://forums.phpfreaks.com/topic/86628-solved-php_self-if-and-html-form/#findComment-442663 Share on other sites More sharing options...
zc1 Posted January 18, 2008 Author Share Posted January 18, 2008 Hi, Thought I would post the form code to <form action="<? echo $PHP_SELF; ?>" method="post"> <center> <!-- TABLE FOR DAILY EVENTS --> <center> <table width="100%" border="0" cellpadding="4" bgcolor="#C9C9C9"> <tr> <td valign="top" colspan="2"><center> <b>One-Time Events</b> </center></td> </tr> <tr> <td valign="top" colspan="2"> <? if ($EventType == "Daily") { echo "<input type=\"radio\" name=\"EventType\" value=\"Daily\" CHECKED> "; } else { echo "<input type=\"radio\" name=\"EventType\" value=\"Daily\"> "; } ?> Check here if this is a one-time event or multiple day event that will only happen once. <a href="./calDaily.php" onClick=return(openSmallWindow('./calDaily.php'))>What's This?</a> </td></tr> <tr> <td valign="top"><b>Start date:</b><br> <? if (!$DailyStartYear) { $DailyStartYear = date("Y"); } if (!$DailyStartMonth) { $DailyStartMonth = date("m"); } if (!$DailyStartDay) { $DailyStartDay = date("d"); } // get the month echo "<select name=\"DailyStartMonth\">\n"; for ($i = 1; $i <= 12; $i++) { if ($i < 10 AND !ereg("^0",$i)) { $i = "0".$i; } $showMonth = date("F",mktime(0,0,0,$i,1,date("Y"))); if ($DailyStartMonth == $i) { echo "<option value=\"$i\" SELECTED> $showMonth </option>\n"; } else { echo "<option value=\"$i\"> $showMonth </option>\n"; } } echo "</select> \n\n"; // get the day echo "<select name=\"DailyStartDay\">\n"; for ($i = 1; $i <= 31; $i++) { if ($i < 10 AND !ereg("^0",$i)) { $i = "0".$i; } $showDay = date("dS",mktime(0,0,0,01,$i,$DailyStartYear)); if ($DailyStartDay == $i) { echo "<option value=\"$i\" SELECTED> $showDay </option>\n"; } else { echo "<option value=\"$i\"> $showDay </option>\n"; } } echo "</select> \n\n"; // get the year echo "<select name=\"DailyStartYear\">\n"; for ($i = (date("Y") - 1); $i <= (date("Y") + 5); $i++) { if ($DailyStartYear == $i) { echo "<option value=\"$i\" SELECTED> $i </option>\n"; } else { echo "<option value=\"$i\"> $i </option>\n"; } } echo "</select> \n\n"; ?> </td> <td valign="top"><b>End date:</b><br> <? // get the month echo "<select name=\"DailyStopMonth\">\n"; echo "<option value=\"\"> None </option>\n"; for ($i = 1; $i <= 12; $i++) { if ($i < 10 AND !ereg("^0",$i)) { $i = "0".$i; } $showMonth = date("F",mktime(0,0,0,$i,1,date("Y"))); if ($DailyStopMonth == $i) { echo "<option value=\"$i\" SELECTED> $showMonth </option>\n"; } else { echo "<option value=\"$i\"> $showMonth </option>\n"; } } echo "</select> \n\n"; // get the day echo "<select name=\"DailyStopDay\">\n"; echo "<option value=\"\"> None </option>\n"; for ($i = 1; $i <= 31; $i++) { if ($i < 10 AND !ereg("^0",$i)) { $i = "0".$i; } $showDay = date("dS",mktime(0,0,0,01,$i,$DailyStartYear)); if ($DailyStopDay == $i) { echo "<option value=\"$i\" SELECTED> $showDay </option>\n"; } else { echo "<option value=\"$i\"> $showDay </option>\n"; } } echo "</select> \n\n"; // get the year echo "<select name=\"DailyStopYear\">\n"; echo "<option value=\"\"> None </option>\n"; for ($i = (date("Y") - 1); $i <= (date("Y") + 5); $i++) { if ($DailyStopYear == $i) { echo "<option value=\"$i\" SELECTED> $i </option>\n"; } else { echo "<option value=\"$i\"> $i </option>\n"; } } echo "</select> \n\n"; ?> </td> </tr> </table> </center> <center> <input type="hidden" name="Returned" value="1"> <input type="hidden" name="CalendarDetailsID" value=""> <input type="hidden" name="LocationID" value="<? echo $LocationID; ?>"> <input type="submit" value="Add Event >>"> </form> Regards, Garry Quote Link to comment https://forums.phpfreaks.com/topic/86628-solved-php_self-if-and-html-form/#findComment-442677 Share on other sites More sharing options...
adam291086 Posted January 18, 2008 Share Posted January 18, 2008 Where are you defining your posted data? Quote Link to comment https://forums.phpfreaks.com/topic/86628-solved-php_self-if-and-html-form/#findComment-442680 Share on other sites More sharing options...
zc1 Posted January 18, 2008 Author Share Posted January 18, 2008 Hi, What do you mean ? If you mean where is it being posted to, it is posted to a MySQL database Regards, Garry Quote Link to comment https://forums.phpfreaks.com/topic/86628-solved-php_self-if-and-html-form/#findComment-442685 Share on other sites More sharing options...
adam291086 Posted January 18, 2008 Share Posted January 18, 2008 when you post a form you need to define the information that is being sent For example you are sending the feild from your form called Returned. When you want to call on that information from that feiled you need to do something like $return = $_POST['Returned'] that sets $return to = the information from the feiled Returned in your form Quote Link to comment https://forums.phpfreaks.com/topic/86628-solved-php_self-if-and-html-form/#findComment-442691 Share on other sites More sharing options...
zc1 Posted January 18, 2008 Author Share Posted January 18, 2008 Hi, That did it, thank you I made one for each field of the form $xxxx = $_POST['xxxxx']; and it seems to work Thank you very much Regards, Garry Quote Link to comment https://forums.phpfreaks.com/topic/86628-solved-php_self-if-and-html-form/#findComment-442723 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.