PHP - How To Use $_post With The Post Name Being A Variable?
Code: [Select]
$amountBoxName = "amount".$id; // Constructs the name of the input field $amountToPay = strip_tags($_POST["$amountBoxName"]); $amountBoxName then goes to 'amount22' says, however $amountToPay is then showing also as 'amount22', not getting the value of the text field whose name/id is amount22 on the previous page. How do I do this? I tried having " around the $amountBoxName, ' and no quotes although still can't get it working. Similar TutorialsI have a form that creates rows of data input textboxes depending on a user input number of things. I have a naming convention for all these textboxes that basically just keeps incrementing a number suffix for each row. All this is working fine. My problem is I need to get the data inserted into this table of textboxes into an array. Here's my code where I attempt to to this (it does not work): Code: [Select] $temp = $_SESSION['Num_Part']; $count = 1; while ($count <= $temp){ $temp2[$count] = "'Participant_P".$count."'"; //echo $temp2[$count]."<br/>"; $temp3[$count]=$_POST[$temp2[$count]]; //here's the problem $temp4[$count] = "'Result_P".$count."'"; $temp5[$count]=$_POST[$temp4[$count]]; //here's the problem //echo $temp4[$count]."<br/>"; $count++; } The problem is that the $_POST does not work with the variable in the argument position - even though the argument is formatted with single quotes. Can a variable be used in a POST argument and if so what is the correct syntax? If not, is there some other simple solution to harvest the data into an array. I understand I can harvest by explicitly accessing each key in the post assoc array. But this could be dozens of rows of input fields. Thanks in advance for your help here. I couldn't find anything online re this topic. Hi, I need to pass value of variable to another php file. I thought it is possible to do it as following: <form action="products.php"> <INPUT TYPE=hidden NAME='id' . VALUE='$id'> </form> But the problem is like that. The php file inside which I want to write above html code has not using <form> tag and it has no buttons. So how to initiate the transfer of variable into another php file? Is the above idea is not the good idea? Are there any another ways? Why doesn't this code work... Code: [Select] // Initialize variables. $form_value = ''; $form_value = $_POST['form_value']; I get this error... Quote Notice: Undefined index: form_value Thanks, Debbie what would be the $_POST variable name for a radio button option? Hi Everyone, I'm trying to make an userlist where I have a button (or better a picture with a hyperlink) which if I click it I will be forwarded to a new page where the user name is send as a $_Post variable. The code below is what I have this far. In some way when I click the send button it always gives the last username in the table in the $_Post variable. Can anyone help me please. Thnx Ryflex <?php require_once('auth.php'); require_once('config.php'); $global_dbh = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die("Could not connect to database"); mysql_select_db(DB_DATABASE, $global_dbh) or die("Could not select database"); $user_query = "SELECT * FROM members"; $user_result = mysql_query($user_query); ?> <form ID="gotoresource" NAME="gotoresource" METHOD="POST" ACTION="resource_compose.php"> <table width="500" border="1" align="center" cellpadding="2" cellspacing="0"> <tr> <td><b>User</b></td> <td><b>Resource</b></td> </tr> <?php while($row = mysql_fetch_assoc($user_result)) { echo "<tr>"; echo "<td>"; echo $row['login']; $user = $row['login']; ?> <input name="User" type="hidden" maxlength="15" id="user" value="<?php echo $user; ?>"/> </td> <td> <input type="submit" name="Submit" value="Send" /> </td> <?php echo "</tr>"; } ?> <html> <head> <title>Userlist</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> </body> </html> User clicks on a url, ie: example.com/AEQ438J When I perform this in the code below: Code: [Select] $referrer = $_GET['_url']; // echo $referrer displays the referrer ID contents correctly as "AEQ438J" if ( ! empty($referrer)) { $mysqli->query("UPDATE coming_soon_emails SET clicks = clicks + 1 WHERE code='" . $referrer ."'"); } // this also updates the database correctly as it should if (!empty($_POST['email'])){ // echo $referrer displays the referrer ID contents as BLANK. It should display "AEQ438J"! ..... $referrer displays correctly BEFORE if($_POST['form']), however during the if($_POST['form']) $referrer is empty. How can I fix my code so that $referrer is not empty during the time the user posts their email address in the form? Thank you! Complete PHP and HTML Code: [Select] <?php require "includes/connect.php"; //var_dump($_GET);die; function gen_code($codeLen = 7) { $code = ''; for ($i=0; $i<$codeLen; $i++) { $d=rand(1,30)%2; $code .= $d ? chr(rand(65,90)) : chr(rand(48,57)); } return $code; } function add_code($email_id) { global $mysqli; $code = gen_code(7); $mysqli->query("UPDATE coming_soon_emails SET code='" . $code ."' WHERE email_id='" . $email_id . "'"); if($mysqli->affected_rows != 1) { add_code($email_id); } else return $code; } $msg = ''; $referrer = $_GET['_url']; // echo $referrer displays the referrer ID contents correctly if ( ! empty($referrer)) { $mysqli->query("UPDATE coming_soon_emails SET clicks = clicks + 1 WHERE code='" . $referrer ."'"); } if (!empty($_POST['email'])){ // echo $referrer displays the referrer ID contents as BLANK // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $mysqli->query("INSERT INTO coming_soon_emails SET email='".$mysqli->real_escape_string($_POST['email'])."'"); if($mysqli->affected_rows != 1){ throw new Exception('This email already exists in the database.'); } else { $email_code = add_code($mysqli->insert_id); } $msg = "http://www.example.com/" . $email_code; //the following doesn't work as referrer is now empty :( if ( ! empty($referrer)) { $mysqli->query("UPDATE coming_soon_emails SET signup = signup + 1 WHERE code='" . $referrer ."'"); } if($ajax){ die(json_encode(array('msg' => $msg))); } } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" type="text/css" href="css/styles.css" /> </head> <body> <div id="launch"> <form id="form" method="post" action=""> <input type="text" id="email" name="email" value="<?php echo $msg;?>" /> <input type="submit" value="Submit" id="submitButton" /> </form> <div id="invite"> <p style="margin-top:20px;">The ID of who referred you: <?php echo $referrer; //this displays correctly?>)</p> <p style="margin-top:20px;"><span id="code" style="font-weight:bold;"> </span></p> </div> </div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script src="js/script.js"></script> </body> </html> script.js Code: [Select] $(document).ready(function(){ // Binding event listeners for the form on document ready $('#email').defaultText('Your Email Address'); // 'working' prevents multiple submissions var working = false; $('#form').submit(function(){ if(working){ return false; } working = true; $.post("./index.php",{email:$('#email').val()},function(r){ if(r.error){ $('#email').val(r.error); } else { $('#email').val(r.msg); // not needed but gets hidden anyways... $('#launch form').hide(); $("#code").html(r.msg); $("#invite").fadeIn('slow'); } working = false; },'json'); return false; }); }); // A custom jQuery method for placeholder text: $.fn.defaultText = function(value){ var element = this.eq(0); element.data('defaultText',value); element.focus(function(){ if(element.val() == value){ element.val('').removeClass('defaultText'); } }).blur(function(){ if(element.val() == '' || element.val() == value){ element.addClass('defaultText').val(value); } }); return element.blur(); } htaccess Code: [Select] RewriteEngine on RewriteCond %{HTTP_HOST} ^my-url.com RewriteRule (.*) http://www.my-url.com/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z0-9]+)$ /index.php?_url=$1 [NC,L,QSA] table.sql Code: [Select] CREATE TABLE IF NOT EXISTS `coming_soon_emails` ( `email_id` int(11) NOT NULL auto_increment, `email` varchar(64) collate utf8_unicode_ci NOT NULL, `code` char(7) collate utf8_unicode_ci DEFAULT NULL, `clicks` int(64) collate utf8_unicode_ci DEFAULT 0, `signup` int(64) collate utf8_unicode_ci DEFAULT 0, `ts` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`email_id`), UNIQUE KEY `email` (`email`), UNIQUE KEY `code` (`code`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; Hi guys, I pretty new to php, and was writing a small script after a I read a chapter (4) about if-statements of a book. But it seems I am doing something wrong. Maybe someone could help me in the right direction. In a nutshell: I have a small form, and when someone presses submit it should go to another page and include the variables of the previous page. So far I am only been able to include html form variables which I recover on the next page with $_POST['xxxx']; here under ill Put a part of my script which is not of any use, but its more for me to understand how to get php variables on the next page. I am using a self referencing script and i have some comments added to read along. Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>bla bla bla</title> </head> <body> <?php //code to be executed when monkey button pressed if (isset($_POST['monkey'])){ echo $_POST[$number1]; echo 'monkey pressed'; } //code to be executed when snakes button pressed if (isset($_POST['snakes'])){ echo $_POST[$number1]; echo 'snakes pressed'; } ?> <h1>bla bla bla</h1> <h3> <?php $number1 = $number1.mt_rand(1,100000); echo $number1; ?> </h3> <form action="<?php echo $_PHP['PHP_SELF']; ?>" method="post"> <input type="submit" value="monkey" name="monkey" /> <input type="submit" value="snakes" name="snakes" /> </form> </body> </html> Why isn't this working? function friendFunction(){ v=$("Donald"); $.post('./action/friendaction.php',{ user:v.val()},function(d){ alert(d) }); }It works if I change it to user:"bob" though. What is the most effect approach to doing this? Code: [Select] <?php $catid = $_POST['catid']; if($catid = "Automotive"){ $catid = '3'; } if($catid = "Business"){ $catid = '4'; } if($catid = "Careers"){ $catid = '5'; } if($catid = "Education"){ $catid = '6'; } if($catid = "Financial"){ $catid = '7'; } if($catid = "Government"){ $catid = '8'; } if($catid = "Health"){ $catid = '9'; } if($catid = "Mobile"){ $catid = '10'; } if($catid = "Organization"){ $catid = '11'; } if($catid = "Programming"){ $catid = '12'; } if($catid = "Software"){ $catid = '13'; } if($catid = "Travel"){ $catid = '14'; } if($catid = "Web"){ $catid = '15'; } if($catid = "Other"){ $catid = '16'; } if($catid = "Gaming"){ $catid = '17'; } ?> I tried this and it works; Code: [Select] <?php $catid = "Automotive"; if($catid = "Automotive"){ $catid = '3'; } echo $catid; ?> But... When I add another if statement... Code: [Select] <?php $catid = "Automotive"; if($catid = "Automotive"){ $catid = '3'; } if($catid = "Gaming"){ $catid = '17'; } echo $catid; ?> It echos $catid as 17 and not 3 which is defined as a variable. I hope there is a simple solution for this! Thanks in advanced! preg_replace() asks that "Delimiter must not be alphanumeric or backslash" in the pattern. So I changed $new_text = preg_replace($_POST['withthis'] ,$_POST['withthis'],$_POST['text']); to this $replacethis = $_POST['replacethis']; $new_text = preg_replace("/$replacethis/",$_POST['withthis'],$_POST['text']); It works fine, but out of curiosity, is there any way to have the POST variable as a parameter directly, and why does it not work? Just to try it, I attempted: "/$_POST['withthis']/" and $_POST["/'withthis'/"] and both do not work. str_replace is a better option I think, but I am just trying to get a better understanding of this delimiter rule. Thanks for your time! HI - I'm trying to write an expression which tests the existence of a value within a POST variable. I have tried every which way ie isset, empty, ==0.00, NULL and yet I'm doing something wrong as nothing works. I hope you can help this student of PHP ! The expression is testing whether a price per lb exists ie the price of chicken per pound. But some products are not priced this way eg a jar of jam has no $pricelb[$i]. Here's some detail. The expression I am testing is: Code: [Select] if (!isset($pricelb[$i])){ // FIRST HALF FAILS $ordervalue = $price[$i]; $weight = '0.00';} else // SECOND HALF WORKS $pricelb = $pricelb[$i];{ $weight = $weight[$i]; $ordervalue = $pricelb * $weight; The $pricelb[$i] refers to an array of product weights coming off of the array $pricelb = $_POST['pricelb'] which I then cycle through using a for Loop, hence $pricelb[$i]. Bottom Line: if there is no pricelb then the then the ordervalue for the purchase is the same as the starting unit price. Suppose I have 2 products on the order. One with a pricelb of 5 and one with none. Then I do print_r on $_POST['pricelb'] I get: Code: [Select] Array ( [0] => 5 ) I.E. the second value is absent. YET, if I look into the DB table I see pricelb 0.00 for the second value - very confusing ! MANY MANY thanks ! for all your help ! Hi - I have a POST variable which contains a bunch of products with their codes and prices etc. However if the customer wants to delete one of those products it has to be removed from the POST before being processed. I have read the manual on unset which appears to work well when you know the key relating to the value, but if you take a look at the array ( below ) you can see that it is a multi- dimensional array where the number of potential entries not knowable in advance. My HTML checkbox for delete has a value of prodid. The answer is probably obvious but so far this student of PHP hasn't found it - MANY thanks for your advice ! Code: [Select] Array ( [quantity] => Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 ) [prodid] => Array ( [0] => 17 [1] => 28 [2] => 27 [3] => 25 ) [name] => Array ( [0] => Ribs Large pack 20 pieces [1] => 25 Piece Bag [2] => Sirloin Steak [3] => 50 piece bag of Scalops ) [orderid] => Array ( [0] => JAC0398 [1] => JAC2920 [2] => JAC2920 [3] => JAC2920 ) [pricelb] => Array ( [0] => 5.00 [1] => [2] => [3] => ) [submit] => Update and Submit to Picking >> ) www.mywebpage.co.uk/page22 Is it possible to produce a variable with the value = page22 using only the url above, I know that usually you would use get and post, but I was just curious to know if this had been done before. I currently have a php form that asks for first name, last name and email address then when they click submit it sends me an email with this information. I also have a javascript that pops up a window saying their message was sent with an ok button that redirects them back to the main page. I'd like to change this to redirect them to a new php page with a certificate with their name on it taken from the previous php form (but still email me the information). My form action currently points back to the same php page for verification of information (like valid email address, etc.) so I can't point that to a new page. Is there any way to do this? The variables I have for the first name and last name are just $firstname and $lastname. I have been pulling my hair out for about 2 weeks with this problem. I am doing this on a localhost set up, not a live server. Here are the fields in the categories table in question: id, cattitle, caturl, catdesc, orderby, parentid What I am trying to accomplish is to create a dropdown list from the values in cattitle and parentid fields which I have done successfully. Here is the code from my "categories_modify.php" file where the dropdown is displayed. <form action="" method="POST"> <table cellspacing="5" cellpadding="1" border="0"> <tr> <td> Change Parent Category To: </td> <td> <select name="location"> <?php foreach ($categories as $loc): ?> <option name="parid" value="<?php htmlout($loc['parentid']); ?>"><?php htmlout($loc['cattitle']); ?></option> <?php endforeach; ?> </select> </td> </tr> <tr> <td> </td> <td> <input type="hidden" name="id" value="<?php htmlout($id); ?>" /> <input type="submit" value="Update" /> </td> </tr> </table> </form> The code generating the values in the form is in my controller script called index.php. Here is the code for that part. **Note that the top section of the script below populates a series of text boxes with current values in the database for editing/updating I did not show "edit" form in the code above as it works fine. The part of code populating my dropdown box values starts with the "locat... line except for my db.inc.php database connection at the top (which also works fine). if (isset($_POST['action']) and $_POST['action'] == 'Edit') { include $_SERVER['DOCUMENT_ROOT'] . './includes/db.inc.php'; { $id = mysqli_real_escape_string($link, $_POST['id']); $sql = "Select id, cattitle, orderby, caturl, catdesc, parentid from categories where id = '$id'"; $result = mysqli_query($link, $sql); if (!$result) { $error = 'Error fetching category details ' . mysqli_error($link); include 'error.php'; exit(); } $row = mysqli_fetch_array($result); $pagetitle = 'Edit Category'; $action = 'editform'; $id = $row['id']; $cattitle = $row['cattitle']; $orderby = $row['orderby']; $caturl = $row['caturl']; $catdesc = $row['catdesc']; $button = 'Update'; $locate = "Select id, cattitle, parentid from categories order by cattitle asc"; $res = mysqli_query($link, $locate); if (!$res) { $error = 'Error fetching category details ' . mysqli_error($link); include 'error.php'; exit(); } while ($locat = mysqli_fetch_array($res)) { $categories[] = array('id' => $locat['id'], 'cattitle' => $locat['cattitle'], 'parentid' => $locat['parentid']); } } include 'categories_modify.php'; exit(); } Now for the code that gets the POSTED info from the dropdown window. if (isset($_GET['location'])) { include $_SERVER['DOCUMENT_ROOT'] . './includes/db.inc.php'; $id = mysqli_real_escape_string($link, $_POST['id']); $parentid = mysqli_real_escape_string($link, $_POST['parid']); $parentid++; $sql = "Update categories set parentid = '$parentid' where id = '$id'"; if (!mysqli_query($link, $sql)) { $error = 'Error updating categories ' . mysqli_error($link); include 'error.php'; exit(); } header('Location: .'); exit(); } The goal is to take the parentid value and increase it by 1 so I can create subcategories based on the parentid value. (maybe not the best way but I'd still like to figure out why I can't make this work.) This line is where I think the problem is, or atleast part of it: $parentid = mysqli_real_escape_string($link, $_POST['parid']); I believe it is coming back blank because when I re-run the script for my "test" value it will always comeback as 1 (the default value for parentid is 0) 0 + 1 = 1. If I update the form again where the parentid now equals 1 it still equals 1, can't get it to 2. BTW I have tried every variation of the above line I could think of with no luck hence this post. Thanks for any help. I hope this was clear enough. hi is it possible to post a variable like this either with javascript or php query.php Code: [Select] <?php include("../../includes/config.php"); mysql_connect($db_address, $db_username, $db_password);mysql_select_db($db_name) or die(mysql_error()); $fid = $_GET['fid']; $fid = mysql_real_escape_string($fid); $query10 = "SELECT * FROM films WHERE (film_id = '$fid')"; $qry_result10 = mysql_query($query10) or die(mysql_error()); while($row10 = mysql_fetch_array($qry_result10)) { $urlfid="http://www.onfilm.biz/streaming/home/".$row10['client']."/".$row10['client_office']."/".$row10['filename'].".mp4";?> <a class="hofwhite14" href="#" onclick="loadNplay('<?php echo $urlfid; ?>')"><u></u>Property Film</u></a> <?php }mysql_close(); //EDIT 290510 ?> <script type="text/javascript"> var video= $urlfid; $.post('indextest.php', {urlfid:video}); </script> Hey guys. This is my code: <?php session_start(); if ($_SESSION['adminlogin'] == 1){ //Run } else { header('Location: Log-In.php'); exit; } ?> <!DOCTYPE HTML> <html lang="en-GB"> <head> <meta charset="utf-8"> <!--Search Engine Meta Tags--> <meta name="author" content="Worldwide Lighthouses"> <meta name="keywords" content="Lighthouses,Lightships,Trinity House,Fog Signals,Fog Horns,Fresnel"> <meta name="description" content="Worldwide Lighthouses is the number 1 source of information, pictures and videos on the Subject of Lighthouses and Lightships"> <!--Stylesheets/Javascript--> <link rel="stylesheet" href="../../Page-Layout.css" media="screen and (min-width: 481px)"> <link rel="stylesheet" href="../../Mobile-Page-Layout.css" media="only screen and (max-width:480px)"> <!--Mobile Browser Support--> <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <!--IE Support--> <!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <link rel="stylesheet" href="../Page-Layout.css"><![endif]--> <meta name="application-name" content="Worldwide Lighthouses"> <meta name="msapplication-starturl" content="http://worldwidelighthouses.com/"> <meta name="msapplication-tooltip" content="Worldwide Lighthouses: Your number one source of Lighthouse Information, Videos and Pictures"> <meta name="msapplication-task" content="name=Lighthouses;action-uri=http://worldwidelighthouses.com/Lighthouses.php;icon-uri=http://worldwidelighthouses.com/IE9/Lighthouses.ico"> <meta name="msapplication-task" content="name=Lightships;action-uri=http://worldwidelighthouses.com/Lightships.php;icon-uri=http://worldwidelighthouses.com/IE9/Lightships.ico"> <meta name="msapplication-task" content="name=Fog Signals;action-uri=http://worldwidelighthouses.com/Fog-Signals.php;icon-uri=http://worldwidelighthouses.com/IE9/Fog-Signals.ico"> <meta name="msapplication-task" content="name=Glossary;action-uri=http://worldwidelighthouses.com/Glossary.php;icon-uri=http://worldwidelighthouses.com/IE9/Glossary.ico"> <title>Mailing List Administration | Worldwide Lighthouses</title> </head> <body> <header> <h1 id="WWLH">Worldwide Lighthouses</h1> <form method="get" action="http://www.worldwidelighthouses.com/Search/search.php" id="Search-Box"> <input type="search" placeholder="Search Worldwide Lighthouses" name="query" id="query" size="30" value="" autocomplete="off"> <input type="submit" value="Search"> <input type="hidden" name="search" value="1"> </form> </header> <nav> <ul id="Nav"> <li class="MenuButton" id="Index"><a href="http://www.worldwidelighthouses.com/Index.php"><p class="Nav">Home</p></a></li> <li class="MenuButton" id="Lighthouses"><a href="http://www.worldwidelighthouses.com/Lighthouses.php"><p class="Nav">Lighthouses</p></a></li> <li class="MenuButton" id="Lightships"><a href="http://www.worldwidelighthouses.com/Lightships.php"><p class="Nav">Lightships</p></a></li> <li class="MenuButton" id="FogSignals"><a href="http://www.worldwidelighthouses.com/Fog-Signals.php"><p class="Nav">Fog Signals</p></a></li> <li class="MenuButton" id="Daymarks"><a href="http://www.worldwidelighthouses.com/Daymarks.php"><p class="Nav">Daymarks</p></a></li> <li class="MenuButton" id="Buoys"><a href="http://www.worldwidelighthouses.com/Buoys.php"><p class="Nav">Buoys</p></a></li> <li id="MenuButtonLast"><a href="http://www.worldwidelighthouses.com/Glossary.php"><p class="Nav">Glossary</p></a></li> </ul> </nav> <?php if ($_SESSION['adminlogin']==1) { echo '<div id="logout"> <div style="float:left; width:30%; text-align:left;!important"> <a href="Log-In-Accept-Deny.php">Back to Admin Home</a> </div> <div style="float:right; width:70%;"> <a href="Logout.php">Log Out of Admin</a> <p style="font-size:10px;">Always Sign Out when Finished!</p> </div></div>';} ?> <article> <?php $title = $_POST['title']; $introparagraph = $_POST['introparagraph']; $update1title = $_POST['update1title']; $update2title = $_POST['update2title']; $update3title = $_POST['update3title']; $update1caption = $_POST['update1caption']; $update2caption = $_POST['update2caption']; $update3caption = $_POST['update3caption']; $update1link = $_POST['update1link']; $update2link = $_POST['update2link']; $update3link = $_POST['update3link']; $maincontenttitle = $_POST['maincontenttitle']; $article = $_POST['article']; $articlelink = $_POST['articlelink']; ################################################################# #####################IMAGE UPLOAD SCRIPT######################### ################################################################# // Where the mainimage file is going to be placed $target_path_mainimage = "Newsletter-Images/Main-Images/"; // Wheere the update images will be places $target_path_updateimage1 = "Newsletter-Images/Update-Images/1/"; $target_path_updateimage2 = "Newsletter-Images/Update-Images/2/"; $target_path_updateimage3 = "Newsletter-Images/Update-Images/3/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ //Main $target_path_mainimage = $target_path_mainimage . basename( $_FILES['mainimage']['name']); //Update Images $target_path_updateimage1 = $target_path_updateimage1 . basename( $_FILES['update1']['name']); $target_path_updateimage2 = $target_path_updateimage2 . basename( $_FILES['update2']['name']); $target_path_updateimage3 = $target_path_updateimage3 . basename( $_FILES['update3']['name']); //Move the main image file to its location if(move_uploaded_file($_FILES['mainimage']['tmp_name'], $target_path_mainimage)) { } else{ echo "There was an error uploading the main image file, please try again!"; } //Move the update images to their location if(move_uploaded_file($_FILES['update1']['tmp_name'], $target_path_updateimage1)) { } else{ echo "There was an error uploading the 1st update image file, please try again!"; } if(move_uploaded_file($_FILES['update2']['tmp_name'], $target_path_updateimage2)) { } else{ echo "There was an error uploading the 2nd update image file, please try again!"; } if(move_uploaded_file($_FILES['update3']['tmp_name'], $target_path_updateimage3)) { } else{ echo "There was an error uploading the 3rd update image file, please try again!"; } ############################################################################## ######################### END IMAGE UPLOAD SCRIPT ############################ ############################################################################## $mainimageurl = "http://www.worldwidelighthouses.com/Newsletter/Admin/Newsletter-Images/Main-Images/".basename( $_FILES['mainimage']['name']); $update1imageurl = "http://www.worldwidelighthouses.com/Newsletter/Admin/Newsletter-Images/Update-Images/1/".basename( $_FILES['update1']['name']); $update2imageurl = "http://www.worldwidelighthouses.com/Newsletter/Admin/Newsletter-Images/Update-Images/2/".basename( $_FILES['update2']['name']); $update3imageurl = "http://www.worldwidelighthouses.com/Newsletter/Admin/Newsletter-Images/Update-Images/3/".basename( $_FILES['update3']['name']); $emailcontent = ' <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>'.$title.'</title> </head> <body style="margin: 0; padding: 0;"> <table width="100%" cellpadding="0" cellspacing="0" bgcolor="#333333"><tr><td> <table cellspacing="15" id="main" align="center" width="600" cellpadding="0" bgcolor="ffffff" style="margin-top: 10px; border: 1px solid #cfcece;"> <tr> <td> <table id="header" cellpadding="10" cellspacing="0" align="center" bgcolor="#000000"> <tr> <td width="570" bgcolor="#356A5C"><a href="http://www.worldwidelighthouses.com" style="color: #FFF; text-decoration: none;"><h1 style="font-size: 24px; font-family:'."'Lucida Grande', 'Lucida Sans', 'Lucida Sans Unicode'".', sans-serif; margin: 0; color: #ffffff; padding: 0;">Worldwide Lighthouses</h1></a><h2 style="font-size: 24px; font-family: Arial, Helvetica, sans-serif; margin: 0; color: #ffffff !important; padding: 0;">'.$title.'</h2></td> </tr> <tr> <td width="570" align="right" bgcolor="#154A3C"><p style="font-size: 12px; line-height: 1.5; font-family:'."'Lucida Grande', 'Lucida Sans', 'Lucida Sans Unicode'".', sans-serif; color: #ffffff; margin: 0; padding: 0;">'.date("F Y").'</p></td> </tr> </table><!-- header --> </td> </tr><!-- header --> <tr> <td></td> </tr> <tr> <td> <table id="content-1" cellpadding="0" cellspacing="0" align="center"> </table> <img src="'.$mainimageurl.'" height="190" alt="'.$title.'" width="570" style="display: block;" /><!-- content 1 --> </td> </tr><!-- content 1 --> <tr> <td> <table id="content-2" cellpadding="0" cellspacing="0" align="center"> <tr> <td width="570"><p style="font-size: 12px; line-height: 1.5; font-family:'."'Lucida Grande', 'Lucida Sans', 'Lucida Sans Unicode',".' sans-serif; color: #444444; margin: 0; padding: 0;">'.$introparagraph.'</p></td> </tr> </table><!-- content-2 --> </td> </tr><!-- content-2 --> <tr> <td> <table id="content-3" cellpadding="0" cellspacing="0" align="center"> <tr> <td valign="top" width="170" bgcolor="d0d0d0" style="padding: 5px;"> <a href="'.$update1link.'" style="color: #FFF; text-decoration: none;"><img src="'.$update1imageurl.'" alt="'.$update1title.'" style="display: block;" /></a> </td> <td width="15"></td> <td valign="top" width="170" bgcolor="d0d0d0" style="padding: 5px;"> <a href="'.$update2link.'" style="color: #FFF; text-decoration: none;"><img src="'.$update2imageurl.'" alt="'.$update2title.'" style="display: block;" /></a> </td> <td width="15"></td> <td valign="top" width="170" bgcolor="d0d0d0" style="padding: 5px;"> <a href="'.$update3link.'" style="color: #FFF; text-decoration: none;"><img src="'.$update3imageurl.'" alt="'.$update3title.'" style="display: block;" /></a> </td> </tr> </table><!-- content-3 --> </td> </tr><!-- content-3 --> <tr> <td> <table id="content-4" cellpadding="0" cellspacing="0" align="center"> <tr> <td width="180" valign="top"> <a href="'.$update1link.'" style="color: #FFF; text-decoration: none;"><h5 style="font-size: 18px; margin: 0 0 0.8em; font-family: Arial, Helvetica, sans-serif; color: #444444;">'.$update1title.'</h5></a> <a href="'.$update1link.'" style="color: #FFF; text-decoration: none;"><p style="font-size: 12px; line-height: 1.5; font-family:'." 'Lucida Grande', 'Lucida Sans', 'Lucida Sans Unicode'".', sans-serif; color: #444444; margin: 0; padding: 0;">'.$update1caption.'</p></a> </td> <td width="15"></td> <td width="180" valign="top"> <a href="'.$update2link.'" style="color: #FFF; text-decoration: none;"><h5 style="font-size: 18px; margin: 0 0 0.8em; font-family: Arial, Helvetica, sans-serif; color: #444444;">'.$update2title.'</h5></a> <a href="'.$update2link.'" style="color: #FFF; text-decoration: none;"><p style="font-size: 12px; line-height: 1.5; font-family:'."'Lucida Grande', 'Lucida Sans', 'Lucida Sans Unicode'".', sans-serif; color: #444444; margin: 0; padding: 0;">'.$update2caption.'</p></a> </td> <td width="15"></td> <td width="180" valign="top"> <a href="'.$update3link.'" style="color: #FFF; text-decoration: none;"><h5 style="font-size: 18px; margin: 0 0 0.8em; font-family: Arial, Helvetica, sans-serif; color: #444444;">'.$update3title.'</h5></a> <a href="'.$update3link.'" style="color: #FFF; text-decoration: none;"><p style="font-size: 12px; line-height: 1.5; font-family:'."'Lucida Grande', 'Lucida Sans', 'Lucida Sans Unicode'".', sans-serif; color: #444444; margin: 0; padding: 0;">'.$update3caption.'</p></a> </td> </tr> </table><!-- content-4 --> </td> </tr><!-- content-4 --> </tr><!-- content-5 --> <td> <tr bgcolor="#FFFFFF" align="center"> <a href="'.$articlelink.'" style="color: #FFF; text-decoration: none;"><td height="30"><h5 style="font-size: 18px; margin: 0 0 0.8em; font-family: Arial, Helvetica, sans-serif; color: #444444 !important; text-align:left;">'.$maincontenttitle.'</h5></a></td> </tr> <tr> <td> <table id="content-6" cellpadding="0" cellspacing="0" align="center" bgcolor="#FFFFFF"> <p align="left" style="font-size: 12px; line-height: 1.5; font-family:'."'Lucida Grande', 'Lucida Sans', 'Lucida Sans Unicode'".', sans-serif; color: #444444; margin: 0; padding: 0;">'.$article.'</p> <p align="center" style="font-size: 12px; line-height: 1.5; font-family:'."'Lucida Grande', 'Lucida Sans', 'Lucida Sans Unicode'".', sans-serif; color: #444444; margin: 0; padding: 0;"><a href="http://www.worldwidelighthouses.com" style="text-decoration: none; color: #4A72AF;">Visit the website now!</a></p> </table> </td> </tr> </table><!-- main --> <table id="bottom-message" cellpadding="20" cellspacing="0" width="600" align="center"> <tr> <td align="center"> <p style="font-size: 12px; line-height: 1.5; font-family: Arial, Helvetica, sans-serif; color: #444444; margin: 0; padding: 0;">You are receiving this email because you signed up for updates</p> <p style="font-size: 12px; line-height: 1.5; font-family: Arial, Helvetica, sans-serif; color: #444444; margin: 0; padding: 0;"><a href="mailto:dantonybrown@hotmail.co.uk?subject=Unsubscribe%20Me&body=Please%20unsubscribe%20me%20from%20your%20mailing%20list" style="text-decoration: none; color: #4A72AF;">Unsubscribe instantly</a> </td> </tr> </table><!-- top message --> </td></tr></table><!-- wrapper --> </body> </html> '; echo '<div class="Textbox"><h2>Email Preview:</h2>'; echo '<p>If you are happy with the below preview (note: Make sure you check all links work and spelling is correct before sending) then click te button below</p>'; ?> <form action="Send-Email.php" method="post"> <input type="hidden" value="<?php $emailcontent?>" name="emailcontent"> <input type="submit" value="Send Email to Entire Contact List"> </form> </div> <?php echo $emailcontent;?> </article> <footer> <ul> <li><a href="http://www.worldwidelighthouses.com/About.php">About</a></li> <li><a href="http://www.worldwidelighthouses.com/Contact-us.php">Contact</a></li> <li><a href="http://www.worldwidelighthouses.com/Use-Our-Media.php">Use our media</a></li> <li><a href="http://www.worldwidelighthouses.com/Search/search.php">Search</a></li> <li><a href="http://www.worldwidelighthouses.com/Social-Networking.php">Social</a></li> <li><a href="#Top">Back to top</a></li> </ul> <br> <br> &#169; Worldwide Lighthouses <?php echo date("Y"); ?> </footer> </body> Essentially what im trying to do is create and display a preview of an automatically generated email (which works) then i want the email (all of whoms code is contained in $emailcontent to be posted to the next page where it will actually send. However this does not seem to work. any advice? Thanks. Danny having issues with Code: [Select] echo curl_setopt($ch, CURLOPT_POSTFIELDS,"name='. $name .'&email='. $email .'&macs='.$mac_addresses.'&serial=".$serialnumber); the thing is $mac_addresses is a serialized array that should look like this Code: [Select] 4a:4:{i:0;s:14:"98340234820384";i:1;s:16:"0980342883408230";i:2;s:11:"72843729374";i:3;s:16:"4209384082304980";} but when I unserilize $mac_addressed and echo it I get Code: [Select] \'.a:4:{i:0;s:14:\"98340234820384\";i:1;s:16:\"0980342883408230\";i:2;s:11:\"72843729374\";i:3;s:16:\"4209384082304980\";}.\' can anyone see what my issue is? Hi, I wrote this to retrieve a file based on a POST value. For some reason it will not retrieve the file content and display it at all. I get this message: Warning: fopen(18.txt) [function.fopen]: failed to open stream: No such file or directory in /home/content/x/y/z/path/html/includes/different.php The 18 is the correct POST value. So that is a positive There is a file named 18.txt in /home/content/x/y/z/path/html/includes/18.txt Thanks. <?php $id5 = $_POST[id]; //Display Text File $myFile = $id5; $myFile .= ".txt"; $fh = fopen($myFile, 'r'); $theData = fgets($fh); fclose($fh); echo $theData; ?> Hi, I'm trying to edit some database fields, I have text1, text2, text3, text4, text5, text6 etc.. They are displayed on the index.php page, with an edit link so the user can choose which set to edit // Extract details from database $sql = "SELECT * FROM data WHERE id=1"; $stmt = $db->prepare($sql); $stmt->execute(); $e = $stmt->fetch(); <h1><?php echo $e['text1']) ?></h1> <p><?php echo ($e['text2']); ?></p> <p><a href="edit.php">EDIT</a></p> <h1><?php echo $e['text3']) ?></h1> <p><?php echo ($e['text4']); ?></p> <p><a href="edit.php">EDIT</a></p> <h1><?php echo $e['text5']) ?></h1> <p><?php echo ($e['text6']); ?></p> <p><a href="edit.php">EDIT</a></p>
edit.php: // Extract details from database $sql = "SELECT * FROM data WHERE id=1"; $stmt = $db->prepare($sql); $stmt->execute(); $e = $stmt->fetch(); <form method="post" action="process.php" enctype="multipart/form-data"> <label>Page Title <input type="text" name="text1" maxlength="90" value="<?php echo $e['text1'] ?>" /> </label> <br> <label>Title Text</label> <textarea name="text2"><?php echo $e['text2'] ?></textarea> <input id="button" type="submit" name="submit" value="Save Changes" /> and then update them: process.php $sql = "UPDATE data SET text1=?, text2=? WHERE id=1 LIMIT 1"; $stmt = $db->prepare($sql); $stmt->execute( array( $_POST['text1'], $_POST['text2'] ) ); $stmt->closeCursor(); Question: How can I pass the form values dynamically from the index.php page so I don't have to hard code text1, text2 etc into the edit.php and process.php page and have a different update & process page for each set of data?
Thanks in advance. |