PHP - How To Not Update Form Output Having Two Forms?
I have two (2) forms on the same pages, each with 3 buttons. When a button is clicked, it will include the desired page. Since I have 2 of these forms, clicking one of them will refresh the page thus "delete" the info former retrieved from the other form.
Is there a way to make the page "remember" the last form action? Similar TutorialsCode: [Select] //display an external link or form button if ($product_link = $meta['mp_product_link']) { $button = '<a class="mp_link_buynow" href="' . esc_url($product_link) . '">' . __('Buy Now »', 'mp') . '</a>'; } else { if ($all_out) { $button .= '<span class="mp_no_stock">' . __('Out of Stock', 'mp') . '</span>'; } else { $button = '<div class="mp_product_variations" name="variation">'; //create select list if more than one variation if (is_array($meta["mp_price"]) && count($meta["mp_price"]) > 1 && empty($meta["mp_file"])) { // for each as foreach ($meta["mp_price"] as $key => &$value) { $disabled = (in_array($key, $no_inventory)) ? ' disabled="disabled"' : ''; $variation_select = '<form name="' . $key . '" class="mp_buy_form" method="post" action="' . mp_cart_link(false, true) . '">\n'; $variation_select .= '<input type="hidden" name="product_id" value="' . $post_id . '" />'; $variation_select .= '<input type="hidden" name="variation" value="' . $key . '">'; $variation_select .= '<span>' . esc_html($meta["mp_var_name"][$key]) . ' - '; if ($meta["mp_is_sale"] && $meta["mp_sale_price"][$key]) { $variation_select .= $mp->format_currency('', $meta["mp_sale_price"][$key]); } else { $variation_select .= $mp->format_currency('', $value); }$variation_select .= "</span>\n"; if ($context == 'list') { if ($variation_select) { $variation_select .= '<a class="mp_link_buynow" href="' . get_permalink($post_id) . '">' . __('Choose Option »', 'mp') . '</a>'; } else if ($settings['list_button_type'] == 'addcart') { $variation_select .= '<input type="hidden" name="action" value="mp-update-cart" />'; $variation_select .= '<input class="mp_button_addcart" type="submit" name="addcart" value="' . __('Add To Cart »', 'mp') . '" />'; } else if ($settings['list_button_type'] == 'buynow') { $variation_select .= '<input class="mp_button_buynow" type="submit" name="buynow" value="' . __('Buy Now »', 'mp') . '" />'; } } else { $button .= $variation_select; //add quantity field if not downloadable if ($settings['show_quantity'] && empty($meta["mp_file"])) { $button .= '<span class="mp_quantity"><label>' . __('Quantity:', 'mp') . ' <input class="mp_quantity_field" type="text" size="1" name="quantity" value="1" /></label></span> '; } if ($settings['product_button_type'] == 'addcart') { $button .= '<input type="hidden" name="action" value="mp-update-cart" />'; $button .= '<input class="mp_button_addcart" type="submit" name="addcart" value="' . __('Add To Cart »', 'mp') . '" />'; } else if ($settings['product_button_type'] == 'buynow') { $button .= '<input class="mp_button_buynow" type="submit" name="buynow" value="' . __('Buy Now »', 'mp') . '" />'; } } $variation_select .= "</form>\n"; } //end for each $variation_select .= '</div>'; } else { $button .= '<input type="hidden" name="variation" value="0" />'; } } } Everything inbetween "for each" is being looped, except for the <form>. How can I get it to include <form> and </form> in the loop? I'm working on a chat using basic textarea input, post, but the problem that I'm facing is, if a person doesn't send something, then the output is not updated eg. other messages from other users updating in real time.
How is that achieved when you see new database entries pop up live, milliseconds after they are entered?
Do I set a constant refresh rate of some sort?
How do you update a section of a webpage without "refreshing" the entire page like the POST method?
I am using multiple levels of JSON data coming into php from a C# application, as in:
return new RootObject() { ID_Project = 4, Name_Project = "Test", Receiver_ID = 4, Receiver_Name = "ABCDE", UserID = 20, UserRole = new User_Role() { ID_User = 20, Role_User = "level 3", User_Role_Description = "U", UserGroup = new List<user_group>() { new User_Group() { ID_UserGroup = 30, Name_UserGroup = "usergroup8", UserID = 20 }, new User_Group() { ID_UserGroup = 31, Name_UserGroup = "usergroup9", UserID = 21 }, new User_Group() { ID_UserGroup = 32, Name_UserGroup = "usergroup10", UserID = 22 } } } }; i am having troubles accessing the second level: UserRole and 3rd level: User_Group in my php script. im currently trying like this: foreach ($phpArray as $key => $value) { echo "<h2>$key</h2>"; foreach ($value as $k => $v) { echo "$k | $v "; foreach ($v as $key1) { echo "$key1 "; } } } does anyone have an idea? Thanks, Revathy Hi i have this simple update form and scrip but somehow it doesnt seem to be update the field on the database can someone help out please. The html form is the second form bellow where the action send to status_update.php HTML FORM Code: [Select] <?php include("../header.html"); ?> <?php include("header_news.html"); extract($_REQUEST,EXTR_SKIP); ?><?php /* print("sfilm_refnum = $sfilm_refnum<BR>"); print("sfilm_addr01 = $sfilm_addr01<BR>"); print("sfilm_postcode = $sfilm_postcode<BR>"); print("Film Client = $fclient<BR>"); */ ?> <form id="search" action="list.php" method="post" name="search"> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#eeeeee"> <tr> <td align="right" width="140"></td> <td width="320"><span class="hofblack10"> </span> </td> <td align="center" width="100"><input type="hidden" name="lstart" value="<?php print("$lstart"); ?>" /><input type="hidden" name="lend" value="<?php print("$lend"); ?>" /><input type="hidden" name="lamount" value="<?php print("$lamount"); ?>" /></td> <td align="center" width="100"></td> <td align="right"></td> </tr> </table> </form> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#4050c4"> <tr> <td width="60" class="hofwhite10">action</td> <td width="140"><span class="hofwhite14">DATE</span></td> <td width="80"><span class="hofwhite14">ID</span></td> <td><span class="hofwhite14">News Titile</span></td> <td width="100"><span class="hofwhite14">Status</span></td> </tr> <tr height="0"> <td bgcolor="white" width="60"></td> <td bgcolor="white" width="140" height="0"></td> <td bgcolor="white" width="80" height="0"></td> <td bgcolor="white" height="0"></td> <td bgcolor="white" width="100" height="0"></td> </tr> </table><table width="780" border="0" cellspacing="0" cellpadding="4"><tr> <td width="60"></td> <td width="80"></td> <td><a class="blueullrg" href="add.php">Add News</a></td> <td align="right" width="120"></td> </tr> <tr height="0"> <td width="60" height="0"></td> <td width="80" height="0"></td> <td height="0"></td> <td align="right" width="120" height="0"></td> </tr> </table> <?php //get the DB connection variables include("../../../includes/config.php"); //connect to DB $connection = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select DATABASE."); $query2="SELECT * FROM news WHERE !(news_status='deleted')"; $result2 = mysql_query($query2) or die("Couldn't execute QUERY - Select NEWS Qty"); $fqty = mysql_num_rows($result2); //SELECT or FIND the same USERNAME $query3="SELECT * FROM news WHERE !(news_status='deleted') ORDER BY news_id DESC"; $result3 = mysql_query($query3) or die("Couldn't execute QUERY - Select NEWS"); while ($row = mysql_fetch_array($result3)) { $news_id = $row['news_id']; $news_title = $row['news_title']; $news_story = $row['news_story']; $news_image = $row['news_image']; $news_image_caption = $row['news_image_caption']; $news_image_link = $row['news_image_link']; $news_date_day = $row['news_date_day']; $news_date_month = $row['news_date_month']; $news_date_year = $row['news_date_year']; $news_status = $row['news_status']; $news_website = $row['news_website']; $news_date_created = $row['news_date_created']; $news_date_modified = $row['news_date_modified']; ?> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#eeeeee"> <tr> <td width="60"><span class="hofblack10"> <?php if($news_status=="deleted"){ print("<a class='hifblack10'>deleted</span>"); }ELSE{ print("<a class='blueul' href='edit.php?id=$news_id'>edit</a>"); } ?> </span></td> <td width="140"><span class="titlegrey12"> <?php if(!$news_date_day) { echo "00"; } else{ echo $news_date_day; } echo "/"; if(!$news_date_month) { echo "00"; }else{ echo $news_date_month; } echo "/"; if(!$news_date_year) { echo "0000"; }else{ echo $news_date_year; } ?> </span></td> <td width="80"><span class="titlegrey12"><?php print("$news_id"); ?></span> </td> <td><?php if($news_status=="deleted") { print("<class='hofblack10'>$news_title</span>"); }ELSE{ print("<a class='blueul' href='edit.php?id=$news_id'>$news_title</a>"); } ?></td> <td width="100"> <form id="list_update" action="status_update.php" method="post" name="list_update"> <select name="newnstatus" size="1"> <option <?php if($row['news_status'] == "") { print("selected"); } ?> selected="selected" value="">Status...</option> <option <?php if($row['news_status'] == "on") { print("selected"); } ?> value="on">On</option> <option <?php if($row['news_status'] == "off") { print("selected"); } ?> value="off">Off</option> <option <?php if($row['news_status'] == "deleted") { print("selected"); } ?> value="deleted">Delete</option> </select> <input type="hidden" name="nstatus" value="<?php echo $row[news_status]; ?>" /> <input type="hidden" name="id" value="<?php echo $row[news_id]; ?>" /> <input type="submit" name="update" value="update" /> </form> </td> </tr> <tr height="0"> <td bgcolor="white" width="60"></td> <td bgcolor="white" width="140" height="0"></td> <td bgcolor="white" width="80" height="0"></td> <td bgcolor="white" height="0"></td> <td bgcolor="white" width="100" height="0"></td> </tr> </table> <?php } mysql_close($connection);//}?> <table width="780" border="0" cellspacing="0" cellpadding="4"> <tr> <td width="60"></td> <td width="80"></td> <td><a class="blueullrg" href="add.php">Add News</a></td> <td align="right" width="120"></td> </tr> </table><?php // include("list_navigation.html"); ?> <?php include("../footer.html"); ?> </div></body></html> The action script php Code: [Select] <?php /* echo "fstatus: ".$fstatus."<BR>"; echo "id: ".$id."<BR>"; echo "fclient: ".$fclient."<BR>"; echo "newfstatus: ".$newfstatus."<BR>";*/ //set the date of agreement $timestamp = date('l jS \of F Y h:i:s A'); //get the DB connection variables include("../../../includes/config.php"); //connect to DB $connection = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select FILMS DATABASE."); // All appears well, so enter into database $query= "UPDATE news SET news_status = '$newnstatus' WHERE news_id='$id'"; $result = mysql_query($query) or die("could not execute query - Update FILMS Record to DB"); //setup an email to the Admin @ hof, w/o attachment $emailto="xx@xxx.co.uk"; $emailfrom="no-reply@xxxx.co.uk"; $emailsubject="xx Record Updated"; $emailmessage="Hello Registrar\n\n"; $emailmessage.="News ID: ".$id."\n"; $emailmessage.="Updated on: ".$timestamp."\n\n"; $emailmessage.="Status was: ".$nstatus."\n"; $emailmessage.="Status now: ".$newfnstatus."\n"; $emailmessage.="Thank you,\n\n"; $emailmessage.="Web Site ROBOT\n"; $emailmessage.="(Administrator)\n"; $emailmessage.="xxx.co.uk | xxx.biz\n"; $emailmessage.="----------------------------------------------\n"; $emailmessage.="e. http://www.xxx.co.uk/contact.php\n"; $emailmessage.="w. http://www.xxx.co.uk\n"; $emailheader="From: xxx.co.uk<$emailfrom>"; $emailheader .= 'Cc: xxx@xxx.co.uk'."\r\n"; $emailheader .= 'Bcc: xxx@xxxxx.co.uk'."\r\n"; $ok=mail($emailto,$emailsubject,$emailmessage,$emailheader); mysql_close($connection); if ($ok) { header("Location: list.php"); /* Redirect browser */ exit; } else { $errmsg="There was a problem, please try later or telephone us direct."; $errsta="1"; include("edit_error.html"); //echo "<p>Mail could not be sent. Sorry!</p>"; exit; } ?> Thanks in advance Good morning. I am looking fo some help with an update script to update all rows in a table. This is what I have for a form and all looks well. form.php <?php // run the query and put the results in an array variable called $result $result = mysql_query("SELECT * FROM table ORDER BY 'id', 'title', 'text', 'number'"); print "<form method='post' action='update.php'> <table width='100%' border='0' cellspacing='1' cellpadding='1'><tr> <td align='center'><strong>ID</strong></td> <td align='center'><strong>Title</strong></td> <td align='center'><strong>text</strong></td> <td align='center'><strong>Number</strong></td> </tr>\n"; // start a loop to print all of the courses with their book information // the mysql_fetch_array function puts each record into an array. each time it is called, it moves the array counter up until there are no more records left while ($Update = mysql_fetch_array($result)) { // start displaying the info; the most important part is to make the name an array (notice bookinfo[$i]) print "<td align='center'><p>{$Update['id']}</p></td>\n"; print "<td align='center'><input type='text' name='title' value='{$Update['title']}' /></td>"; print "<td align='center'><input type='text' size='40' name='text' value='{$Update['text']}' /></td>\n"; print "<td align='center'><input type='text' size='40' name='number' value='{$Update['number']}' /></td>\n"; print "</tr>\n"; // add 1 to the count, close the loop, close the form, and the mysql connection } print "<tr> <td colspan='4' align='center'><input type='submit' value='submit' />"; print "</td> </tr> </table> </td> </tr> </form> </table>"; print "</tr>\n"; ?><br /><br /> My question is. How do I update this info into the database with the proper info. ie. Update.php? Which one is better for standards practices in PHP. 1. Using the same form for everything. (Add and edit). Meaning setting up one form to handle adding new records, as well as editing existing records. Or 2. Using two different forms for both actions. Use one form/area to handle Adding, and one form/area to handle editing. Which one of these are better from a standards/practice point of a view. Which one better fits into the MVC platform (a framework like Codeignitor, or Cake). Should their be separate controller functions/views for add and edit or should they all be in the same controller function/form. Thanks for the feedback. I have a form that searches a database then outputs the data via php how do I take the info from the radio button and the age range and search the database with it Code: [Select] <?php $max_age = 18; $ageOptions = "<option value='00'>From</option>\n"; for($age=1; $age<=$max_age; $age++) { $ageOptions .= "<option value='{$age}'>{$age}</option>\n"; } ?> <form name="child_info" action="selectdata.php" method="post" id="child_info"> <table width="444" align="center" > <tr> <td width="208">Choose Male or Female:</td> <td width="224"> <input type="radio" name="gender" value="male" /> Male <input type="radio" name="gender" value="Female" /> Female </td> </tr> <tr> <td>Choose age range:</td> <td> <select name="first_age" id="first_age"> <?php echo $ageOptions; ?> </select> <select name="second_age" id="second_age"> <?php echo $ageOptions; ?> </select> </td> </tr> <tr> <td></td> <td> <div align="right"> <input type="submit" name="submit" id="submit" value="submit" /> <input type="reset" name="reset" id="reset" value="reset" /> </div> </td> </tr> </table> </form> <?php $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("", $con); $query = "SELECT picture_number, first_name, middle_name, first_family_name, second_family_name, DATE_FORMAT(birthdate, '%c-%e-%Y') as birthdate, gender FROM child_info ORDER BY picture_number ASC"; $result = mysql_query($query); if(!$result) { echo "There was a problem getting the data"; } else if(!$result) { echo "There were no results"; } else { echo "<b><center>Children to be sponsored</center></b><br><br>\n"; while($row = mysql_fetch_assoc($result)) { echo "<table border='1'> <tr> <th>Picture Number</th> <th>First Name</th> <th>Middle Name</th> <th>First Family Name</th> <th>Second Family Name</th> <th>Birthdate<br> M-D-Y</th> <th>Gender</th> </tr>"; { echo "<tr>"; echo "<td>" . $row['picture_number'] . "</td>"; echo "<td>" . $row['first_name'] . "</td>"; echo "<td>" . $row['middle_name'] . "</td>"; echo "<td>" . $row['first_family_name'] . "</td>"; echo "<td>" . $row['second_family_name'] . "</td>"; echo "<td>" . $row['birthdate'] . "</td>"; echo "<td>" . $row['gender'] . "</td>"; echo "</tr>"; } echo "</table>"; } } mysql_close(); ?> I have my form outputting the checked boxes using echo "Your Selected Markets = " . $markets ; when it comes out it is displayed as... Your Selected Markets = Aviation and Aerospace Banks Oil and Gas How can I change the output so it for example looks like this. Your Selected Markets = Aviation and Aerospace, Banks & Oil and Gas or Your Selected Markets = Aviation and Aerospace Banks Oil and Gas Hi I am having a problem with my form output. No matter what I search I get "No matching records". Even if I am searching words that I know should return a result. Any help would be much appreciated
<?php define("PERPAGE", 15); // number of records on each page /************************************************************************************** * function to output page selection buttons * * @param int $total total records * @param int $page current page number * @return string selection buttons html */ function page_selector($total, $page) { if ($total==0) { return ''; } $kPages = ceil($total/PERPAGE); $filler = ' · · · '; $lim1 = max(1, $page-2); $lim2 = min($kPages, $page+3); $p = $page==1 ? 1 : $page - 1; $n = $page== $kPages ? $kPages : $page + 1;; $out = "$kPages page" . ($kPages==1 ? '' : 's') . "  "; if ($kPages==1) { return $out; } $out .= ($page > 1) ? "<div class='pagipage' data-pn='$p'>Prev</div> " : ''; if ($page > 4) { $out .= "<div class='pagipage' data-pn='1'>1</div> $filler"; } elseif ($page==4) { $out .= "<div class='pagipage' data-pn='1'>1</div>"; } for ($i=$lim1; $i<=$lim2; $i++) { if ($page==$i) $out .= "<div class='pagicurrent'>$i</div>"; else $out .= "<div class='pagipage' data-pn='$i'>$i</div>"; } if ($page < $kPages-3) { $out .= "$filler <div class='pagipage' data-pn='$kPages'>$kPages</div>"; } $out .= $page < $kPages ? " <div class='pagipage' data-pn='$n'>Next</div>" : ''; return $out; } /*********************************************** ** SEARCH FOR MATCHING TVS ************************************************/ $showResults = 0; $search = ''; if (isset($_GET['tag'])) { $showResults = 1; $search = $_GET['tag']; $srch = array_unique(explode(' ', trim($_GET['tag']))); foreach ($srch as $t) { $repl[] = "<span class='hilite'>$t</span>"; $placeholders[] = '?'; $params[] = $t; } $params[] = count($srch); // // FINDTOTAL RECORDS IN SEARCH RESULTS // $res = $db->prepare("SELECT COUNT(*) as tot FROM television WHERE MATCH(title,description,keywords) AGAINST(? IN BOOLEAN MODE) "); $res->execute($params); $total = $res->fetchColumn(); $page = $_GET['page'] ?? 1; $params[] = ($page-1)*PERPAGE; // append parameters offset $params[] = PERPAGE; // and number of records for limit clause // // GET A PAGEFUL OF RECORDS // $sql = "SELECT id , title , description , keywords FROM television WHERE MATCH(title,description,keywords) AGAINST(? IN BOOLEAN MODE) ORDER BY TITLE LIMIT ?,? "; $stmt = $db->prepare($sql); $stmt->execute($params); if ($stmt->rowCount()==0) { $results = "<h3>No matching records</h3>"; } else { $results = "<tr><th>Product Id</th><th>Title</th><th>Description</th><th>Tags</th><th>Edit</th></tr>\n"; foreach ($stmt as $rec) { $alltags = str_replace($srch, $repl, $rec['keywords']); $results .= "<tr><td>{$rec['id']}</td><td>{$rec['title']}</td><td>{$rec['description']}</td><td>$alltags</td> <td><a href='?action=edit&id={$rec['id']}'><img src='edit-icon.png' alt='edit'></a></td> </tr>\n"; } } } ?> <div id='title'>Television Search</div> <form id='form1'> <fieldset> <legend>Search for tags</legend> <input type='text' name='tag' size='50' value='<?=$search?>' placeholder='Search for...' > <input type="hidden" name="page" id="page" value="1"> <input type="hidden" name="action" id="page" value="search"> <input type="submit" name="btnSub" value="Search"> </fieldset> <div id='formfoot'></div> </form> <?php if ($showResults) { ?> <div class="paginate_panel"> <?=page_selector($total, $page)?> </div> <table border='1'> <?=$results?> </table> <?php } ?>
I am working on a form that takes in 5 numbers as INPUT (the number range is from 1 to 10). Then, the OUTPUT will display the 5 numbers entered with their associated color. I am having problems getting the color value to show on the browser. Can someone please help as to what I am doing wrong? Below is the code I have so far. <?php
error_reporting(0);
{ $color1 = $position1;
if ($position1 == "2,4,6,8,10") $color2 = $position2;
if ($position2 == "2,4,6,8,10") $color3 = $position3;
if ($position3 == "2,4,6,8,10") $color4 = $position4;
if ($position4 == "2,4,6,8,10") $color5 = $position5;
if ($position5 == "2,4,6,8,10") }
?>
<!-- START :: Input Form -->
</body> ----- EOF ----
Hey Guys, I've got a section of code that generates a date and time. This is currently standalone however I'm looking to integrate it with a standard page. This is the code page: <?php error_reporting(0); include("options.php"); include("include/functions.php"); include("include/class.php"); list($year,$month,$day) = explode("-",date("Y-n-j",strtotime($_REQUEST["date"]))); $bookFrom = formatDateByCalendarId($day,$month,$year,$_REQUEST["cid"]); $sql = "SELECT * FROM ".$TABLES["Calendars"]." WHERE id=".$_REQUEST["cid"]; $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql); $Calendar = mysql_fetch_assoc($sql_result); $CalendarOptions = unserialize($Calendar["options"]); $fontFamily = $Fonts[$CalendarOptions["fonts"]]; $daysFontSize = $FontSize[$CalendarOptions["daysFontSize"]]; $daysFontStyle = $Styles[$CalendarOptions["daysFontStyle"]]; $availableDaysFontSize = $FontSize[$CalendarOptions["availableDaysFontSize"]]; $availableDaysFontStyle = $Styles[$CalendarOptions["availableDaysFontStyle"]]; $timeSlot=new Timeslot($_REQUEST["cid"]); $reservations=$timeSlot->getFreeFilter($CalendarOptions["startTime"],$CalendarOptions["endTime"],$year,$month,$day,$CalendarOptions["timeSlot"]); if (!isset($_REQUEST["view"])) { $view = '1'; } else { $view = $_REQUEST["view"]; }; if ($_REQUEST["ac"]=='book') { $message =''; $format = GetCalendarDateFormat($_REQUEST["cid"]); $sYear = GetYear($format,$_REQUEST["startDate"]); $sMonth = GetMonth($format,$_REQUEST["startDate"]); $sDay = GetDay($format,$_REQUEST["startDate"]); $reservations=$timeSlot->getFreeFilter($CalendarOptions["startTime"],$CalendarOptions["endTime"],$sYear,$sMonth,$sDay,$CalendarOptions["timeSlot"]); $sDateLong = strtotime($CalendarOptions["startTime"],mktime(0,0,0,$sMonth,$sDay,$sYear)); $first=-1; $last=-1; for ($i=0;$i<count($reservations);$i++) { if (($_REQUEST[$i]=="on")&&((($reservations[$i]>0)&&($reservations[$i]==$_REQUEST["rid"]))||(!$reservations[$i]))) { if ($first<0) $first=$i; $last=$i; } } $eDateLong = strtotime("+".($CalendarOptions["timeSlot"]*($last+1))." minutes",$sDateLong); $sDateLong= strtotime("+".($CalendarOptions["timeSlot"]*$first)." minutes",$sDateLong); if($_REQUEST["rid"]>0) { $updateRange = $_REQUEST["rid"]; } else $updateRange = NULL; if(! $timeSlot->checkInterval($sDateLong,$eDateLong,$updateRange)){ $message = "Some of the timeslots on the selected date are already booked."; } else { $settings["status"]=$CalendarOptions["reservationStatus"]; $settings["notes"]=mysql_escape_string(utf8_encode($_REQUEST["notes"])); $settings["customerName"]=mysql_escape_string(utf8_encode($_REQUEST["customerName"])); $settings["phone"]=mysql_escape_string(utf8_encode($_REQUEST["phone"])); $settings["email"]=mysql_escape_string(utf8_encode($_REQUEST["email"])); $settings["price"]=$_REQUEST["price"]; if (! isset($updateRange)) $settings["dt"]=date("Y-m-d H:i:s"); if (! $timeSlot->addReservation($sDateLong,$eDateLong,$settings,$updateRange)) $message = 'Failed saving'; else { if($_REQUEST["findReservation"]=="1") $_REQUEST["ac"]='findReservation'; else $_REQUEST["ac"]='view'; $_REQUEST["month"] = $sMonth*1; $_REQUEST["year"] = $sYear; $search_tokens=array("<Name>","<Email>","<Phone>","<Notes>","<Date>","<StartTime>","<EndTime>","<Price>"); $replace_tokens=array($_REQUEST["customerName"],$_REQUEST["email"],$_REQUEST["phone"],stripslashes($_REQUEST["notes"]),$_REQUEST["startDate"],formatTime($sDateLong,$_REQUEST["cid"]),formatTime($eDateLong,$_REQUEST["cid"]),$_REQUEST["price"]); $MESSAGE_BODY=$CalendarOptions["emailMessage"]; $MESSAGE_BODY=nl2br(str_replace($search_tokens,$replace_tokens,$MESSAGE_BODY)); $mailheader = "From: ".$CalendarOptions["NotificationEmail"]."\r\n"; $mailheader .= "Reply-To: ".$CalendarOptions["NotificationEmail"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; if ($CalendarOptions["NotificationEmail"]<>'') { if(!mail($CalendarOptions["NotificationEmail"], 'Reservation Confirmation', $MESSAGE_BODY, $mailheader)) $message="Failure sending e-mails.<br />"; }; if ($_REQUEST["email"]<>'') { if (!mail($_REQUEST["email"], 'Reservation Confirmation', $MESSAGE_BODY, $mailheader)) $message="Failure sending e-mails.<br />"; }; if($CalendarOptions["allowPaypal"]=="true" and $CalendarOptions["paypalAddress"]<>"" and $CalendarOptions["depositPayment"]>0 and isset($_REQUEST["price"]) and $_REQUEST["price"]>0){ $price = $_REQUEST["price"]; $deposit = $price * ($CalendarOptions["depositPayment"] / 100); $_REQUEST["ac"] = "redirectToPaypal"; } else { unset($_REQUEST["ac"]); } $message.='Reservation saved.'; } } } echo '<div style="font-family:'.$fontFamily.'; color:#'.$CalendarOptions["availableDaysFontColor"].'; font-size:'.$availableDaysFontSize.'px; font-weight:bold">'.$message.'</div>'; if($_REQUEST["ac"]=="redirectToPaypal"){ } else { ?> <?php if(isset($_REQUEST["date"])){ ?> <form action="load-bookingform.php" method="post" name="frm" style="margin:0px; padding:0px" onsubmit="return false"> <table width="<?php echo $CalendarOptions["width"]; ?>" border="0" cellspacing="0" cellpadding="2" style='font-family:"<?php echo $fontFamily; ?>"; color:#<?php echo $CalendarOptions["availableDaysFontColor"]; ?>; font-size:<?php echo $availableDaysFontSize; ?>px; <?php echo $availableDaysFontStyle; ?>'> <tr> <td width="16%" align="left">Date:</td> <td width="85%" align="left" name="startDate" id="startDate"><strong><?php echo $bookFrom; ?></strong></td> </tr> <?php $price = 0; ?> <tr> <td colspan="2"> <table width="100%" border="0" cellspacing="2" cellpadding="2"> <tr> <td width="33%" valign="top" bgcolor="#DDDDDD">Start time</td> <td width="33%" valign="top" bgcolor="#DDDDDD">End time</td> <td colspan="2" valign="top" bgcolor="#DDDDDD">Book </td> </tr> <?php for ($i=0;$i<count($reservations);$i++) { ?> <tr> <td align="left" style="border-bottom:1px solid #DFE4E8"><?php if ($CalendarOptions["timeFormat"]=='12') echo date("h:i A",strtotime("+".($CalendarOptions["timeSlot"]*$i)." minutes",strtotime($CalendarOptions["startTime"]))); else echo date("H:i",strtotime("+".($CalendarOptions["timeSlot"]*$i)." minutes",strtotime($CalendarOptions["startTime"]))); ?></td> <td align="left" style="border-bottom:1px solid #DFE4E8"><?php if ($CalendarOptions["timeFormat"]=='12') echo date("h:i A",strtotime("+".($CalendarOptions["timeSlot"]*($i+1))." minutes",strtotime($CalendarOptions["startTime"]))); else echo date("H:i",strtotime("+".($CalendarOptions["timeSlot"]*($i+1))." minutes",strtotime($CalendarOptions["startTime"]))); ?></td> <td width="34%" align="left" valign="top" style="border-bottom:1px solid #DFE4E8"><input type="checkbox" id="<?php echo $i; ?>" name="<?php echo $i; ?>" <?php if ($reservations[$i]) { echo "checked"; echo ' disabled="disabled"'; } ?> onclick="selectTimeSlot()" /></td> </tr> <?php }; ?> </table> </td> </tr> <tr> <td align="left"> </td> <td align="left"> <input type="button" name="Button" value="Book" onclick="pass=checkForm(); if (pass) submitBooking('<?php echo $bookFrom; ?>','<?php echo date("n",strtotime($_REQUEST["date"])); ?>','<?php echo date("Y",strtotime($_REQUEST["date"])); ?>')" /> <input type="button" name="Button" value="Cancel" onclick="javascript: ajaxpage('<?php echo $SETTINGS["installFolder"]; ?>load-bookingform.php?cid=<?php echo $_REQUEST["cid"]; ?>','DateBookings<?php echo $_REQUEST["cid"]; ?>','get'); " /> </td> </tr> <?php } ?> </table> </form> <?php }; ?> I already have a checkout page, that this info needs to be parsed to. Any ideas how I can integrate it? Hello all! First, I'm a complete noob when it comes to php coding so bare with me on this. I know this might seem like a super simple thing to do, but as I said I'm a beginner at best. What I have is a very simple contact form with three fields: name, email, and comments. The way I have it set up is that when someone fills out the form and hits the submit button, it sends me an email via Gmail with the values of the form. Pretty basic stuff. The thing is, when I get the values in the email, it's all on one line and rather unflattering looking. It works for just me, I don't care really. But I'd like to turn around and use this form/php code I have for a client. The form for them is going to have a lot more input fields and I can only imagine the string of text that it's going to create. What I would like to do is format the values that I or they receive via email so that it's a bit more presentable. I have no idea how to do this. Here's my php code connected to my form: Code: [Select] <?php include_once("phpmailer/class.phpmailer.php"); $name = $_POST['name']; $email = $_POST['email']; $comments = $_POST['comments']; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->Host = "smtp.gmail.com"; $mail->SMTPSecure = "ssl"; $mail->Port = 465; $mail->Username = "myemail@gmail.com"; $mail->Password = "xxxxxx"; $mail->AddAddress("mymail@gmail.com"); $mail->From = "mymail@gmail.com"; $mail->FromName = $_POST['name']; $mail->Subject = "User Comment"; $mail->IsHTML(true); $mail->Body = "Name: $name\n Email: $email\n Comments: $comments"; if($mail->Send()) { echo "Message sent! Thanks for your comments!"; } ?> so right now with that I get an email for example that looks like this: Name: Bob Email: blank@blank.com Comments: I like soda! where I would rather have something like: Name: Bob Email: blank@blank.com Comments: I like soda! Any advice would very much appreciated! I have a form where people enter in values and I need these values displayed in the proper format. I need the output string to have a "<" at the beginning and a ">" at the end but whenever I put the code in to add the < in the beginning nothing shows up. Here is my code. I am able to get it to work with just adding the > at the end but it seems when I add "<" to the beginning this is where nothing shows up. Code: [Select] <?php $hairbald = trim($_POST['HairBald']); $eyes = trim($_POST['Eyes']); $test =$eyes.'.'.$hairbald; if(empty($test)) { $test = $test; } else $test = '<'.$test.'>'; ?> If the user selects blue eyes and bald head I need the output to be <blue.bald> Hi guys, I'm having a bit of PHP problems trying to combine two bits of code which is definitely possible as it's simple if statements, but I'm a bit confused. Not sure if you guys are familiar, but there's a PHP Form Builder Class part of the Google Code Hosting Project. There's two forms I'm playing with one 'Google Spreadsheets' form which allows the data submitted via a form to be entered in a Google Spreadsheet, and one which sends the data to an email address. http://www.imavex.com/php-form-builder-class/examples/email.php http://www.imavex.com/php-form-builder-class/examples/google-spreadsheets.php I have these working separately, but ideally want I need is to be able to combine them both, per se, and allow the data submitted to go to both the spreadsheet and the email address defined. The code for the email is: Code: [Select] <?php error_reporting(E_ALL); session_start(); include("../class.form.php"); if(isset($_POST["cmd"]) && in_array($_POST["cmd"], array("submit_0"))) { $form = new form("email_" . substr($_POST["cmd"], -1)); if($form->validate()) { $result = $form->email("my_username", "my_password", array( "to" => "my_recipient(s)", "subject" => "my_subject", "from" => "my_from", "replyto" => "replyto", "cc" => "my_cc", "bcc" => "my_bcc", "preHTML" => "my_prehtml", "postHTML" => "my_posthtml", "css" => '<style type="text/css">...</style>', "cssFile" => "my_css.css or http://www.my_domain.com/my_css.css", "textonly" => "true/false" )); if($result) header("Location: email.php?errormsg_" . substr($_POST["cmd"], -1) . "=" . urlencode("Congratulations! The information you enter has been emailed from your Google Gmail account.")); else header("Location: email.php?errormsg_" . substr($_POST["cmd"], -1) . "=" . urlencode("Oops! The following error has occurred while sending information from your Google Gmail account. " . $form->getEmailError())); } else header("Location: email.php"); exit(); } elseif(!isset($_GET["cmd"]) && !isset($_POST["cmd"])) { $title = "Email w/PHPMailer + Google's Gmail Service"; include("../header.php"); ?> <p><b>Email w/Google's Gmail Service</b> - This project's email function provides the ability to email a form's submitted data using PHPMailer and Google's Gmail service. This function has four parameters as seen below.</p> <ul style="margin: 0;"> <li>Google Account Email Address - Email address (including domain) of your Google Gmail account.</li> <li>Google Account Password - Password of your Google Gmail account.</li> <li>Additional Parameters (optional) - This parameter allows you to set various email settings through an associative array of key/value pairs. Available settings are provided below. <ul style="margin: 0;"> <li>to - Sets the email's to address. If blank, this parameter will be set to the Google Gmail account email address used in the first parameter.</li> <li>subject - Sets the email's subject.</li> <li>from - Sets the email's from address. If blank, this parameter will be set to the Google Gmail account email address used in the first parameter.</li> <li>replyto - Sets the email's reply to address. If empty, the from address will be used.</li> <li>cc - Sets the email's CC address.</li> <li>bcc - Sets the email's BCC address.</li> <li>preHTML - Allows you to prepend html content above the form's submitted data.</li> <li>postHTML - Allows you to append html content below the form's submitted data.</li> <li>textonly - Sends text-only version of the form's submitted data. By default, the email function will send an email containing both an html and text version.</li> <li>css - Gives you the ability to style the html email as needed. This parameter should be passed as a string beginning with <style type="text/css"> and ending with </style></li> <li>cssFile - Gives you the ability to style the html email as needed by specifying a css include file.</li> </ul> </li> </ul> <p>Before getting started, you'll want to review the checklist of information provided below to ensure you have a good understanding on how this functionality works.</p> <ol style="margin: 0;"> <li>You'll need a Google Gmail account. If you don't have one, you can create one by clicking the "Create an account" link at <a href="http://mail.google.com">http://mail.google.com</a>.</li> <li>to, replyto, cc, and bcc can contain multiple email addresses - just separate them with commas.</li> <li>to, from, replyto, cc, bcc can contain email addresses formatted as either "my@email.com" or "My Email <my@email.com>"</li> <li>Within the email function, a call is made to another public function - getEmail - to get the email's html/text content. If you already have an existing system in place for sending email, you can use this function instead of the project's email function to build a string containing an html/text representation of the form's submitted data. By default, this function will return html, but you can pass true as the first and only parameter to return text.</li> </ol> <p>In the php source code of this example file, you'll see that the email function call currently contains demo authentication/email settings ("my_email", "my_password", etc). You'll want to replace these with your information. Another important thing to note is that the various email settings that can be applied through the email function's fourth parameter are optional. In the php source code of this example file, you'll find all of them listed for reference in the email function call. Feel free to include as many or few as needed.</p> <?php $form = new form("email_0"); $form->setAttributes(array( "map" => array(2, 2, 1, 3), "width" => 500 )); if(!empty($_GET["errormsg_0"])) $form->errorMsg = filter_var(stripslashes($_GET["errormsg_0"]), FILTER_SANITIZE_SPECIAL_CHARS); $form->addHidden("cmd", "submit_0"); $form->addTextbox("First Name:", "FName"); $form->addTextbox("Last Name:", "LName"); $form->addEmail("Email Address:", "Email"); $form->addTextbox("Phone Number:", "Phone"); $form->addTextbox("Address:", "Address"); $form->addTextbox("City:", "City"); $form->addState("State:", "State"); $form->addTextbox("Zip Code:", "Zip"); $form->addButton(); $form->render(); include("../footer.php"); } ?> And for the spreadsheet: Code: [Select] <?php error_reporting(E_ALL); session_start(); include("../class.form.php"); if(isset($_POST["cmd"]) && in_array($_POST["cmd"], array("submit_0"))) { $form = new form("googlespreadsheets_" . substr($_POST["cmd"], -1)); if($form->validate()) { if($form->sendToGoogleSpreadsheet("my_email", "my_password", "my_spreadsheet_title", "(optional) my_worksheet_title")) header("Location: google-spreadsheets.php?errormsg_" . substr($_POST["cmd"], -1) . "=" . urlencode("Congratulations! The information you enter has been sent your Google Docs spreadsheet.")); else header("Location: google-spreadsheets.php?errormsg_" . substr($_POST["cmd"], -1) . "=" . urlencode("Oops! The following error has occurred while sending information to your Google Docs spreadsheet. " . $form->getGoogleSpreadsheetError())); } else header("Location: google-spreadsheets.php"); exit(); } elseif(!isset($_GET["cmd"]) && !isset($_POST["cmd"])) { $title = "Google Spreadsheets"; include("../header.php"); ?> <p><b>Google Spreadsheets</b> - This project's sendToGoogleSpreadsheet function provides the ability to send a form's submitted data direclty to a Google Docs spreadsheet using the Google Spreadsheet API. This function has four parameters as seen below.</p> <ul style="margin: 0;"> <li>Google Account Email Address - Email address (including domain) of your Google account.</li> <li>Google Account Password - Password of your Google account.</li> <li>Google Docs Spreadsheet - The title of the spreadsheet where you'd like the form's submitted data to be sent.</li> <li>Worksheet (optional) - The title of the worksheet to be used within the specified spreadsheet. This parameter will default to the the spreadsheet's first worksheet.</li> </ul> <p>Before getting started, you'll want to review the checklist of information provided below to ensure you have a good understanding on how this functionality works.</p> <ol style="margin: 0;"> <li>You'll need a Google account. If you don't have one, you can create one by clicking the "Create an account now" link at <a href="http://docs.google.com">http://docs.google.com</a>.</li> <li>If the spreadsheet title you specify in the sendToGoogleSpreadsheet function does not exist, a new spreadsheet will be created for you with the appropriate title and column headers.</li> <li>If you're creating your spreadsheet manually through the Google Docs GUI, an important thing to keep in mind is that Google will treat the initial row of cells as column identifiers. These column identifiers must match an element's label used in your form ("First Name:", "Last Name:", etc), which enables the form's submitted data to be correctly placed within the appropriate column. If the spreadsheet you specify in the sendToGoogleSpreadsheet function exists but has no inital row of column headers, your form's data will not populated upon submission. Your spreadsheet does not need to contain a column for every element used in the form - data for those elements that are not included will just not be collected. Likewise, your spreadsheet can contain column identifiers that don't match an element's label used in the form - data for those columns will be left blank.</li> <li>Elements of type hidden, captcha, button, html, and htmlexternal will not be included in the information that is sent to your Google spreadsheet.</li> <li>The "ignoreGSSend" element attribute can be applied to form elements that you do not want to be send to your Google Docs spreadsheet. The hidden field "cmd" has this attribute set in the form below.</li> <li>If you're populating an existing spreadsheet in your Google Docs account, you can store the web server's date/time at the moment the form's data is submitted by adding "Timestamp" as a column header.</li> </ol> <p>In the php source code of this example file, you'll see that the sendToGoogleSpreadsheet function call currently contains demo authentication/spreadshet settings ("my_email", "my_password", etc). You'll want to replace these with your information.</p> <?php $form = new form("googlespreadsheets_0"); $form->setAttributes(array( "map" => array(2, 2, 1, 3), "width" => 500 )); if(!empty($_GET["errormsg_0"])) $form->errorMsg = filter_var(stripslashes($_GET["errormsg_0"]), FILTER_SANITIZE_SPECIAL_CHARS); $form->addHidden("cmd", "submit_0"); $form->addTextbox("First Name:", "FName"); $form->addTextbox("Last Name:", "LName"); $form->addEmail("Email Address:", "Email"); $form->addTextbox("Phone Number:", "Phone"); $form->addTextbox("Address:", "Address"); $form->addTextbox("City:", "City"); $form->addState("State:", "State"); $form->addTextbox("Zip Code:", "Zip"); $form->addButton(); $form->render(); include("../footer.php"); } ?> I have managed to speak to one of the admins, who can't help me further, but states: 'My recommendation would be to use both the $form->email() and $form->sendToGoogleSpreadsheet() methods after your form has been submitted. It's not a "one or the other" type of scenario.' Could you help me out and show me how this would be possible which in turn I can learn from? Thanks, and sorry for the long post but felt it was better as a code include rather than an attachment? Richard I am trying to work on a code for php where you first have a form that asks the user to input a message then input a color. When they click the submit button it takes them to the output page. It should take their message and output it into boxes in a square. And the background should turn the color that they types in. Hi,
I need to create a landing page with a form. That form needs to be recorded somewhere instead of sent to email. I know I can write it to a SQL database, and then to an excel file. But I only need a temporary solution so I figured I'd just go straight to CSV.
Is this bad practice? What potential problems might I encounter other than security issues?
My code is supposed to update the table but it just wipes all the fields clean if (isset($_POST['Update'])){ // here we encrypt the password and add slashes if needed if (isset($_POST['add'])) { $_POST['element_1'] = addslashes($_POST['element_1']); $_POST['element_7_1'] = addslashes($_POST['element_7_1']); $_POST['element_7_2'] = addslashes($_POST['element_7_2']); $_POST['element_2'] = addslashes($_POST['element_2']); $_POST['element_3'] = addslashes($_POST['element_3']); $_POST['element_4'] = addslashes($_POST['element_4']); $_POST['element_5'] = addslashes($_POST['element_5']); $_POST['element_13'] = addslashes($_POST['element_13']); $_POST['element_11'] = addslashes($_POST['element_11']); $_POST['element_6'] = addslashes($_POST['element_6']); $_POST['element_12'] = addslashes($_POST['element_12']); $_POST['element_8'] = addslashes($_POST['element_8']); //------------------// $e1 = $_POST['element_1']; $e71 = $_POST['element_7_1']; $e72 = $_POST['element_7_2']; $e2 = $_POST['element_2']; $e3 = $_POST['element_3']; $e4 = $_POST['element_4']; $e5 = $_POST['element_5']; $e13 = $_POST['element_13']; $e11 = $_POST['element_11']; $e6 = $_POST['element_6']; $e12 = $_POST['element_12']; $e8 = $_POST['element_8']; } mysql_real_escape_string($update = "UPDATE `YBK_Ads` SET `BSN` = '{$e1}', `CNF` = '{$e71}', `CNL` = '{$e72}', `ADD` = '{$e2}', `CITY` = '{$e3}', `STATE` = '{$e4}', `ZIP` = '{$e5}', `AS` = '{$e13}', `PT` = '{$e11}', `CN` = '{$e6}', `BY` = '{$e12}', `ACI` = '{$e8}' WHERE `ID` = '{$_POST['id']}'"); mysql_query($update) or die( 'Query string: ' . $update . '<br />Produced an error: ' . mysql_error() . '<br />' ); //header("Location: http://ybk.watsonn.com/list.php"); } I am creating a user inbox system. I am retrieving all the unread messages. Each message row contains a "reply" form. So say I have 10 messages showing on a single page. That's 10 forms. What I would like to know is how can I submit any one of the 10 forms and not have it affect the remaining 9 forms? Here is the basic code. if(isset($_POST['submit'])) { $post_message = trim($_POST['message']); $errors = array(); $db->beginTransaction(); if(empty($post_message)) { $errors[] = 'The message field can not be empty!'; } if(empty($errors)) { $db->commit(); echo 'success'; } else { $db->rollBack(); } } <form action="" method="post"> <fieldset> <textarea name="message" maxlength="10000" placeholder="What would you like to say?"></textarea> </fieldset> <fieldset> <input type="submit" name="submit" value="Submit" /> </fieldset> </form>
|