PHP - Two Questions. One About Submit Buttons, And One About Drop-down Boxes
Similar TutorialsHello, I have the following function function make_agent_drop($dropname,$parent=''){ $agents = mysql_query("SELECT * FROM ad_category WHERE cat_status='1' AND parent_id='".(is_numeric($parent)?$parent:"0")."'") or die(mysql_error()); $anum = mysql_num_rows($agents); if($anum>0){ $agentdrop='<select style="width:150px; height:20px; margin-left:100px; font-size:11px;" name="'.$dropname.'" id="'.$dropname.'" class="text" '.(is_numeric($parent)?'':'onchange="update_subcatdrop($(this).val());').'"> <option value="0">Select a Category</option>'; while($row= mysql_fetch_array($agents)){ $agentdrop.='<option value="'.$row['cat_id'].'">'.$row['cat_name'].'</option>'; } $agentdrop.='</select>'; }else{ $agentdrop= 'No '.(is_numeric($parent)?'Sub':'').'Categories Found.'; } return $agentdrop; ; } I creates a drop down from database cats and sub cats.. I am trying to figure out how to add a submit button to dynamically appear when it displays the sub category... Thanks! Dan Hey! I have it so users can submit info to my site. They have to check some check boxes and radio buttons. I want them to be able to edit this information, so I want to have the data pulled from the MySQL database and have the correct radio button selected (and the text bolded). So I'm thinking some sort of array to check for each value in the database... but I don't really know. There are a few groups of radio boxes and check boxes but here is an example of one. Code: [Select] <input type="radio" name="stage" value="Stage 1" /> Stage 1 <input type="radio" name="stage" value="Stage 2" /> Stage 2 <input type="radio" name="stage" value="Stage 3" /> Stage 3 The information is pulled from the database like this: Code: [Select] $res=mysql_query("SELECT * FROM ACTIVE WHERE INDEX_ID=$id"); if(mysql_num_rows($res)==0) echo "There is no data in the table <br /> <br />"; else { for($i=0;$i<mysql_num_rows($res);$i++) { $row=mysql_fetch_assoc($res); } } So when I pull information (lets say I want to echo it) it'd look like this: Code: [Select] $row[STAGE] The value for the stage selection can only be Stage 1, Stage 2 or Stage 3 so I need it to be selected when the page loads. Thanks! I was wondering if you can have a form that has different actions depending on what submit button is pressed. I have two button and with one I was to use <form action="<?php echo ( $_SERVER['PHP_SELF'] ); ?>" method="post"> and with the other I want to use <form action="preview.php" method="post"> I was to do this because I want to user to be able to preview their content before submitting. I want the preview page to use the post variables as the value of the input fields so the user doesn't have to input their data again. However because the form doesn't redirect the user to the preview page I have to save all the post variables as session variables. Hi all Im looking to do a "SIMPLE" search on a databse usign php. I want to have a drop down box like so : <select name="Lowest"> <option>0</option> <option>100</option> <option>200</option> </select> this is for the prices i want 2 of these so that the first will be the lowest price and the second will be the higher price Then i will make a query to SELECT * WHERE ( i dont know how to call the results from the select box here to display the whole tabled results ) any help please thnax Hi I have 3 drop down boxes and I want my boxes to go to another page when I select them and click go. For example if I click western cape I want it to give me all the resorts in western cape and if I click western cape and beaches I want it to give me all the resorts that are in the western cape that are next to beaches. I have been able to populate the drop down boxes with information and it can go to another page but it doesn't give me the information I want. This is my drop down boxes code Code: [Select] <script type="text/javascript"> function showGo(){ var region_id = $("#region_id").val(); var lifestyle_id = $("#lifestyle_id").val(); var resort_facility_id = $("#resort_facility_id").val(); if((region_id != 'false') || (lifestyle_id != 'false') || (resort_facility_id != 'false')){ $("#destinationSearchButton").css('display', 'block'); }else{ $("#destinationSearchButton").css('display', 'none'); } </script> <form action="/pages/search/" method="post"> <select class="formSelect" name="region_id" id="region_id" size="1" tabindex="1" onchange="showGo()"> <option label="Region"> <?php $regions_model = new regions_model('regions'); $regions = $regions_model -> get_all(); foreach($regions as $region){ $name = $region['name']; $id =$region['id']; $select = "SELECT $id, $name FROM regions"; echo "<option value='$id'>$name</option>"; } ?> </option> </select> <select class="formSelect" name="lifestyle_id" id="lifestyle_id" size="1" tabindex="2" onchange="showGo()"> <option label="lifestyle"> <?php $lifestyles_model = new lifestyles_model('lifestyles'); $lifestyles = $lifestyles_model -> get_all(); foreach($lifestyles as $lifestyle){ $name = $lifestyle['name']; $id = $lifestyle['id']; $select = "SELECT $name FROM lifestyles"; echo "<option name='$id'>$name</option>"; } ?> </option> </select> <select class="formSelect" name="resort_facility_id" id="resort_facility_id" size="1" tabindex="3" onchange="showGo()"> <option label="Facilities & Amenities"> <?php $resort_facilities_model = new resort_facilities_model('resort_facilities'); $resort_facilities= $resort_facilities_model -> get_all(); foreach($resort_facilities as $resort_facility){ $name = $resort_facility['name']; $id = $resort_facility['id']; $select = "SELECT $name FROM resort_failities"; echo "<option name='$id'>$name</option>"; } ?> </option> </select> <input class="formInputButton" type="submit" name="submitButtonName" id="destinationSearchButton" value="Go" tabindex="4"/ style="display: none;" /> </form> </div> Thank you One submit button goes to my own login system.. the other goes to a billing system. I am having problems getting it to work probably because there are alot of if and else if statements. Or maybe I am just missing something. The problem is the line with blesta.. I take that if isset out and just start with if permission =1 then all is great but I need both of them to operate .. with one being sent to one place and the other to another one. the login file and my form has both input types ready to go within it.. I can declare the values I just need to know what I am doing wrong in the if statement. Code: [Select] <input type="image" name="blesta" id="BtnSubmit" src="images/cart.jpg" width="25" height="20" submit="Blesta"></td> <td><input name="login" type="image" class="vote" src="images/index19.jpg" submit="login"></td> Code: [Select] <? session_start(); $username = $_SESSION["username"]; ?> <html><body> <title>Login</title> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="poptop" height="10"><img src="password/images/spacer.gif" width="3" height="3"><img src="logo.png" border="0"></td> </tr> <tr> <td class="hrz_line"><img src="password/images/spacer.gif" width="1" height="1"></td> </tr> <tr> <td style="background: #ffffff; padding: 5px" valign="middle"><h1 style="margin-top: 0; margin-bottom: 0">Welcome<br><br> Newest User: <font style="FONT-FAMILY: Verdana; FONT- SIZE: 7pt"><?php $connect = mysql_connect("localhost", "username", "pw") or die("Could not connect to database: " . mysql_error()); mysql_select_db("db", $connect) or die("Could not select database"); $query = "SELECT * FROM users ORDER BY created DESC LIMIT 1"; $result = mysql_query($query, $connect) or die ("QUERY FAILED: " . mysql_error()); $row = mysql_fetch_array($result,MYSQL_ASSOC);?> <?echo $row[username]; ?></td></h1></font> </tr> <tr> <td class="hrz_line"><img src="password/images/spacer.gif" width="1" height="1"></td> </tr> <tr> <td valign="top" style="padding: 1em" class="maincontent" height="90"> <META HTTP-EQUIV="expires" CONTENT="0"> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <link rel="stylesheet" type="text/css" href="style.css"> <?php $connect = mysql_connect("localhost", "user", "pw") or die("Could not connect to database: " . mysql_error()); mysql_select_db("db", $connect) or die("Could not select database"); $login = $_POST["username"]; $password = $_POST["password"]; $field = ""; if (isset($_POST["username"]) and isset($_POST ["password"])) { if (is_numeric('$login')) { $field = "user_id"; } else { $field = "username"; } $query = sprintf ("SELECT * FROM users WHERE $field='$login' AND password='".md5 ($password)."'", mysql_real_escape_string($login), mysql_real_escape_string($password)); $result = mysql_query($query, $connect) or die ("QUERY FAILED: " . mysql_error()); if (mysql_num_rows($result) == 0) { if(session_is_registered("LoginFailed")) { if($_SESSION['LoginFailed'] > 3) { $user_query = mysql_query("SELECT * FROM users WHERE username = '$login'") or die("QUERY FAILED: " . mysql_error()); $user = mysql_query($user_query); $hostname = gethostbyaddr($_SERVER ['REMOTE_ADDR']); $password_cypt = md5($password); $date = date("YmdHis"); $IP = getenv("REMOTE_ADDR"); $browser = getenv("HTTP_USER_AGENT"); $handle = fopen("ban.txt", "a+"); //echo "sql: ".$query.""; //echo "Login Failed!"; $access_query = "INSERT INTO hacklog (date, username, hostname, ip_address, browser, refer, password) values ('$date', '$login', '$hostname', '$IP', '$browser', '$refer', '$password')" or die("QUERY FAILED: " . mysql_error()); $access = mysql_query($access_query) or die ("QUERY FAILED: " . mysql_error()); $browser = getenv("HTTP_USER_AGENT"); $hostname = gethostbyaddr($_SERVER ['REMOTE_ADDR']); $date = date("YmdHis"); $rest = substr(getenv('SCRIPT_NAME'), 1, -4); mail("email", "Hack Attack Alert", "Someone Is Attempting To Enter V.I.P\nThe username is: $login\nPassword is: $password\nIP is: $visitorip\nHostname is: $hostname\nBrowser Used is: $browser\nDate: $date\nFile: $rest", "From: email\n"); $browser = getenv("HTTP_USER_AGENT"); $date = date("YmdHis"); $hostname = gethostbyaddr($_SERVER ['REMOTE_ADDR']); $IP = getenv("REMOTE_ADDR"); $handle = fopen("ban.txt", "a+"); $date = date("m-d-Y H:i:s"); $somecontent = $IP.", ".$date. ", ".$browser.", ".$hostname.""; fwrite($handle, $somecontent . " "); fclose($handle); echo "$IP Is Now Banned. Follow Instructions On Next Screen."; print "<META HTTP-EQUIV=\"Refresh\" target= \"info\" Content=\"1; URL=ban.php\">"; exit(); } else { $_SESSION['LoginFailed'] = $_SESSION ['LoginFailed'] + 1; print "<p><strong>Now " . $_SESSION ['LoginFailed'] . " out of 4 Attempts Used</strong></p>\n"; print "<META HTTP-EQUIV=\"Refresh\" Content=\"1; URL=error.php?msg=pass\">"; exit(); } } else { $_SESSION['LoginFailed'] = 1; print "<p><strong>You have used " . $_SESSION ['LoginFailed'] . " out of 4 trys</strong></p> \n"; print "<META HTTP-EQUIV=\"Refresh\" Content=\"1; URL=error.php?msg=pass\">"; exit(); } print "<META HTTP-EQUIV=\"Refresh\" Content=\"1; URL=error.php?msg=pass\">"; exit(); } else { $date = date("YmdHis"); $session = md5($date); $password_cypt = md5($password); $row = mysql_fetch_array($result,MYSQL_ASSOC); $hostname = gethostbyaddr($_SERVER ['REMOTE_ADDR']); $IP = getenv("REMOTE_ADDR"); $browser = getenv("HTTP_USER_AGENT"); $_SESSION["logged"] = "1"; $_SESSION["id"] = $row["user_id"]; $_SESSION["username"] = $row["username"]; $_SESSION["firstname"] = $row["firstname"]; $_SESSION["lastname"] = $row["lastname"]; $_SESSION["email"] = $row["email"]; $_SESSION["created"] = $row["created"]; $_SESSION["last_access"] = $row["last_access"]; $_SESSION["pw"] = $row["pw"]; $_SESSION["permission"] = $row["permission"]; $_SESSION["count"] = $row["count"]; $_SESSION["photo"] = $row["photo"]; $_SESSION["session_id"] = $row["session_id"]; //echo "sql: ".$query."<br>"; //echo "Login success: username: ".$_SESSION ["username"]; //Find Last Access $dd = substr($_SESSION[last_access],6,2); $mm = substr($_SESSION[last_access],4,2); $yyy = substr($_SESSION[last_access],0,4); $HH = substr($_SESSION[last_access],8,2); $MM = substr($_SESSION[last_access],10,2); $SS = substr($_SESSION[last_access],12,2); $access2 = "$mm-$dd-$yyy $HH:$MM:$SS"; $username = $_SESSION["username"]; $access = "$access2"; $login_message = "<p><br> Login Successful.<br><br> [$username] , Last Visited MalenTek On: [$access]<br>Loading Please Wait..<img src=password/images/ajax-loader.gif border=0></p>\n"; if (isset($_POST['blesta']) { print "You are being redirected to your Billing Account"; print "<META HTTP-EQUIV=\"Refresh\" Content= \"10; URL=/cart/u-main.php">"; } else if ($_SESSION[permission] == "1") { $connect = mysql_connect("localhost", "user", "pw") or die("Could not connect to database: " . mysql_error()); mysql_select_db("db", $connect) or die("Could not select database"); mysql_query("UPDATE users SET last_access = $date WHERE username = '$username'")or die("QUERY FAILED: " . mysql_error()); include ("file.php"); print "$login_message"; print "<META HTTP-EQUIV=\"Refresh\" Content=\"10; URL=password/admin.php\">"; } else if ($_SESSION[permission] == "0") { $connect = mysql_connect("localhost", "user", "pw") or die("Could not connect to database: " . mysql_error()); mysql_select_db("db", $connect) or die("Could not select database"); mysql_query("UPDATE users SET last_access = $date WHERE username = '$username'")or die("QUERY FAILED: " . mysql_error()); include ("file.php"); print "$login_message"; print "<META HTTP-EQUIV=\"Refresh\" Content=\"10; URL=members.php/">"; } else if ($_SESSION[permission] == "2") { mysql_query("UPDATE users SET last_access = $date WHERE username = '$username'")or die("QUERY FAILED: " . mysql_error()); include ("ban.php"); print "$login_message"; print "<META HTTP-EQUIV=\"Refresh\" Content=\"10; URL=index.php\">"; } //} } } ?> </td> </tr> <tr> <td class="hrz_line"><img src="images/spacer.gif" width="1" height="1"></td> </tr> <tr> <td height="20" class="popbot"><a href="mailto:email Errors">Report Errors</a></td> </tr> </table> </body> </html> I can't figure out why my $_POST['join'] isn't working. Does my form need to be inside my foreach? Code: [Select] <?php if(is_admin($user_info['uid'], $info['companyid']) === false) { if (isset($_POST['join'])) { echo "works"; die(); } $companies = fetch_company_by_name($info['cname']); ?> <table class="feed pts pbl"> <?php foreach ($companies as $company) { ?> <tr class="mbm"> <td> <form method="post" id="ccreateform" class="man"> <input type="submit" name="join[<?php echo $company['companyid']; ?>]" value="Join" /> </form> </td> </tr> <?php } ?> </table> <?php } ?> I'm new to PHP and attempting to set up my first interactive site that is a basic survey for little kids to take. There's a picture shown to them and two submit buttons below the pic, one reads YES and the other NO to register whether they've participated in the activity before or not. Since the only thing that changes on the page after the selection is made is the photo for the next question/activity, I'd like to be able to use the two buttons to both send their choice to a database (Yes=1 and No=2) and also increment a counter so I can update the picture on the page as they progress through the survey. All the information I've searched/read so far on submit buttons and multiple page surveys doesn't use the actual button itself as data but it's used to submit information gathered elsewhere on the page to another php page for processing via the Action attribute, so I'm wondering if what I want can be done. I'm leaving the Action attribute blank for each button as I want to stay on the same page and attempting to use an incremental counter to update the picture on the page in order to "step" through the survey each time one of the two buttons is clicked, but not having any luck and would appreciate suggestions or points in the right direction on the best way to do this. Apologies in advance if this seems like a basic question, and thanks for any suggestions you can offer. Hey, I'm new to php and I made a webpage that searches a text file and displays a list of courses I've taken depending on what you type into a textbox. I want to change it instead into two drop-down boxes (one for department one for semester) and a all button so that it's neater and to prevent errors. Here is what I have currently: http://codepad.org/nX6g9zh2 Please help! Thank you! I have a shopping cart in the backend there is drop down for navigating through the categories and sub categories, but I'm looking for a better way as I have over 3 thousand categories! and I need a better and faster way to navigate the categories. Any ideas? I think I understand that there can only be one "submit" button on a page.
I want buttons for separate forms to not trigger the empty errors on the other forms...
How do you accomplish specific button actions?
I think I've tried it with javascript but you can do it with PHP right?
Thanks for any help.
So I have created an online test . I have the results from the form submitted to my email. It is working great but the only problem is that when a question is left unanswered, the radio button doesn't have a result. What i want it to do is when a question is left unanswered, the email should look like this (Question) 1_01: True 1_02: Unanswered 1_03: False 1_04: Unanswered 1_05: True Right now it looks like this: (Question) 1_01: True 1_03: False 1_05: True I can't make the radio button required because it is a timed test where you have to work fast, so unanswered questions are going to happen. How do I make it so that unanswered radio buttons submit the value "unanswered" in the E-mail? I'm trying to repopulate a dropdown list when the user hits the submit button to add another item to the dropdown. I'm trying to use the isset method, but am having some issues implementing it properly. Can anyone steer me in the right direction? <html> <head><title>Dynamic List</title></head> <body> <form action="test.php"><select name="list">; <? if (isset($_POST['submit'])){ $file = file("test.txt"); sort($file); foreach($file AS $country){ echo "<option>".$country."</option>\n"; } } ?> </select> </form> please enter your new country:<br> <form action=test.php method="post"> <input type="text" name="name">: enter your country<br> <input type="submit" name="submit"> </form> <? $file = "test.txt"; $tf = @fopen("$file", "a+"); $name = "\n" . $_POST["name"]; $write = fwrite($tf, $name); @fclose($file); ?> </body> </html> I'm simply trying to set up a form where, if when a user clicks 'Submit', and then 'Back', the values from the form are preserved. My question is, how do I preserve the values of drop down menus. The following is a snippet of my code: Code: [Select] <select name="dropdown_dept" id="dept_list"> <option value=0><?php echo "Please select one..."?></option> <?php $dropdown_dept = "select dept_name from departments"; $result_dept = $db_conn->query($dropdown_dept); if (!$result_dept) { echo '<p>Unable to get department data.</p>'; return false; } for($i=0; $i<$result_dept->num_rows; $i++) { $app_name_row = $result_dept -> fetch_array(); ?> <option><?php echo($app_name_row[0]); ?></option> <? } ?> </select> Above is where I have set up a drop down menu of departments. Given that code, how can I preserve the department name after a user clicks 'Submit'? Hi all I am trying to write a piece of code that allows a user to select a country from the drop down menu and them submit it so that it changes the delivery cost in the session. Here's the code for the drop down menu: echo "<form method=\"post\" action=\"basket.php\">"; echo "<select name=\"postal_area_name\" >"; echo "<option value=\"\">--Please Select--</option>"; echo "<option value=\"England\">England</option><option value=\"Scotland\">Scotland</option><option value=\"Wales\">Wales</option>"; echo "</select>"; echo "<input type=\"submit\" name=\"submit_postal_area\" value=\"Go\" class=\"go\">"; echo "</form>"; Then here's my code to grab the delivery change from the form: if(isset($_POST['postal_area_name'])) { $_SESSION['postal_area'] = ($_POST['postal_area_name']); header("Location: basket.php"); exit; } Then this is to set the session price: if(isset($_SESSION['postal_area']) && $_SESSION['postal_area'] == "England") { $set_delivery = "5.95"; } elseif(isset($_SESSION['postal_area']) && $_SESSION['postal_area'] == "Wales") { $set_delivery = "10.00"; } elseif(isset($_SESSION['postal_area']) && $_SESSION['postal_area'] == "Scotland") { $set_delivery = "20.00"; } else { $set_delivery = "5.95"; } $subtotal += $set_price * $qty; $delivery += $set_delivery * $qty; Then I echo out the $delivery in the basket. This doesn't seem to update, it shows the value as being 0 all the time? Please help Thanks Pete Hi all !
I wish to post the value of an auto submit dropdown value to another page, be redirected to that page, and use it on that page. I am unable to achieve this in php and so I tried as :-follows:-
dropdown.php
<form method="post" action = dropdownaction.php> <select name="myselect" onchange="this.form.submit();"> <option>blue</option> <option>red</option> </select> </form>and now I need the equivalent of dropdownaction.php <?php if(isset($_POST(['myselect']))) echo " I am selected".$_POST['myselect']; ?>Please can someone tell me how I may retrieve the value of 'myselect' in the dropdownaction.php after being redirected to it. Thanks loads. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=341998.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=310879.0 Hello all , here is another problem of my project. I need to create a textarea , drop down list and submit button . At first , I can type whatever I want in the textarea , but for certain part I can just choose the word I want from drop down list and click submit , then the word will appear in the textarea as my next word . But I have no idea how to make this works , is there any simple example for this function ? Thanks for any help provided . |