PHP - Problem With Parsing Variable To Form
First, apologies if this is in the wrong section, basically I am not sure what language my problem lies!
Here is the general over view. I have a jquery script that automatically selects a group of sub categorys and pus them in a select list depending on the input of a first select list, so you can choose you main cat and then the sub cats for this cat appear in the next list, this all works fine, the basic code is below: Code: [Select] <script type="text/javascript"> $(document).ready(function() { $('#wait_1').hide(); $('#drop_1').change(function(){ $('#wait_1').show(); $('#result_1').hide(); $.get("scripts/func.php", { func: "drop_1", drop_var: $('#drop_1').val() }, function(response){ $('#result_1').fadeOut(); setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400); }); return false; }); }); function finishAjax(id, response) { $('#wait_1').hide(); $('#'+id).html(unescape(response)); $('#'+id).fadeIn(); } </script> <form action='do.php' method='post'> <select name="drop_1" id="drop_1"> <option value="" selected="selected" disabled="disabled">Select a Category</option> <?php getTierOne(); ?> </select> <span id="wait_1" style="display: none;"> <img alt="Please Wait" src="images/ajax-loader.gif"/> </span> <span id="result_1" style="display: none;"></span> This calls scripts/func.php Code: [Select] <?php //************************************** // Page load dropdown results // //************************************** function getTierOne() { $result = mysql_query("SELECT * FROM blog_cats") or die(mysql_error()); while($tier = mysql_fetch_array( $result )) { echo '<option value="'.$tier['cat_id'].'">'.$tier['cat_name'].'</option>'; } } //************************************** // First selection results // //************************************** if($_GET['func'] == "drop_1" && isset($_GET['func'])) { drop_1($_GET['drop_var']); } function drop_1($drop_var) { include_once('../connect.php'); $result = mysql_query("SELECT * FROM blog_subs WHERE cat_id='$drop_var'") or die(mysql_error()); echo '<select name="tier_two" id="tier_two"> <option value=" " disabled="disabled" selected="selected">Select Sub Catergory</option>'; while($drop_2 = mysql_fetch_array( $result )) { echo '<option value="'.$drop_2['sub_id'].'">'.$drop_2['sub_name'].'</option>'; } echo '</select> '; } ?> The problem I am having is getting the second select (tier_two) to pass to my form processing page. I just get an undefined variable error Many Thanks Similar TutorialsThis works: Code: [Select] form action="http://localhost/mysite/css/screen.css" method="post"> This does not work: Code: [Select] <?php $link_1 = "http://localhost/mysite/css/screen.css" ; $link_2 = '"' . "http://localhost/mysite/css/screen.css" .'"' ; ?> <form action=<?php echo $link_1;?> method="post"> <form action=<?php echo $link_2;?> method="post"> Why do neither of the PHP variables work? Thanks! I have been trying to figure this out for more than a week but my form does not parse the information to send it to mysql. When I try to send it I get this error: Parse error: syntax error, unexpected ')' in /home/content/19/6550319/html/listingpoopys.php on line 91 Can anyone maybe try the code out and figure out what is not right? Here is the form. Underneath will be the php Code: [Select] <form method="post" action="something.php" enctype="multipart/form-data"> <label>Asking Price </label> <input type="text" name="price" /> <br /> <br /> <div style="text-align: left;"> </div> <label>Photo 1 <span class="small">(required)</span> </label> <input type="hidden" name="size" value="350000" /> <input type="file" name="photo" /> <label>Photo 2 (Optional) <span class="small">no larger than 320px x 240px </span> </label> <input type="hidden" name="size" value="77000" /> <input type="file" name="phototwo" /> <label>Photo 3 (Optional) <span class="small">no larger than 320px x 240px </span> </label> <input type="hidden" name="size" value="77000" /> <input type="file" name="photothree" /> <label>Photo 4 (Optional) <span class="small">no larger than 320px x 240px </span> </label> <input type="hidden" name="size" value="77000" /> <input type="file" name="photofour" /> <label> description <span class="small">Ad Copy</span> </label> <textarea name="atDescription" rows="10" cols="35" onfocus="this.value=''; this.onfocus=null;">What you enter here will show up on the description area</textarea> <p>What is the condition?</p> <select name="condition"> <option value="Excellent">Excellent</option> <option value="Very Good">Very Good</option> <option value="Good">Good</option> <option value="Fair">Fair</option> </select> <p>How many GB?</p> <select name="giga"> <option value="16">16</option> <option value="32">32</option> <option value="64">64</option> </select> <p>Does It Come installed?</p> <select name="yesg"> <option value="Yes">Yes</option> <option value="No">No</option> </select> <br /><br /> <h1>Personal Information</h1> <p class="style">Information below will not appear on website</p> <label>First Name </label> <input type="text" name="firstName" /> <label>Last Name </label> <input type="text" name="lastName" /> <label>email </label> <input type="text" name="email" /> <br/> <br/> <input type="submit" value="Submit form" /> </form> Here is the php: Code: [Select] <?php //This is the directory where images will be saved $target = "upload/"; // $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $price=$_POST['price']; $pic=($_FILES['photo']['name']); $pic2=($_FILES['phototwo']['name']); $pic3=($_FILES['photothree']['name']); $pic4=($_FILES['photofour']['name']); $description=$_POST['atDescription']; $condition=$_POST['condition']; $gig=$_POST['giga']; $yesg=$_POST['yesg']; $fname=$_POST['firstName']; $lname=$_POST['lastName']; $email=$_POST['email']; // Connects to your Database // I'll assume you are using host, user and psssword, and have just removed them for security. mysql_connect ("", "", "") or die(mysql_error()) ; // I'll assume you have the database name in here, and have just removed it for security. mysql_select_db("") or die(mysql_error()) ; $price = mysql_real_escape_string ($price); $description = mysql_real_escape_string ($description); $condition = mysql_real_escape_string ($condition); $gig = mysql_real_escape_string ($gig); $yesg = mysql_real_escape_string ($yesg); $fname = mysql_real_escape_string ($fname); $lname = mysql_real_escape_string ($lname); $email = mysql_real_escape_string ($email); //Writes the photos to the server and store the names in $picname[] foreach ($_FILES["photos"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["photos"]["tmp_name"][$key]; $name = $_FILES["photos"]["name"][$key]; move_uploaded_file($tmp_name, "upload/$name"); $picname[] = $name; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your files."; } // setup empty names so that the variable will exist $pic = ""; $pic2 = ""; $pic3 = ""; $pic3 = ""; // overwrite the empty pic names if they exist if (count($picname) > 0) { //at least 1 pic $pic = $picname[0]; } if (count($picname) > 1) { //at least 2 pics $pic2 = $picname[1]; } if (count($picname) > 2) { //at least 3 pics $pic3 = $picname[2]; } if (count($picname) > 3) { //at least 4 pics $pic4 = $picname[3]; } // don't care if there's more than 4 // print variables to screen for debugging echo "price is ".$price."<br/>"; echo "description is ".$description."<br/>"; echo "condition is ".$condition."<br/>"; echo "gig is ".$gig."<br/>"; echo "yesg is ".$yesg."<br/>"; echo "fname is ".$fname."<br/>"; echo "lname is ".$lname."<br/>"; echo "email is ".$email."<br/>"; // remove or comment out when debugging complete //Writes the information to the database $sql = "INSERT INTO artdod (price,photo,phototwo,photothree,photofour,atDescription,condition,giga,yesg,firstName,lastName,email) VALUES ('$price', '$pic', '$pic2', '$pic3', '$pic4', '$description', '$condition', '$gig', '$yesg', '$fname', '$lname', '$email')") ; //Print the sql to screen after all the variable substitutions. echo $sql."<br/>"; // remove or comment out when debugging complete //Writes the information to the database mysql_query($sql) or die(mysql_error()); // and catch any error echo date("m/d/y : H:i:s", time()) ?> I am asking if anyone knows of any tutorials to take the contents of a simple form, hit submit, then the values go to an email, the email contents are then parsed and go into the correlating mysql table. For example, if I have a form like this http://nobaltimorebeveragetax.com/ It is only the first name, lastname, email address and zip code. I know how to do a POST or a GET, to put directly into a database table. The reason is because there are multiple sites with this type of form and would like them to go to one central database. I do not wish to do iframe since we would still have to style (css) each form. I have heard of "paring emails". Any tutorial, resources or suggestions would be most appreciated. Thanks Kip I have a situation were I need to just get a simple location. I don't want any while loops or any of that jazz. I just want 1 string location every time. <?php $ider = $_GET['id']; $conn = mysqli_connect("localhost", "Me", "pass", "MyDB"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT Location FROM LifeSaver1 WHERE id =$ider"; $result = $conn->query($sql); $obj = mysqli_fetch_object($result); $obj2 = $obj->Location; var_dump($obj); ?> This is what it outputs Quotestring(11) "Boston" I just need Boston. Can anyone give me a hint? I'm practicing some code here Code: [Select] reset($_POST); while (list ($key, $val) = each ($_POST)) { if ($val == "";) $val = "NULL"; $arVals[$key] = (get_magic_qqotes_gpc()) ? $val : addslashes($val); if($val == "NULL") $_SESSION[$key] = NULL; else $_SESSION[$key] = $val; if ($key != "access_period" && $key != "passwd") $arVals[$key] = "'".$arVals[$key]."'"; } And it's giving me error Quote Parse error: parse error in C:\wamp\www\php\user_registration\registered.php on line 26 line 26 is the Code: [Select] if ($val == "";) $val = "NULL"; I wonder what the problem is... Folks, I want to parse a particular element from an array and nothing else. Here is the Class (RecursiveTwitterSearch.php): <? /** * Wrapper class around the Twitter Search API for PHP * Based on the class originally developed by David Billingham * and accessible at http://twitter.slawcup.com/twitter.class.phps * @author Ryan Faerman <ryan.faerman@gmail.com> * @version 0.2 * @package PHPTwitterSearch */ class TwitterSearch { /** * Can be set to JSON (requires PHP 5.2 or the json pecl module) or XML - json|xml * @var string */ var $type = 'json'; /** * It is unclear if Twitter header preferences are standardized, but I would suggest using them. * More discussion at http://tinyurl.com/3xtx66 * @var array */ var $headers=array('X-Twitter-Client: PHPTwitterSearch','X-Twitter-Client-Version: 0.1','X-Twitter-Client-URL: http://ryanfaerman.com/twittersearch'); /** * Recommend setting a user-agent so Twitter knows how to contact you inc case of abuse. Include your email * @var string */ var $user_agent=''; /** * @var string */ var $query=''; /** * @var array */ var $responseInfo=array(); /** * Use an ISO language code. en, de... * @var string */ var $lang; /** * The number of tweets to return per page, max 100 * @var int */ var $rpp; /** * The page number to return, up to a max of roughly 1500 results * @var int */ var $page; /** * Return tweets with a status id greater than the since value * @var int */ var $since; /** * Returns tweets by users located within a given radius of the given latitude/longitude, where the user's location is taken from their Twitter profile. The parameter value is specified by "latitide,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers) * @var string */ var $geocode; /** * When "true", adds "<user>:" to the beginning of the tweet. This is useful for readers that do not display Atom's author field. The default is "false" * @var boolean */ var $show_user = false; /** * @param string $query optional */ function TwitterSearch($query=false) { $this->query = $query; } /** * Find tweets from a user * @param string $user required * @return object */ function from($user) { $this->query .= ' from:'.str_replace('@', '', $user); return $this; } /** * Find tweets to a user * @param string $user required * @return object */ function to($user) { $this->query .= ' to:'.str_replace('@', '', $user); return $this; } /** * Find tweets referencing a user * @param string $user required * @return object */ function about($user) { $this->query .= ' @'.str_replace('@', '', $user); return $this; } /** * Find tweets containing a hashtag * @param string $user required * @return object */ function with($hashtag) { $this->query .= ' #'.str_replace('#', '', $hashtag); return $this; } /** * Find tweets containing a word * @param string $user required * @return object */ function contains($word) { $this->query .= ' '.$word; return $this; } /** * Set show_user to true * @return object */ function show_user() { $this->show_user = true; return $this; } /** * @param int $since_id required * @return object */ function since($since_id) { $this->since = $since_id; return $this; } /** * @param int $language required * @return object */ function lang($language) { $this->lang = $language; return $this; } /** * @param int $n required * @return object */ function rpp($n) { $this->rpp = $n; return $this; } /** * @param int $n required * @return object */ function page($n) { $this->page = $n; return $this; } /** * @param float $lat required. lattitude * @param float $long required. longitude * @param int $radius required. * @param string optional. mi|km * @return object */ function geocode($lat, $long, $radius, $units='mi') { $this->geocode = $lat.','.$long.','.$radius.$units; return $this; } /** * Build and perform the query, return the results. * @param $reset_query boolean optional. * @return object */ function results($reset_query=true) { $request = 'http://search.twitter.com/search.'.$this->type; $request .= '?q='.urlencode($this->query); if(isset($this->rpp)) { $request .= '&rpp='.$this->rpp; } if(isset($this->page)) { $request .= '&page='.$this->page; } if(isset($this->lang)) { $request .= '&lang='.$this->lang; } if(isset($this->since)) { $request .= '&since_id='.$this->since; } if($this->show_user) { $request .= '&show_user=true'; } if(isset($this->geocode)) { $request .= '&geocode='.$this->geocode; } if($reset_query) { $this->query = ''; } return $this->objectify($this->process($request))->results; } /** * Returns the top ten queries that are currently trending on Twitter. * @return object */ function trends() { $request = 'http://search.twitter.com/trends.json'; return $this->objectify($this->process($request)); } /** * Internal function where all the juicy curl fun takes place * this should not be called by anything external unless you are * doing something else completely then knock youself out. * @access private * @param string $url Required. API URL to request * @param string $postargs Optional. Urlencoded query string to append to the $url */ function process($url, $postargs=false) { $ch = curl_init($url); if($postargs !== false) { curl_setopt ($ch, CURLOPT_POST, true); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs); } curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_NOBODY, 0); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers); $response = curl_exec($ch); $this->responseInfo=curl_getinfo($ch); curl_close($ch); if( intval( $this->responseInfo['http_code'] ) == 200 ) return $response; else return false; } /** * Function to prepare data for return to client * @access private * @param string $data */ function objectify($data) { if( $this->type == 'json' ) return (object) json_decode($data); else if( $this->type == 'xml' ) { if( function_exists('simplexml_load_string') ) { $obj = simplexml_load_string( $data ); $statuses = array(); foreach( $obj->status as $status ) { $statuses[] = $status; } return (object) $statuses; } else { return $out; } } else return false; } } class RecursiveTwitterSearch extends TwitterSearch { var $request_count = 0; var $max_request_count = 5; var $max_id; function recursive_results() { $request = 'http://search.twitter.com/search.'.$this->type; $request .= '?q='.urlencode($this->query); if(isset($this->rpp)) { $request .= '&rpp='.$this->rpp; } if(isset($this->page)) { $request .= '&page='.$this->page; } if(isset($this->lang)) { $request .= '?='.$this->lang; } if(isset($this->since)) { $request .= '&since_id='.$this->since; } if($this->show_user) { $request .= '&show_user=true'; } if(isset($this->geocode)) { $request .= '&geocode='.$this->geocode; } if(isset($this->max_id)) { $request .= '&max_id='.$this->max_id; } $response = $this->objectify($this->process($request)); $this->request_count++; if ($response) { $results = $response->results; if(!empty($response->next_page)) { preg_match('|\?page=([0-9]*)&max_id=([0-9]*)&|', $response->next_page, $matches); $this->page = $matches[1]; $this->max_id = $matches[2]; if ($this->request_count < $this->max_request_count) { $results = array_merge($results, $this->recursive_results()); } } return $results; } else return false; } function max_request_count($n) { $this->max_request_count = $n; return $this; } } ?> Here is how i am calling it: <?php require ("RecursiveTwitterSearch.php"); $rts = new RecursiveTwitterSearch('paintball mask'); echo '<pre>'; print_r($rts->recursive_results()); echo '</pre>'; echo 'It took ' . $rts->request_count . ' request(s) to get this result.'; ?> If you observer the Output, u will see lot of array, i want to extract only "[text]" portion. So the desired output should be like: Quote vPaintball Mask http://bit.ly/czBA6S The Paintball Republic does a short video about mask safety. LEARN. http://fb.me/KkMvjDWF airsoft vs paintball mask http://goo.gl/fb/tyoxk @mmorgansmithh like wearing a paintball mask on your head to starbucks Tippmann US Army Ranger Paintball Goggle Mask - Camo: Tippmann US Army Ranger Paintball Goggle Mask - Camo ... http://bit.ly/9hFi3p and so on......... Infact, i prfer to use "foreach" to each each element so i can do further operation on it. Can anyone help to achieve this? Natty Hallo I'm having a problem inserting $messageorder into mysql datebase. Otherwise works good. So there is no problem with database itself or mysql command too. I suspect there must be something in this code that mysql doesnt like. Also have to say that im able to sent email with $messageorder. Please take a look at the codee. Code: [Select] $messageorder = "\r\n" . 'Order:' . '<br><br><table>' . "\r\n"; $result3 = mysql_query("SELECT * FROM orderslist WHERE supplier='$supplier'") or die(mysql_error()); $data = array(); $data['' . $row3['id']] = $_POST['' . $row3['id']]; while($row3=mysql_fetch_array($result3)) { $value = $_POST['' . $row3['id']]; if ( $value == ""){ } else { $messageorder .= " <tr> <td class='H4'><strong>$row3[name]</strong></td> <td class='H4' align='center'>$value</td> <td class='H4'>$row3[unit]</td> </tr> "; } } $messageorder .= "</table>"; echo $messageorder; date_default_timezone_set('Europe/London'); $supplier=$_GET['order']; $delivery=$_POST['delivery']; $timestamp = date("H:i:s"); $datestamp = date('Y/m/d'); mysql_query ("INSERT INTO orders (id, datestamp, timestamp, supplier, ordertext, delivery ) VALUES ('', '$datestamp', '$timestamp', '$supplier', '$messageorder', '$delivery')"); If someone could help to find a solution I will appriciate ! Thank you very much Hey there, I am using prototype to send JSON information to a PHP file which will then use the data to update a database, the AJAX presently looks as follows: Code: [Select] function saveprofile() { var email = document.getElementById("email").value; var profileDetails = { "email":email, "titleitalic":titleitalic, "profileDetails":titlefontcolor, "titlefontcolor":titleunderline, "titleoffsettop":titleoffsettop, "titleoffsetleft":titleoffsetleft, "aboutbackgroundcolour":aboutbackgroundcolour, "aboutunderline":aboutunderline, "aboutfontfamily":aboutfontfamily, "aboutbold":aboutbold, "aboutitalic":aboutitalic, "aboutfontcolor":aboutfontcolor, "aboutoffsettop":aboutoffsettop, "aboutoffsetleft":aboutoffsetleft, "statusoffsetleft":statusoffsetleft, "statusinfooffsetright":statusinfooffsetright, "pictureoffsetleft":pictureoffsetleft, "profilebold":profilebold, "profileunderline":profileunderline, "profileitalic":profileitalic, "profilefontcolor":profilefontcolor, "profilefontfamily":profilefontfamily, "profilebackgroundcolour":profilebackgroundcolour } var jsonstring = JSON.stringify(profileDetails); alert(jsonstring); var request = new Ajax.Request ('scripts/updateprofile.php', { method: 'POST', parameters: jsonstring, onComplete: responseReturned } ); } Which outputs the following JSON which has been tested on http://www.jsonlint.com/ as valid: Code: [Select] { "email": "l-wilson-1986@hotmail.co.uk", "titleitalic": "normal", "profileDetails": "#d0deea", "titlefontcolor": "none", "titleoffsettop": 100, "titleoffsetleft": 100, "aboutbackgroundcolour": "transparent", "aboutunderline": "none", "aboutfontfamily": "Arial", "aboutbold": "normal", "aboutitalic": "normal", "aboutfontcolor": "#d0deea", "aboutoffsettop": 325, "aboutoffsetleft": 100, "statusoffsetleft": 450, "statusinfooffsetright": 250, "pictureoffsetleft": 100, "profilebold": "normal", "profileunderline": "none", "profileitalic": "normal", "profilefontcolor": "#fff", "profilefontfamily": "Arial", "profilebackgroundcolour": "#2c3c49" } The PHP file which receives the JSON looks as follows: Code: [Select] <?php $myjson = $_POST['jsonstring']; $jsonchars = json_decode(($myjson), true); $json_errors = array( JSON_ERROR_NONE => 'No error has occurred', JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded', JSON_ERROR_SYNTAX => 'Syntax error', ); echo 'Last error : ', $json_errors[json_last_error()], PHP_EOL, PHP_EOL; // do something with the data ?> The problem is the PHP constantly returns the following error: Last error : Syntax error and any attempts to access the JSON data returns NULL values. I have looked at several online examples and cannot see where I might be going wrong, and although users have had problems with syntax errors it normally relates to incorrect JSON. Any advice on this topic would be greatly appeciated Leanne Hi,
Well, I've been wondering if I can get answer to my problem here...
I'd used curl to fetch information from other site and then I need to parse the data to be displayed in our own. However I found something odd...I can't parse it to get what I want...however should I put the result into a html file, n parse the file itself...it's fine.
Basically I just need to find whether a word/phrase is there or not...n I'm using preg_match to do it so far. Since the time it first arises...I'd been googling n saw some posts...something similar to how regex is doing poorly in doing such thing...
However it does work when I just make a php file just to do that regex from the curl-result html file, it just not work on the actual php file which handle the process even if it's from the same curl-result html file. FYI, I'm using codeigniter.
I wonder if it got something to do with codeigniter or something...or is there any other better way to parse a html file from a curl result. In my opinion it's just the same...be it a curl result or just a normal html...so I really can't figure out where it went wrong.
I appreciate if there's anyone who can shed a light on this problem, even a little bit is a great help to me
Thanks in advance,
Hi, it's my first post so hello to you and i hope you will be forgiving:) I've made a basic script, which takes a urls from the form(each of them is the new row) and then search each of those urls for an email. The problem is that only the email from the last url is returned. print_r("show link:". $urls[$i]."<br>"); shows all urls in the form, but the print_r("show current_url:". $current_url); shows only the last one. Code: [Select] <?php $urls = explode("\n", $_POST['urls']); $db = new mysqli('localhost', 'root', 'root', 'urls'); if (mysqli_connect_errno()) { echo 'Błąd: '; exit; } for ($i=0; $i<count($urls); $i++){ print_r("show link:". $urls[$i]."<br>"); $current_url = file_get_contents($urls[$i]); print_r("show current_url:". $current_url); preg_match( "/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $current_url, $email);//email print_r ("show email:".$email[0]); $zapytanie = "INSERT INTO urle set adres = '$email[0]' "; $wynik = $db->query($zapytanie); } if ($wynik) { echo $db->affected_rows ."pozycji dodano."; } else { echo mysql_errno() . ":" . mysql_error() . "Wystąpił błąd przy dodawaniu urli "; } $db->close(); ?> My error happens on line #81 Hi , how I can save something into form? I mean , insert something in variable and than insert it into value in the form so when i send the form the value will be send too. I also want that it will be can not change. for example : <input name="email" value="a@s.d"/> but this example can be change if you insert something else. thanks , Mor. I am stuck on trying to get the form to repopulate after a failed validation. The real form involves REST calls and such but I trimmed the code back to this issue. I think I need to declare the variables differently. I also tried to use the variables in the PHP script to refill the form with the original form entries. I have tried numerous ways of getting the variables to repopulate but could never get it to work consistently (such as declaring global variables. Here is the form code: Code: [Select] <div> <a name="error_field"></a> <?php if($_GET['error']): ?> <div style="padding:10px;border:1px solid;color:#C70C0C;"><?php echo $_GET['error'] ?></div> <?php endif; ?> <div> <form method="post" action="process2.php"> <fieldset name="Group1"> <legend>Account Registration</legend> <div id="field"><label id="Firstname">First Name:</label></div> <div id="input"><input name="Firstname" id="Firstname" type="text" value="<?php $_POST['Firstname']?>"/></div> <div id="field"><label id="Lastname">Last Name:</label></div> <div id="input"><input name="Lastname" id="Lastname" type="text" value="<?php $_POST['Lastname']?>"/></div> <div id="field"><label id="Username">E-Mail Username):</label></div> <div id="input"><input name="Username" type="text" value="<?= $_POST['Username']?>"/></div> <div id="field"><label id="Password">Password:</label></div> <div id="input"><input name="Password" type="password" /></div> <div class="center" style="margin-top:15px;margin-bottom:15px"> <input name="Submitx" type="submit" value="submit" /> <input name="Reset1" type="reset" value="reset" /> </div> </fieldset></form> </div> </div> and here is the PHP which I have on a different page Code: [Select] <?php $new_user_username = check_input($_POST['Username'], "Enter your e-mail"); $new_user_password = check_input($_POST['Password'], "Enter your password"); $new_user_first_name = check_input($_POST['Firstname'], "Enter your first name"); $new_user_last_name = check_input($_POST['Lastname'], "Enter your last name"); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $new_user_username)) { show_error("E-mail address not valid"); } else{ header('Location: TY.php'); } function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { header('Location: tp1.php?error=' . $myError); exit(); } ?> Thanks in advance for any help. <head> <script language="javascript" type="text/javascript" src="datetimepicker.js"> </script> </head> <form action="main.php?id=test.php" method="post"> <p>Start Date: <input name="start" id="start" type="text" size="10"> <a href="javascript:NewCal('start','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a> End Date: <input name="end" id="end" type="text" size="10"> <a href="javascript:NewCal('end','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a> <input name="submit" type="submit" value="Look Up"> </form> <?php if(isset($_POST['submit'])) { $start = $_POST['start']; $end = $_POST['end']; $sql = "SELECT * FROM `corps` WHERE `notedate` BETWEEN '$start' AND '$end'"; $results = mysql_query($sql) OR DIE(mysql_error()); $numrow = mysql_num_rows($results) ; $i = 0; While ($i < $numrow) $shownotes = mysql_result($results,$i,'notes'); echo $shownotes."<br>"; { Echo "Records found ".$i."<br>"; $i++; } } The $start, and $end don't seem to be getting any values Hi, I have a weather app, coded which creates weather based on a set zip code. I want to create a form which when the user fills out their local code and clicks the send button that will change the zip code variable. Currently it is set up like this $zip = '90210'; //change to your zipcode need help with getting started with this. Thanks! I have a php index page that includes a form page with a delete button for that row. When I hit the delete button nothing happens. I am not sure if the variable is not passing or if the index.php page is not processing it correctly. Here is the index page that includes the form page: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Welcome Page Test</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <?php if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); $_GET = array_map('stripslashes_deep', $_GET); $_COOKIE = array_map('stripslashes_deep', $_COOKIE); $_REQUEST = array_map('stripslashes_deep', $_REQUEST); } if (isset($_GET['addjoke'])) { include 'form.html.php'; exit(); } $link = mysqli_connect('localhost', 'root', 'password'); if (!$link) { $output = 'Unable to connect to the database server.'; include 'output.html.php'; exit(); } if (!mysqli_set_charset($link, 'utf8')) { $output = 'Unable to set database connection encoding.'; include 'output.html.php'; exit(); } if (!mysqli_select_db($link, 'database')) { $output = 'Unable to locate the database.' . mysqli_error($link); include 'output.html.php'; exit(); } if (isset($_POST['joketext'])) { $joketext=mysqli_real_escape_string($link,$_POST['joketext']); $sql = "INSERT INTO jokes2 (joketext, jokedate) VALUES ('$joketext', CURDATE() )"; if (!mysqli_query($link,$sql)) { $error = 'Error adding submitted joke: ' . mysqli_error($link); include 'error.html.php'; exit(); } header('Location: .'); exit(); } if (isset ($_GET['deletejoke'])) { $id= mysqli_real_escape_string($link,$_POST['id']); $sql = "DELETE FROM jokes2 WHERE id='$id'"; if(!mysqli_query($link,$sql)) { $error= 'Error deleting actor: ' . mysqli_error($link); include 'error.html.php'; exit(); } header('Location: .'); exit(); } $result = mysqli_query($link, 'SELECT jokes2.id, joketext, name, email FROM jokes2 INNER JOIN author ON authorid = author.id'); if (!$result) { $error = 'Error retrieving data' . mysqli_error($link); include 'error.html.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $jokes[] = array('id'=>$row['id'], 'joketext'=>$row['joketext'], 'name'=>$row['name'], 'email'=>$row['email']); } include 'jokes.html.php'; ?> </body> </html> The $_GET array should be getting the variable id passed when the Delete button is pressed on the form, but nothing is happening when I press the button. Here is the form: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Welcome Page Test</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <p> <a href="?addjoke">Add Joke </a> </p> <p> Here are all the jokes: </p> <form action="?deletejoke" method="post"> <?php foreach($jokes as $joke): ?> <p> <?php echo htmlspecialchars($joke['id'], ENT_QUOTES, 'UTF-8'), htmlspecialchars($joke['joketext'], ENT_QUOTES, 'UTF-8'), htmlspecialchars($joke['name'], ENT_QUOTES, 'UTF-8'), htmlspecialchars($joke['email'], ENT_QUOTES, 'UTF-8'); ?> <input type="hidden" name="id" value="<?php echo $joke['id']; ?>" /> <input type="submit" value="Delete"/> </p> </form> <?php endforeach; ?> </p> </body> </html> All of my other variables seem to be passing just fine. Any ideas why this one is a problem? Ok here is what im trying to do: 1. drop down list pulled from mysql database.( working ) 2. after you select the name in the drop down list 3. Use selected name to another page. here is code Code: [Select] <?php include('include/db_connection.inc'); $table = "truck_master"; $result = mysql_query( "SELECT driver_name FROM $table" ); $options=""; while ($row=mysql_fetch_array($result)) { $driver_name=$row["driver_name"]; $options.="<OPTION VALUE=\"driver_name\">".$driver_name.'</option>'; } ?> <html> <head> </head> <body> <table align="center"> <form name="form1" method="GET" align="center" action="issue.php"> <tr> <td>Driver Name :</td> <td><SELECT name="driver_name"><OPTION VALUE=''>Choose<?php echo $options?></SELECT> </td> </tr> <tr> <td><input type="submit" name="Submit" value="Submit"> </td> </tr> </form> </table> </body> <html> Second Code IS Code: [Select] $driver = $_GET['driver_name']; I have a form passing user's search term, ie name. $pname = mysql_real_escape_string($pname; Not sure on proper syntax to include this in my select statement. I also want it to return for partial string matched, like 'mik' for 'mike': $result = mysql_query( "SELECT * FROM guest WHERE name like '$pname'" ); Currently I have a PHP file that is pulling information from a table in the Database and inserting it into an HTML table. It consists of the fields: Last_Name, First_Name, Party, District, Address, CIty, State, Zip, and Email. And the Email field is being converted to a Hyperlink. (All working fine so far) I also have a form that has a prewritten letter to be sent to the email address. I need to have the HyperLink from the Email pass the address to the form to allow me to send it. I am not sure how to get this to happen. Here is the code I have so far: The pull from the database: <?php $dbhost = 'localhost'; $dbuser = 'removed'; $dbpass = 'removed'; $db = 'removed'; $link = mysql_connect($dbhost, $dbuser, $dbpass)or die(mysql_error()); mysql_select_db($db)or die(mysql_error()); $result = mysql_query("SELECT * FROM 2011members") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Last Name</th> <th>First Name</th> <th>Party</th> <th>District</th> <th>Address</th> <th>City</th> <th>State</th> <th>Zip</th> <th>Email</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['Last_Name']; echo "</td><td>"; echo $row['First_Name']; echo "</td><td>"; echo $row['Party']; echo "</td><td>"; echo $row['District']; echo "</td><td>"; echo $row['Address']; echo "</td><td>"; echo $row['City']; echo "</td><td>"; echo $row['State']; echo "</td><td>"; echo $row['Zip']; echo "</td><td>"; //Normal Pull //echo $row['Email']; //echo "</td><td>"; //Just Hyperlink //echo '<a href="http://',Email,'">',Email,'</a>'; //echo "</td></tr>"; echo '<a href="http://'.$row['Email'].'">'.$row['Email'].'</a>'; echo "</td></tr>"; } echo "</table>"; ?> The Form: Code: [Select] <?php if($_POST){ $to = 'becca@windfallstudio.com'; $subject = "WHAT SHOULD THIS BE"; $message = "Date: $date\n\r". "Dear $legislator,\n\r". "As a constituent of yours, I urge you to closely review $bill as it pertains to the distribution and allotment of the 4 percent bed tax collected at lodging properties in Montana.\n\r". "Tourism is very important to Montana. Not only it is the second largest industry in Montana, it is also a key economic engine for businesses and the thousands of Montanans that have jobs because of tourism.\n\r". "Nearly 10 million visitors travel to our state each year, contributing between $2.4 billion and $3 billion annually into our economy. In addition to bringing new money into our state, these visitors also help support more than 42,000 Montana jobs and $897 million in worker salaries. (Source: Montana Office of Tourism Annual Report - 2010)\n\r". "Please rest assured that these millions of visitors don't come on their own. They are enticed to come here through marketing and outreach done by various organizations that include the Montana Office of Tourism, Glacier Country Regional Tourism Commission and Missoula Convention and Visitor Bureau.\n\r". "While there is a 7 percent bed tax collected at all lodging entities in the state, 3 percent supports the General Fund and 4 percent supports travel-related partners. The 4 percent is vital to marketing our stage and it is imperative for that money to remain solely dedicated to travel and tourism promotion. I would urge you to vote no on any bill that would direct any portion of that 4 percent elsewhere.\n\r". "Thank you for your consideration in this request and for doing all you can to represent us, your constituents, to the best of your ability. I look forward to hearing from you soon.\n\r". "Sincerely,\n".u "$name \n". "$street \n". "$city, $zip \n". "$email \\n". $headers = "From: $email"; mail($to, $subject, $message, $headers); // SUCCESS! echo '<p class="notice">'. 'Thank you for your submission. '. '</p>'; // clear out the variables for good-housekeeping unset($date,$legislator,$bill,$name,$street,$city,$zip,$email); $_POST = array(); } ?> <div id="content" class="section"> <?php arras_above_content() ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php arras_above_post() ?> <div id="post-<?php the_ID() ?>" <?php arras_single_post_class() ?>> <?php arras_postheader() ?> <div class="entry-content clearfix"> <form method="post" action="" id="letter"> <p><label for="name">Date</label> <input type="text" name="date" id="date" value="<?php echo $_POST['date'];?>"/></p> <p>Dear Senator/Representative <select name="legislator"> <option>Choose a Legislator</option> <option>Senator John Q. Public</option> <option>Rep. Jane Q. Public</option> <option>Some Third Person</option> </select>,</p> <p>As a constituent of yours, I urge you to closely review Bill <select name="bill"> <option>Choose a Bill</option> <option>SB 13 / LC0448</option> <option>LC0505</option> <option>LC0532</option> </select> as it pertains to the distribution and allotment of the 4 percent bed tax collected at lodging properties in Montana.</p> <p>Tourism is very important to Montana. Not only it is the second largest industry in Montana, it is also a key economic engine for businesses and the thousands of Montanans that have jobs because of tourism.</p> <p>Nearly 10 million visitors travel to our state each year, contributing between $2.4 billion and $3 billion annually into our economy. In addition to bringing new money into our state, these visitors also help support more than 42,000 Montana jobs and $897 million in worker salaries. (Source: Montana Office of Tourism Annual Report - 2010)</p> <p>Please rest assured that these millions of visitors don't come on their own. They are enticed to come here through marketing and outreach done by various organizations that include the Montana Office of Tourism, Glacier Country Regional Tourism Commission and Missoula Convention and Visitor Bureau.</p> <p>While there is a 7 percent bed tax collected at all lodging entities in the state, 3 percent supports the General Fund and 4 percent supports travel-related partners. The 4 percent is vital to marketing our stage and it is imperative for that money to remain solely dedicated to travel and tourism promotion. I would urge you to vote no on any bill that would direct any portion of that 4 percent elsewhere.</p> <p>Thank you for your consideration in this request and for doing all you can to represent us, your constituents, to the best of your ability. I look forward to hearing from you soon.</p> <p>Sincerely,<br /> <label for="name">Name:</label> <input type="text" name="name" id="name" value="<?php echo $_POST['name'];?>"/><br /> <label for="email">Street:</label> <input type="text" name="street" id="street" value="<?php echo $_POST['street'];?>"/><br /> <label for="email">City:</label> <input type="text" name="city" id="city" value="<?php echo $_POST['city'];?>"/><br /> <label for="email">Zip:</label> <input type="address" name="zip" id="zip" value="<?php echo $_POST['zip'];?>"/><br /> <label for="email">E-mail:</label> <input type="text" name="email" id="email" value="<?php echo $_POST['email'];?>"/></p> <input type="submit" class="button" value="Submit" /> </form> <?php the_content( __('<p>Read the rest of this entry »</p>', 'arras') ); ?> <?php wp_link_pages(array('before' => __('<p><strong>Pages:</strong> ', 'arras'), 'after' => '</p>', 'next_or_number' => 'number')); ?> </div> What do I need to do to get the Email link from the HTML table to pass to the Email variable in the Form? |