PHP - Passing A Variable From A Drop Down In A Form
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']; Similar Tutorials<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 Can someone please tell me what I am doing wrong here? For some reason, the variable doess not seem to be getting passed to the "action" php script this input is in my html form (action=post)... <input type="hidden" name="httpreferer" value="<?php echo $_SERVER['HTTP_REFERER'] ?>" /> this is in the action script... $httpreferer=$_POST['httpreferer']; echo $httpreferer; I have a php string variable that is created by php code within an html form ($answer). I need to pass this string variable along with all the html form input data to another php script specified with the form "action" (post method). All the html form input data is coming thru fine but not the variable ($answer). How do I do this? Here is the php code for importing html form data at the script called in the form action: $languages = $_POST['languages']; $answergiven = $_POST['answergiven']; $problemanswer = $_POST['$answer']; 'languages' and 'answergiven' are form inputs and come thru fine. '$answer' does not get passed to the second script. How do I do this? Here is the php code within the first html form <?php // OPEN DATABASE $username="servics3_sample"; $password="sample"; $database="servics3_sample"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); // GENERATE RANDOM PROBLEM NUMBER $probnum = (rand ( 1 , 9 )); echo $probnum; // RETRIEVE ANTI-SPAM PROBLEM $query="SELECT * FROM liasantispam WHERE `problem number` LIKE '%$probnum%' "; $result=mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); $firstnum=mysql_result($result,0,"first number"); $operator=mysql_result($result,0,"operator"); $secondnum=mysql_result($result,0,"second number"); $answer=mysql_result($result,0,"answer"); echo $firstnum," ",$operator," ",$secondnum," = "; mysql_close(); ?> Hi, can anybody please tell me how i can make "Arson" into a php variable Code: [Select] <script type="text/javascript" src="js/swfobject.js"></script> <script type="text/javascript"> swfobject.embedSWF( "open-flash-chart.swf", "my_chart", "550", "400", "9.0.0", "expressInstall.swf", {"data-file":"ofc-chart.php?crime=Arson"} ); </script> The below script for some reason isn't passing along the product_id variable. Code: [Select] $product_id=$_GET['product']; session_start(); $error=$_SESSION['error']; $content.='<div class="product_information_text review_form"> <div class="review_header">Write a Review for '.$product_name.'</div> <form action="./review_process.php?product='.$product_id.'"> <p class="form_item"><label>Name:</label> <input type="text" name="review_name" size="30" /></p>'; if(isset($error[0])){$content.='<p class="red">This field is required.</p>';} $content.=' <p class="form_item"><label>E-Mail:</label> <input type="text" name="review_email" size="30" /></p> <p class="form_item"><label>Location:</label> <input type="text" name="review_location" size="30" /></p> <p class="form_item"><label>Describe Yourself:</label> <input type="text" name="review_describe" size="30" /></p> <p class="form_item"><label>Review Title:</label> <input type="text" name="review_title" size="30" /></p> <p class="form_item"><label>Best Use of Product:</label> <input type="text" name="review_best_use" size="30" /></p> <p class="form_item"><label>Product Pros:</label> <input type="text" name="review_pros" size="30" /></p> <p class="form_item"><label>Product Cons:</label> <input type="text" name="review_cons" size="30" /></p> <p class="form_item"><label>Product Rating:</label><br /> <div class="rating_radio"><input type="radio" name="review_product_rating" value="1" /> <br />1</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="2" /> <br />2</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="3" checked /> <br />3</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="4" /> <br />4</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="5" /> <br />5</div> <div class="worst">(Worst)</div><div class="best">(Best)</div> </p> <p> </p> <p class="form_item"><label>Comments on Product:</label><br /> <textarea name="review_text" rows="10" cols="60"></textarea> </p> <p><input type="submit" value="Submit" name="Submit" /></p> </form> </div> '; session_unset(); session_destroy(); That code shows the proper product=$product_id value in the form action tag. Code: [Select] $product_id=$_GET['product_id']; $review_name=$_POST['review_name']; $review_name = stripslashes($review_name); $review_name = mysql_real_escape_string($review_name); if($review_name==""){ $error0=1; } else{ $error0=0; } $review_title=$_POST['review_title']; $review_title = stripslashes($review_title); $review_title = mysql_real_escape_string($review_title); if($review_title==""){ $error1=1; } else{ $error1=0; } $review_email=$_POST['review_email']; $review_email = stripslashes($review_email); $review_email = mysql_real_escape_string($review_email); if($review_email==""){ $error2=1; } else{ $error2=0; } $review_location=$_POST['review_location']; $review_location = stripslashes($review_location); $review_location = mysql_real_escape_string($review_location); if($review_location==""){ $error3=1; } else{ $error3=0; } $review_describe=$_POST['review_describe']; $review_describe = stripslashes($review_describe); $review_describe = mysql_real_escape_string($review_describe); if($review_describe==""){ $error4=1; } else{ $error4=0; } $review_best_use=$_POST['review_best_use']; $review_best_use = stripslashes($review_best_use); $review_best_use = mysql_real_escape_string($review_best_use); if($review_best_use==""){ $error5=1; } else{ $error5=0; } $review_pros=$_POST['review_pros']; $review_pros = stripslashes($review_pros); $review_pros = mysql_real_escape_string($review_pros); if($review_pros==""){ $error6=1; } else{ $error6=0; } $review_cons=$_POST['review_cons']; $review_cons = stripslashes($review_cons); $review_cons = mysql_real_escape_string($review_cons); if($review_cons==""){ $error7=1; } else{ $error7=0; } $review_product_rating=$_POST['review_product_rating']; $review_product_rating = stripslashes($review_product_rating); $review_product_rating = mysql_real_escape_string($review_product_rating); $review_text=$_POST['review_text']; $review_text = stripslashes($review_text); $review_text = mysql_real_escape_string($review_text); if($review_text==""){ $error8=1; } else{ $error8=0; } $review_show="n"; date_default_timezone_set('US/Eastern'); $review_date = date("F j, Y, g:i a T"); $error="".$error0."".$error1."".$error2."".$error3."".$error4."".$error5."".$error6."".$error7."".$error8.""; if($error!=="000000000"){ session_start(); $_SESSION['error']=$error; header("Location: ./store.php?product=".$product_id."#review"); } else{ $sql="INSERT INTO $tbl_name3 (product_id, review_show, review_title, review_email, review_name, review_location, review_date, review_describe, review_best_use, review_pros, review_cons, review_product_rating, review_text) VALUES ('$product_id', '$review_show', '$review_title', '$review_email', '$review_name', '$review_location', '$review_date', '$review_describe', '$review_best_use', '$review_pros', '$review_cons', '$review_product_rating', '$review_text')"; mysql_query($sql); echo "Thank You for submitting your review. It should appear on the site within 48 hours."; } The above redirects to store.php?product=#review with no product id. Ideas on why? hello all, I'm new here and I'm learning mysql/php. Currently I have a dynamic table on one of my webpages, and the loop code looks like this:while ($i < $numRows) { $fname = mysql_result($result, $i, "fname"); $fcode = mysql_result($result, $i, "fcode"); $ftype = mysql_result($result, $i, "ftype"); $fdesc = mysql_result($result, $i, "fdesc"); ?> <tr> <td><a href="showfunction.php?fname=<?php echo "$fname"; ?>" target="_self"> <?php echo "$fname"; ?></a></td> <td> <?php echo "$fdesc"; ?> </td> <td><div align="center"> <?php echo "$ftype"; ?> </div></td> </tr> <?php $i++; } ?> what I would like to do is pass the ''fname'' variable to the "showfunction" page so it can printed from the database. Here is the relevant portion of the page:<body><div class="codeblock"> <div class="title">Code:<br /> </div><code><pre> <?php echo $fcode; ?> </pre></code></div> <br /><pre><hr /> </pre> I know that doesn't work, and I didn't expect it to because there is no way to 'get' the 'fname' variable from the preceeding script. I do not want to use the GET method with this because from what I understand, you can only use it with Forms. I really don't want to put controls in all of my table fields just to be able to pass the function name to the next page. Does that make sense? If I could get a jumpstart on this one last hurdle, I would appreciate it. thank you so much! Cheers. I'm an hour worth of searches into this. It's 2:30. I just want some nice person to give me the answer. I'm trying to pass a variable using href to another page. It works great if the variable is only one word. But it only passes the first word. There are multiple posts on this topic, but I can't seem to get any of those fixes to work for me. Here the code. Code: [Select] <?php $query = "select DISTINCT city from daily where open_bid>0 order by city ASC"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $details=''; $details.='<li class="menu"><span class="name"><a href=list.php?city='.$row['city'].'>'.$row['city'].'</a>'; $details.='</li>'; echo($details); } ?> As you can imagine, some cities names are made up of two words. This is only passing the first word. Thanks for your help. Trying to set up an error message when someone tries to upload a file without the approved .ext. I have it working so it won't up load but I am trying to get an error to print out. I was thinking that I could do something like this if the ext are wrong set $errorMsg1 == 1; and then the page will refresh and I would pass that variable to echo out if ($errorMsg1 == 1){ echo "Invalid"; } else { but it isn't passing can anyone help me with this? Tyring to keep it simple this is the code to select an image else{ $result = mysql_query("SELECT * FROM photos WHERE userID LIKE '$clientID'"); while ($r=mysql_fetch_array($result)) { $photo_1=$r['photo_1']; $photo_2=$r['photo_2']; $photo_3=$r['photo_3']; $photo_4=$r['photo_4']; $photo_5=$r['photo_5']; echo " <form enctype='multipart/form-data' action='' method='POST'> <input type='hidden' name='MAX_FILE_SIZE' value='500000' /> <div id='imageTop'>Image &#35;1</div> "; if ($errorMsg1 == 1){ echo "Invalid"; } echo " <div id='imageBottom'> <span class='image'>"; if (empty($photo_1)) { echo " <img src='uploads/noPhoto.gif' width='75' height='75' class='zip'> "; } else { echo "<a href='uploads/$photo_1' ><img src='uploads/$photo_1' width='75' height='75' class='zip'></a> "; } echo " </span> <span class='action'> <input type='file' name='photo_1' class='zip'><br><br> <input type='checkbox' name='delete_1'>Select to Delete image </span> </div> } this is the code of what to do with that image if (isset($_POST['delete_1'])) { $query = "UPDATE photos SET photo_1='' WHERE userID='$clientID'"; $result = mysql_query($query) or die(mysql_error()); echo " <div id='aboutUpdate'><img src='img/loader.gif'> Information is updating</div> "; echo "<meta http-equiv=refresh content=\"0; URL=photos.php\">"; } else if ($one != NULL) { $extension = strrchr($_FILES['photo_1']['name'],'.'); $extension = strtolower($extension); if($extension != '.jpg' && $extension != '.gif' && $extension != '.png' && $extension != '.bmp' ){ $errorMsg1 == 1; echo "<meta http-equiv=refresh content=\"0; URL=photos.php\">"; } else { $photoNumber="_1"; $finalName="$clientID$photoNumber"; $save_path = "uploads/"; $target_path = $save_path . basename( $_FILES['photo_1']['name']); $NewPhotoName = $finalName; $withExt = $NewPhotoName . $extension; $filename = $save_path . $NewPhotoName . $extension; if(move_uploaded_file($_FILES['photo_1']['tmp_name'], $filename)) { $query = "UPDATE photos SET photo_1='$withExt' WHERE userID='$clientID'"; $result = mysql_query($query) or die(mysql_error()); echo " <div id='aboutUpdate'><img src='img/loader.gif'> Information is updating</div> "; echo "<meta http-equiv=refresh content=\"0; URL=photos.php\">"; } } else { This is driving me MAD! The Variable gets passed through the URL but when I try and echo the result I gte NOTHING. First Page. Code: [Select] <?php include'config.php'; $result = mysql_query("SELECT * FROM carbontrust"); while($entry = mysql_fetch_array($result)) Print "$entry[contact] - $entry[company] :: <a href='edit.php?id=$entry[id]'>Edit</a><br>"; exit; ?> Second Page. (Where I want the Variable passed to) Code: [Select] <?php include'config.php'; $id = $_GET['id']; echo "ID: $id"; } ?> Its probably just a stupid error but iv looked through a load of tutorials and this should be correct. :/ How, if possible, can a $varĀ be passed to theĀ forms action php file? I tried everything with no success. Edited December 24, 2019 by cyberRobotRemoved email address Hi, I am trying to pass a variable when posting a form. This is my form with the select: Code: [Select] <form id="form1" name="form1" method="post" action="products_2.php?id_subcategoria= WHAT SOULD I PUT HERE?"> <select name="subcats" class="subcatsSelectMenu" id="subcats" onchange="this.form.submit()"> <option value="">Ver placas por tipos</option> <?php do { ?> <option value="<?php echo $row_subcats_RS['id_subcategoria']?>"><?php echo $row_subcats_RS['subcategoria_esp']?></option> <?php } while ($row_subcats_RS = mysql_fetch_assoc($subcats_RS));$rows = mysql_num_rows($subcats_RS); if($rows > 0) { mysql_data_seek($subcats_RS, 0); $row_subcats_RS = mysql_fetch_assoc($subcats_RS); } ?> </select> </form>How can I pass the variable in the URL? Thanks I had an iframe working for the last few months on a site at hostgator. Yesterday, it quit working (403 permissions error). After a long bout of trouble-shooting, I found out that it has something to do with mod_security that they have suddenly enabled (have no idea as I'm not a Linux guy). They told me they fixed the problem on my domain by whitelisting it as an exception, but strangely, even though the permissions error went away, the actual src= box of the iframe, which was the url variable I was passing in the url, no longer loads. So.. I'm trying to break this down into the simplest form to figure it out. I just understand php basics so needing some verification that I'm doing this right/wrong. Here's my code.. page1.php Code: [Select] <? $testurl = "http://google.com"; ?> <a href="http://mysite.blah/page2.php?url=<? echo $testurl; ?>">page2.php</a> page2.php Code: [Select] if (isset($_GET['testurl'])) echo $testurl; else echo "sorry dude"; I am only able to print "sorry dude". Am I doing something wrong or shouldn't this send the url? Thanks for the help! Please forgive my limited knowledge of php. I am trying to pass a variable from 1 page to the next. I have SCRIPT A (I didn't write it) that parses an rss feed and then calls SCRIPT B to insert it into a database. Everything works great.. and all I'm trying to do is add a new piece of information. In my db, I added a column called 'city'. There are currently 25 different SCRIPT A's (25 different city names). I could create 25 SCRIPT Bs and call them individually, but I'm trying to use 1 SCRIPT B and just send the city name. I've read about POST and GET but still not sure on this? Can't I just hard code my city name into each SCRIPT A like this: Code: [Select] $city = "miami"; And then put this at the top of SCRIPT B? Code: [Select] $city = $_GET['city']; Well.. apparently, I can't because that doesn't work. Again.. sorry for the dumb question. It's my first time attempting anything with php. Thanks. i have two functions. In function two it has $id=9. how do i get function one to echo $id? how do i adjust the below example to accomplish this? Code: [Select] $newdb = new Database(); class Database { function one() { $newdb->two(); echo $id; } function two() { $id = 9 return $id; } } I'm new to php and was wondering how I would be able to do the following: -I have a search page that allows someone to search for a particular user in the database -In the results, I want to have a <a href> link to another page which will run a sql query based on which user's link was clicked and list their posts. So right now I have been trying this code to build that href link: Code: [Select] echo '<td><a href="viewuser.php?username='.urlencode($row['username']).'>View user</a></td>'; However on the following page it is unable to retrieve the 'username' field. Hi Guys, I'm working on an image resizer, to create thumbnails for my page. The resizer works on principle of include a DIRECT link to the image. But what I want to do is put in the PHP Variable in the URL string, so that it points to that file and resizes it accordingly. My code is as follows : Code: [Select] <img src="thumbnail.php?image=<?php echo $row_select_property['image_url']; ?> Image Resize : Code: [Select] <?php // Resize Image To A Thumbnail // The file you are resizing $image = '$_GET[image_url]'; //This will set our output to 45% of the original size $size = 0.45; // This sets it to a .jpg, but you can change this to png or gif header('Content-type: image/jpeg'); // Setting the resize parameters list($width, $height) = getimagesize($image); $modwidth = $width * $size; $modheight = $height * $size; // Creating the Canvas $tn= imagecreatetruecolor($modwidth, $modheight); $source = imagecreatefromjpeg($image); // Resizing our image to fit the canvas imagecopyresized($tn, $source, 0, 0, 0, 0, $modwidth, $modheight, $width, $height); // Outputs a jpg image, you could change this to gif or png if needed imagejpeg($tn); ?> What I am trying to do is pass on the variable "image=<?php echo $row_select_property['image_url']; ?>" to the Thumbnail script. At the moment I am passing it through the URL string, but it doesnt seem to load the graphic. I'll try expand on this more, should you have questions as I am finding it a little difficult to explain. Thanks in advance. Hello, I'm trying to build a small project; and as part of it - I want users to search and when presented with relevant enteries in the SQL database - they should be able to click and retrieve a page dedicated to that entity. The problem I am having is in passing the 'id' of the search result onto the next (description) page. Code: [Select] $SQL = "SELECT * FROM loads"; $result = mysql_query($SQL); while ($db_field = mysql_fetch_assoc($result)) { $clickid = $_GET['id']; print $db_field['id'] ."<a href=\"load_info.php?id=$id" . $id . "\" target=\"_self\" title=\"\">More Info</a>;"; print $db_field['depart:'] . "<BR>"; print $db_field['dest'] . "<BR>"; } I thought it was easy enough to pass the variable like above ("load_info.php?id=$id) and then grab it on the next page like so: $val = $_GET['clickid']; Unfortunately, it doesn't retrieve the info from the page before. If I insert a number in there, it does work correctly, but I really need the ID of the database entry to pass on so as to provide the user with further information. If anyone could help it would be appreciated. L. hey ive got a page that lists a users bank accounts...when the user chooses to update an account it goes to a new page where they can edit the details...when it goes to this new page it takes the user's ID and the account ID with it in the URL (http://localhost/oswp/bank/updateaccounts.php?id=34&cid=1) so i know these variables are correctly being transferred. now when the user has made their changes and clicked the update button it should update the database and then re-locate back to the original page listing all accounts...to get back to this page and show the correct accounts for that user i thaught i needed to take the ID from the URL...give it a variable...and use it in the URL back to the original page. so for example the variable and update sql and re-locate code would look like this. $cid = $_GET['cid']; //updating the table $result=mysql_query("UPDATE accounts SET accno='$accno', pin='$pin', type='$type', name='$balance', balance='$balance', active='$active' WHERE accid=$id"); header("location:accounts.php?id=$cid"); however currently when the user clicks update and it tries to relocate back to the original page its not getting the variable in the URL. (http://localhost/oswp/bank/accounts.php?id=) and im getting the errors: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\uni\oswp\assignment\bank\accounts.php on line 26 's bank accounts Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\uni\oswp\assignment\bank\accounts.php on line 30 basically saying its expected a number up in the URL and its not finding one...but i dont know why...any ideas please its quite urgent. here is the relevant code for this section: Accounts.php: <a href="adminlogout.php">Logout</a><br /> <?php $id = $_GET['id']; if(!isset($_SESSION['myusername'])) { header("location:adminlogin.php"); } $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $db = 'bank'; $conn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($db); $result = mysql_query("SELECT * FROM customer WHERE cusid=$id"); $row2 = mysql_fetch_array($result); echo $row2['name'] . "'s bank accounts" . "<br><br>"; $result2 = mysql_query("SELECT * FROM accounts WHERE cusid=$id"); echo "<form method='post' action='accounts.php?id=$id'>"; while($row = mysql_fetch_array($result2)) { echo "<input type='hidden' value='$row[accid]' name='accid'>" . $row['accno'] . $row['name'] . $row['type'] . $row['balance'] . $row['active'] . "<a href='updateaccount.php?id=$row[accid]&cid=$id'>Update</a>" . "<br>"; } echo "</form>"; ?> updateaccounts.php: $id = $_GET['id']; $cid = $_GET['cid']; if(!isset($_SESSION['myusername'])) { header("location:adminlogin.php"); } $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $db = 'bank'; $conn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($db); if(isset($_POST['update'])) { $accno=$_POST['accno']; $pin=$_POST['pin']; $type=$_POST['type']; $name=$_POST['name']; $balance=$_POST['balance']; $active=$_POST['active']; // checking empty fields //if item field is empty if(empty($accno)) { echo "<font color='red'>account number field is empty.</font><br/>"; } elseif(empty($pin)) { echo "<font color='red'>pin field is empty.</font><br/>"; } elseif(empty($type)) { echo "<font color='red'>account type field is empty.</font><br/>"; } elseif(empty($name)) { echo "<font color='red'>account name field is empty.</font><br/>"; } elseif(empty($balance)) { echo "<font color='red'>balance field is empty.</font><br/>"; } elseif(empty($active)) { echo "<font color='red'>active field is empty.</font><br/>"; } else { //updating the table $result=mysql_query("UPDATE accounts SET accno='$accno', pin='$pin', type='$type', name='$balance', balance='$balance', active='$active' WHERE accid=$id"); header("location:accounts.php?id=$cid"); } } Okay, I have been looking into this for the last 3 hours, and cant find shit. I have a page with a javascript game where the player moves around on a map. They have an X and Y coordinate, but I'm having a problem. The problem is I need to store that info in a database, and I'm having trouble learning AJAX. Heres a little list of things: Play loads the game. A php variable is taken from a database. The player goes to those X and Y coordinates. The player may move around. Once they move, the player is sent to a php page that updates the Database information. The page is refreshed to the game again, where they may then move around some more. The problem is, when the page is changed the values are lost. For some reasons cookies aren't working at all (like just not working for anything, even a completely different file.) I heard something about using $_GET or $_POST, but I dont see how... |