PHP - Help With Submit Buttons
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. Similar TutorialsI'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. 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 } ?> 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 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? Say I have an "Entries" table. I want to submit same multiple entries using a form submission. And If I have other queries submitted in the same form, I want those quarries to be submitted only once. Is that possible to do? Here's my code. if(isset($_POST['submit'])) { $entries = 10; $id = 55; $name = 'Smith'; $insert = $db->prepare("INSERT INTO entries(id, name) VALUES(:id, :name)"); $insert->bindParam(':id', $id); $insert->bindParam(':name', $name); $result_insert = $insert->execute(); if($result_insert == false) { echo 'Fail'; } else { echo 'Success'; } } ?> <form action="" method="post"> <input type="submit" name="submit" value="SUBMIT" /> </form> Edited January 13, 2019 by imgrooot Hi. Pretty straight forward I guess but as the name suggests am a newbie. I have a form that requires the user to enter certain parameters. If the values are blank it submits to itself and loads the error messages. What I want to do is create PHP code that submits the form to a different url. What I thought was create two forms (the second with hidden fields replicating the first form), each form having a different url in the action"" code. What I cant work out is the PHP IF ELSE code to submit form 2 if Form1 is is validated correctly. This is the PHP code relevant to the form validation. Help? <?php //If form was submitted if ($_POST['submitted']==1) { $errormsg = ""; //Initialize errors if ($_POST[width]){ $title = $_POST[width]; //If title was entered } else{ $errormsg = "Please enter width"; } if ($_POST[drop]){ $textentry = $_POST[drop]; //If comment was entered } else{ if ($errormsg){ //If there is already an error, add next error $errormsg = $errormsg . " & content"; }else{ $errormsg = "Please enter drop"; } } } if ($errormsg){ //If any errors display them echo "<div class=\"box red\">$errormsg</div>"; } //If all fields present if ($title && $textentry){ //Do something echo 'THIS IS WHERE I WANT THE CODE TO SUBMIT FORM 2 or SUBMIT FORM 1 TO A DIFFERENT URL'; } ?> the info posts beautifully i just canst seem to get the button to auto click or submit, tried numerous ways! help Code: [Select] <?php require_once "../store/paypal/utility.php"; require_once "../store/paypal/constants.php"; $url = "https://www.".DEFAULT_ENV.".paypal.com/cgi-bin/webscr"; $postFields = "cmd=".urlencode("_notify-synch"). "&tx=".urlencode(htmlspecialchars($_GET["tx"])). "&at=".urlencode(DEFAULT_IDENTITY_TOKEN); $ppResponseAr = Utils::PPHttpPost($url, $postFields, true); if(!$ppResponseAr["status"]) { Utils::PPError($ppResponseAr["error_msg"], $ppResponseAr["error_no"]); exit; } $httpParsedResponseAr = $ppResponseAr["httpParsedResponseAr"]; // assign posted variables to local variables $item_name = $httpParsedResponseAr['item_name']; $item_number = $httpParsedResponseAr['item_number']; $receiver_email = $httpParsedResponseAr['receiver_email']; $receiver_id = $httpParsedResponseAr['receiver_id']; $quantity = $httpParsedResponseAr['quantity']; $first_name = $httpParsedResponseAr['first_name']; $last_name = $httpParsedResponseAr['last_name']; $payer_email = $httpParsedResponseAr['payer_email']; $txn_type = $httpParsedResponseAr['txn_type']; $address_street = $httpParsedResponseAr['address_street']; $address_city = $httpParsedResponseAr['address_city']; $address_state = $httpParsedResponseAr['address_state']; $address_zip = $httpParsedResponseAr['address_zip']; $item_number = $httpParsedResponseAr['item_number']; $option_name1 = $httpParsedResponseAr['option_name1']; $option_selection1 = $httpParsedResponseAr['option_selection1']; $option_name2 = $httpParsedResponseAr['option_name2']; $option_selection2 = $httpParsedResponseAr['option_selection2']; $invoice = $httpParsedResponseAr['invoice']; $custom = $httpParsedResponseAr['custom']; $payer_id =$httpParsedResponseAr['payer_id']; ?> <html lang="en"> <head> <title>Rec</title> <link REL="stylesheet" href="include/style.css" type="text/css"> <!--[if IE]> <link REL="stylesheet" href="include/styleIE.css" type="text/css"> <![endif]--> <style> #center_block {width:50%;margin:0 auto;min-width:500px;} #contents_block {text-align:center;} #header_block {white-space:nowrap;height:25px;padding:0 10px 5px;text-align:center;} #fields_block {width:100%;margin:0;padding:10px} #header_block span {margin:0 5px} #buttons_block {padding:10px 10px 5px} #buttons_block div {padding:3px} #delimiter {margin:2px} #fields_block td {padding:3px 14px} #username_block td {padding-top:13px;white-space:nowrap;} #remember_block td {padding-bottom:13px;white-space:nowrap;} #required_block {text-align:left;padding:5px} </style> <!--[if IE]> <style> #main_block {width:100%} </style> <![endif]--> </head> <body> <script language="JavaScript" src="include/jquery.js"></script> <script language="JavaScript" src="include/jsfunctions.js"></script> <script language="JavaScript" src="include/runnerJS/RunnerBase.js"></script> <form action="rec.php" method="post" id="rec" name="rec.php"> <table id="center_block" align="center"> <tr><td id="contents_block"> <div class="main_table_border2 loginshade" id="main_block"> <table cellpadding=0 cellspacing=0 border=0 id="fields_block" class="loginshade"> <tr id="email_fieldblock"> <td align=left width=50% class=loginshade> <div align="left"><label for="value_email_1">Email:</label></div> </td> <td width=50% class=loginshade> <span id="edit1_email_0" style="white-space: nowrap;"><input id="value_email_1" style="" type="text" name="value_email_1" maxlength=50 value="<?php echo urldecode($httpParsedResponseAr["payer_email"]) ?>"> <font color="red">*</font></span> <div class="error"></div> </td> </tr> <tr id="pass_fieldblock"> <td align=left width=50% class=loginshade> <div align="left"><label for="value_pass_1">Pass:</label></div> </td> <td width=50% class=loginshade> <span id="edit1_pass_0" style=""><input style="" id="value_pass_1" type="Password" name="value_pass_1" maxlength=50 value="1234"> <font color="red">*</font></span> <div class="error"></div> </td> </tr> <tr id="confirm_block"> <td align=left width=50% class=loginshade> <div align="left"><label for="value_confirm_1">Re-enter password:</label></div> </td> <td width=50% class=loginshade> <span id="edit1_confirm_0" style=""><input style="" id="value_confirm_1" type="Password" name="value_confirm_1" value="1234"> <font color="red">*</font></span> <div class="error"></div> </td> </tr> <tr id="fname_fieldblock"> <td align=left width=50% class=loginshade> <div align="left"><label for="value_fname_1">First Name:</label></div> </td> <td width=50% class=loginshade> <span id="edit1_fname_0" style="white-space: nowrap;"><input id="value_fname_1" style="" type="text" name="value_fname_1" maxlength=50 value="<?php echo urldecode($httpParsedResponseAr["first_name"]) ?>"> <font color="red">*</font></span> </td> </tr> <tr id="lname_fieldblock"> <td align=left width=50% class=loginshade> <div align="left"><label for="value_lname_1">Last Name:</label></div> </td> <td width=50% class=loginshade> <span id="edit1_lname_0" style="white-space: nowrap;"><input id="value_lname_1" style="" type="text" name="value_lname_1" maxlength=50 value="<?php echo urldecode($httpParsedResponseAr["last_name"]) ?>"> <font color="red">*</font></span> </td> </tr> <tr id="address_fieldblock"> <td align=left width=50% class=loginshade> <div align="left"><label for="value_address_1">Address:</label></div> </td> <td width=50% class=loginshade> <span id="edit1_address_0" style="white-space: nowrap;"><input id="value_address_1" style="" type="text" name="value_address_1" maxlength=50 value="<?php echo urldecode($httpParsedResponseAr["address_street"]) ?>"> <font color="red">*</font></span> </td> </tr> <tr id="city_fieldblock"> <td align=left width=50% class=loginshade> <div align="left"><label for="value_city_1">City:</label></div> </td> <td width=50% class=loginshade> <span id="edit1_city_0" style="white-space: nowrap;"><input id="value_city_1" style="" type="text" name="value_city_1" maxlength=50 value="<?php echo urldecode($httpParsedResponseAr["address_city"]) ?>"> <font color="red">*</font></span> </td> </tr> <tr id="state_fieldblock"> <td align=left width=50% class=loginshade> <div align="left"><label for="value_state_1">State:</label></div> </td> <td width=50% class=loginshade> <span id="edit1_state_0" style="white-space: nowrap;"><input id="value_state_1" style="" type="text" name="value_state_1" maxlength=50 value="<?php echo urldecode($httpParsedResponseAr["address_state"]) ?>"> <font color="red">*</font></span> </td> </tr> <tr id="zip_fieldblock"> <td align=left width=50% class=loginshade> <div align="left"><label for="value_zip_1">Zip:</label></div> </td> <td width=50% class=loginshade> <span id="edit1_zip_0" style="white-space: nowrap;"><input id="value_zip_1" style="" type="text" name="value_zip_1" maxlength=50 value="<?php echo urldecode($httpParsedResponseAr["address_zip"]) ?>"> <font color="red">*</font></span> </td> </tr> <tr id="cosponsor_fieldblock"> <td align=left width=50% class=loginshade> <div align="left"><label for="value_cosponsor_1">Cosponsor:</label></div> </td> <td width=50% class=loginshade> <span id="edit1_cosponsor_0" style=""><input id="type_cosponsor_1" type="hidden" name="type_cosponsor_1" value="checkbox"><input id="value_cosponsor_1" type="Checkbox" name="value_cosponsor_1" ></span> </td> </tr> <tr id="recipients_fieldblock"> <td align=left width=50% class=loginshade> <div align="left"><label for="value_recipients_1">Recipients:</label></div> </td> <td width=50% class=loginshade> <span id="edit1_recipients_0" style="white-space: nowrap;"><input id="value_recipients_1" style="" type="text" name="value_recipients_1" maxlength=50 value="<?php echo urldecode($httpParsedResponseAr["quantity"]) ?>"> <font color="red">*</font></span> </td> </tr> <tr id="clients_fieldblock"> <td align=left width=50% class=loginshade> <div align="left"><label for="value_clients_1">Clients:</label></div> </td> <td width=50% class=loginshade> <span id="edit1_clients_0" style=""><input id="type_clients_1" type="hidden" name="type_clients_1" value="checkbox"><input id="value_clients_1" type="Checkbox" name="value_clients_1" ></span> </td> </tr> <tr id="space_block"></tr> </table> </div> </td></tr> </table> <input type=submit value="Submit" class=button id="saveButton1" onload="Submit"></form> </body> </html> Hi all, I was just wondering if it possible to execute a php-script when someone presses a button without the page to reload or is this done with javascript. So for instance a calculator. I would be more than pleased to hear and if possible even a short example. All i know is to work with a form method but as far as I know that requires the page to reload. thanks! I'm totally naive to php coding and i'm trying to modify my website which was written for me by someone else in php. So i'm kind of shooting in the dark - but my modification really isn't that difficult... here goes. I already have a form set up allowing the user to select values from drop down menus. To this I want to add a further selection from a choice of 4 radio buttons. This is the coding I've used (i've stripped it down to basics for simplicity) it's inserted between the 'form' tags <input type=radio name="choice" value="FP"> Front Print<br> <input type=radio name="choice" value="BP"> Back Print<br> <input type=radio name="choice" value="PP"> Pocket Print<br> <input type=radio name="choice" value="CP"> Custom Print<br> Ok - this part displays ok and seems to function as expected. The form 'Action' sends the user to another php page so i need to access these values on a different page. This is where I'm running blind. I just want a simple 'if' statement to set a variable based on the value of the radio buttons. So something that looks like this.... if (choice[1].checked=true) {$printchoice = "Front Print";} if (choice[2].checked=true) {$printchoice = "Back Print";} if (choice[3].checked=true) {$printchoice = "Pocket Print";} if (choice[4].checked=true) {$printchoice = "Custom Print";} This part doesn't work - i've tried various combinations but i'm just taking wild guesses. Any help would be much appreciated - thanks I have made a form which includes text fields and radio buttons. The user completes the fields and makes their selections. Once the form is submit, they are then directed to a php file which displays their entries and selections. Atm I can't quite work out how to post their radio button selections. Here is the form: <legend>Car type</legend> <input name="cartype" type="radio" value="1" id="carone" /> <label for="carone">Compact</label><br /> <input name="cartype" type="radio" value="2" id="cartwo" /> <label for="cartwo">Saloon</label><br /> <input name="cartype" type="radio" value="3" id="carthree" /> <label for="carthree">SUV</label> and here is my current code for the text fields: <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $emailaddress = $_POST['emailaddress']; $phone = $_POST['phone']; echo "Dear ". $firstname . " " . $lastname . ",<br />"; echo "Thank you for your order. <br />"; echo "Your contact details a - <br />"; echo "phone: " . $phone . "<br />"; echo "email: " . $emailaddress . "<br />"; ?> </body></html> If anyone could give a hand I'd be very grateful! Hi i'm making a new website based on PHP. I bumped on a problem now... The problem is that I have a loop where i get all records out of my sql database and get them into a form. Every record has a differend form with a button to. Every button then has a unique ID. Now i tried everyting i could think of to get the value out of a button when a button is clicked. But nothing worked... here is the part of the code where everything is for the form and the POST. Code: [Select] while($record = mysql_fetch_object($result)){ $id = $record->id; echo"<form action='home.php' method='post'>"; echo"<b>name:</b>".$record->name." <b>Price: </b>".$record->price.""; echo'<input type="hidden" name="id" value='.$id.'>'; echo"<input type='submit' value='Buy' /><br />"; echo"</form>"; } if($_POST) { $ID = intval($_POST['id']); $query1 = "SELECT price FROM items WHERE id = ".$ID.""; $result1 = mysql_query($query1); list($cost) = mysql_fetch_row($result1); $gold = getStat('gc',$userID); if($gold > $cost) { setStat('gc',$userID,($gold - $cost)); $queryw = "INSERT INTO users_inventory(item_id,user_id, quantity) VALUES ('".$ID."','".$userID."','1')"; $resultw = mysql_query($queryw); } else { echo"You can't afford this weapons."; } } The only thing that doesn't seem to work is this part Code: [Select] $ID = intval($_POST['id']); is always gives me this error: Notice: Undefined index: id in shop.php on line 26 Please help me out here i have no idea what to do from here on... Code: [Select] if ($cartype = 1 ) { echo "Compact <br/>"; } elseif ($cartype == 2 ) { echo "Saloon <br/>"; } else if ($cartype == 3 ) { echo "SUV <br/>"; } This code will only display the first radio button atm. How do I fix this? Hello guys. I am learning PHP little by little and am writing a VERY basic quiz. For functionality in the future I want to be able to change questions and answers in one "included" php doc. The problem i am having with my current code is that I would like to place a variable in the "value" definition on the radio input. I am unable to do this I guess. Any suggestions to accomplish the same thing? Sorry for my horrible code, this is the first thing I have written from scratch. The form page: Code: [Select] <?php include ("test.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <h2><? print $q1; ?></h2> <form method="post" action="test.php"> <input type="radio" name="q1answered" value="Basketball"/> <?php print $q1ans[0]; ?> <input type="radio" name="q1answered" value="Football"/> <?php print $q1ans[1]; ?> <br /><br /> <input type="submit" value="Submit Your Answer!" name="submit" /> </form> </body> </html> The php Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php //Enter all questions below $q1 = "What is your favorite Sport?"; $q2 = "What is your favorite hobby?"; //End Questions //Enter Asnwer choices for each question $q1ans = array("Basketball", "Football"); //End Answers //All question defined variables here to make grading easier $qbank = array ($q1, $q2,); if (isset($_POST["submit"])) { $choice = $_POST["q1answered"]; if ($choice == $q1ans[0]){ print "Your Favorite Sport is $q1ans[0]."; } else { print "Your Favorite Sport is $q1ans[1]."; } } ?> </body> </html> Thanks! I have been at this for far too long and really need some help. I am just trying to check if a radio button has been set or not when someone hits submit. My validation looks something like this: function protect($string){ $string = trim(strip_tags(addslashes($string))); return $string; } if(isset($_POST['submit'])){ //protect and then add the posted data to variables $username = protect($_POST['username']); $password = protect($_POST['password']); $passconf = protect($_POST['passconf']); $email = protect($_POST['email']); $fname = protect($_POST['fname']); $lname = protect($_POST['lname']); $address = protect($_POST['address']); $phone = protect($_POST['phone']); $gender = $_POST['gender']; if(!$username || !$password || !$passconf || !$email || !$fname || !$lname || !$address || !$phone || !isset($gender)){ echo "<p>Please enter all required fields</p>"; }else{ and my form for the radio button is like this... <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <h1>General</h1> <p> <label for="username">Username: </label> <input type="text" name="username" value="<?=$_POST['username'] ?>" /> </p> <p> <label for="password">Password: </label> <input type="password" name="password" value="<?=$_POST['password'] ?>" /> </p> <p> <label for="passconf">Confirm Password: </label> <input type="password" name="passconf" value="<?=$_POST['passconf'] ?>" /> </p> <p> <label for="email">Email: </label> <input type="text" name="email" value="<?=$_POST['email'] ?>" size="25"/> </p> <p> <label for="fname">First Name: </label> <input type="text" name="fname" value="<?=$_POST['fname'] ?>" size="25"/> </p> <p> <label for="lname">Last Name: </label> <input type="text" name="lname" value="<?=$_POST['lname'] ?>" size="25"/> </p> <p> <label for="address">Home Address: </label> <input type="text" name="address" value="<?=$_POST['address'] ?>" /> </p> <p> <label for="phone">Primary Phone Number: </label> <input type="text" name="phone" value="<?=$_POST['phone'] ?>" size="10" /> </p> <p> <label for="genders">Gender: </label> <input type="radio" name"gender" value="male" /> Male <input type="radio" name"gender" value="female" /> Female </p> everytime i hit submit i get this error: "Notice: Undefined index: gender in C:\wamp\www\LoginRegistration\register.php on line 37 Please enter all required fields" can anyone help me please? I'm not sure how to use foreach to send multiple form information to the database. <form> <input id="<?php print $row['id'];?>" name="attendance" type="radio" value="1" checked="checked" /> <input id="<?php print $row['id'];?>" name="attendance" type="radio" value="2" /> <input id="<?php print $row['id'];?>" name="attendance" type="radio" value="3" /> </form> I have a group of 3 buttons for three different options and this is in a php while loop,and there could be anywhere from 1 to 30 of these forms that ineed to send the data to the database at the same time. each one of these groups are next to a user to mark if they were present, tardy, or absent. I need it to get the id of the user for each one of these and send the value to the database as well. Hi Guys, I am writing a web site for a Company. I have two issues the First one is how can or is it possable to check weather a user is logged in and then call on of two functions depending on the outcome. The second one and the more important ones is it possable to call a PHP Function by a user Clicking a Link or a button? If it is possable how would I go about doing this. Each functions build a different section of the site so for Example; The Function 'Data' will bring back a table displaying the Data from a set table, and then the Function 'Data_Input' would display a different page that allows the users to input data to the tables. I don't want these two functions to be dispalying at the sametime but to one Display and then the other and so on for other functions. Hi guys...I need some help in matching data from results of checkboxs and radio buttons. My Intentions: There are 3 radio buttons and 8 check boxes. Users can select any one but cannot don't select at all. I separate the calss and categories because for classes, users can only select 1 option whereas for categories users can select many. For example, User select class 1 but do not select anything else and click submit...the system will then retrieve that he selected and check the data base if he have the pre requisites to allow him to go through. Coding for my form: Code: [Select] <form id="applicationoptions" method="post" action="s_apply_now.php"> <div id="optionshead">Class :</div> <div id="classoptions"> <input type="radio" name="class" value="1" /> Class 1 Permit <input type="radio" name="class" value="2" /> Class 2 Permit <input type="radio" name="class" value="3" /> Class 3 Permit </div> <div id="optionshead2">Categories :</div> <div id="catoptions"> <input type="checkbox" name="cat" value="1" /> CAT 2PG <input type="checkbox" name="cat" value="2" /> CAT 1OR <input type="checkbox" name="cat" value="3" /> CAT 2TT <br/><br/> <input type="checkbox" name="cat" value="4" /> CAT 3PG <input type="checkbox" name="cat" value="5" /> CAT 2OR <input type="checkbox" name="cat" value="6" /> CAT 3TT <br/><br/> <input type="checkbox" name="cat" value="7" /> CAT 4PG <input type="checkbox" name="cat" value="8" /> CAT 3OR </div> <div class="applynext"> <input class="applynextbutton" type="submit" name="applynextbutton" value="PROCEED" /> </div> </form> Lets say if user do not select any class, but select CAT 3PG, system will check if user have the pre-requisites before proceeding to next step. Any one can help me or give me hints?? most importantly is i do not know how to retreieve the values selected from the form. Is it possible to do it using php or must i hunt for javascript's script?? Thanks in advance guys...greatly appreciate. i created 2 buttons and how do i pass value of one i click on so i have yes and no button do i need 2 different forms or 1 with different values? any tip, tutorial or code will help |