PHP - Cannot Submit On Click Of A Button Using Post Method
Hello
I am working in moodle and its code base is in PHP. I am a novice to moodle as well as PHP and not quite familiar with PHP syntax. Right now I have built a Web page in moodle, and its view.php file I need to implement a fuctionality on click of a button. On click of submit button, I am trying to implement a functionality and I have written the code for that under if(isset($_POST['submit])) { ...my code...} Also while creating the form I have set the attributes as follows: echo "<form method='post' action='" . $_SERVER['PHP_SELF']."?inpopup=". $_GET['inpopup']."&id=" . $_GET['id'] . "'>"; But irrespective of whether or not I click the button, whenevr the page loads for the first time, it perform the code written in IF loop as well. So Am i going wrong in implementing a functionality on click of button in PHP or is it something related to moodle, if anyone knows? Any help or suggestions would be appreciated. As I am stuck with this logic since last three days. Regards Similar TutorialsFolks,
Look at this weird thing. I load the page and get echoed as expected: Did Not REQUEST_METHOD! Then, I click the SUBMIT button and to my astonishment I get echoed: Did Not POST->Submit! Got 2 buttons. Same result whenever clicking any. Why is that ? Check it out:
<?php //include('error_reporting.php'); ini_set('error_reporting',E_ALL);//Same as: error_reporting(E_ALL); ini_set('display_errors','1'); ini_set('display_startup_errors','1'); ?> <form name = "submit" method = "POST" action=""> <label for="domain">Domain:</label> <input type="text" name="domain" id="domain" placeholder="Input Domain"> <br> <label for="domain_email">Domain Email:</label> <input type="email" name="domain_email" id="domain_email" placeholder="Input Domain Email"> <br> <label for="url">Url:</label> <input type="url" name="url" id="url" placeholder="Input Url"> <br> <label for="link_anchor_text">Link Anchor Text:</label> <input type="text" name="link_anchor_text" id="link_anchor_text" placeholder="Input Link Anchor Text"> <br> <textarea rows="10" cols="20">Page Description</textarea> <br> <label for="keywords">Keywords:</label> <input type="text" name="keywords" id="keywords" placeholder="Input Keywords related to Page"> <br> <input type="checkbox" name="alert_visitor_type" id="alert_visitor_type" value="Give Alert: Visitor Type"> </label for="alert_visitor_type">Give Alert: Visitor Type</lablel> <input type="checkbox" name="alert_visitor_potential" id="alert_visitor_potential" value="Give Alert: Potential Visitor"> </label for="alert_visitor_potential">Give Alert: Potential Visitor</lablel> <br> <input type="radio" name="tos_agree" id="tos_agree_yes" value="yes"> <label for="tos_agree_yes">Yes:</label> <input type="radio" name="tos_agree" id="tos_agree_no" value="no"> <label for="tos_agree_no">No:</label> <br> <label for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value="yes">Yes</option> <option value="no">No</option> </select> <br> <button type="submit" value="submit">Submit</button><br> <button type="submit">Submit</button> <br> <input type="reset"> <br> </form> <?php if($_SERVER['REQUEST_METHOD'] === 'POST') { if(isset($_POST['submit'])) { mysqli_report(MYSQLI_REPORT_ALL|MYSQLI_REPORT_STRICT); mysqli_connect("localhost","root","","test"); $conn->set_charset("utf8mb4"); $query = "INSERT into links (domain,domain_email,url,link_anchor_text,page_description,keywords,alert_visitor_type,alert_visitor_potential) VALUES (?,?,?,?,?,?,?,?)"; $stmt = mysqli_stmt_init($conn); if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'ssssssss',$_POST['domain'],$_POST['domain_email'],$_POST['url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keywords'],$_POST['alert_visitor_type'],$_POST['alert_visitor_potential']); if(mysqli_stmt_execute($stmt) === FALSE) { die("Error\" . mysqli_stmt_error()"); } mysqli_stmt_close($stmt); mysqli_close($conn); } else { die("Did not INSERT!"); } } else { die("Did Not POST->Submit!"); } } else { die("Did Not REQUEST_METHOD!"); } ?>
Code: [Select] <?php $db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password if(!$db) die("no db"); if(!mysql_select_db("simple",$db)){ if(!mysql_select_db("regis",$db)){//database name die("No database selected.");}} $message=$_POST['message']; print "<form action='registration.php' method='post'onsubmit='return msg();'>"; print "Your message:<br>"; print "<textarea name='message' cols='40' rows='2'></textarea><br>"; print "<a onClick=\"addSmiley(':)')\"><img src='smile.gif'></a> "; print "<a onClick=\"addSmiley(':(')\"><img src='blush.gif'></a> "; print "<a onClick=\"addSmiley(';)')\"><img src='images/wink.gif'></a> "; print "<input type='submit' name='submit' value='Set Name'></form>"; print "<script language=\"Java Script\" type=\"text/javascript\">\n"; print "function addSmiley(a)\n"; print "{\n"; print "document.form.message.value += a;"; print "document.form.message.focus();\n"; print "}\n"; print "</script>\n"; print "<br><br>"; ?> <script type="text/javascript"> <?php function msg(){ if(isset($_POST['submit'])) //if submit button push has been detected { if(strlen($message)<1) { // print "You did not input a message"; echo"<SCRIPT LANGUAGE='javascript'>alert('You did not input a message')</SCRIPT>"; } else { $message=strip_tags($message); $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP $checkforbanned="SELECT IP from admin where IP='$IP'"; $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS"); if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list { print "You IP is banned from posting."; } else if(strlen($message)>=1) { $message=strip_tags($message); echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('$message')</SCRIPT>"); // die("<meta http-equiv=\"refresh\" content=\"0; url=registration.php\">"); } $message=$_POST['message']; $message=strip_tags($message); /* if($_POST['username'] && $_POST['pass']) { $name = mysql_query("SELECT * FROM Persons"); $thedate = date("U"); //grab date and time of the post $insertmessage="INSERT into mesej (name,IP,postime,message) values('$name','$IP','$thedate','$message')"; mysql_query($insertmessage) or die("Could not insert message"); } */ } } return false; } return true; </script> ?> This is my code in my submit2.php im clicked submit button but if it is empty it should return an javascript alert error but why it directs through registration.php without reading the rules? Hello all,
I am an absolute beginner when it comes to PHP and Javascript but wanted a simple contact form for my website. I used the PHP code from one source and the Javascript validator code from another source and all is working fine except for one very annoying bug: I have to press the Submit button twice in order for the form to send the email. I've found that if the validator is already triggered, however, I only need to press the button once for it to submit. I have scoured the internet for a solution to this problem but am realizing this must be a hangup in the particular code I'm using and I'm just not experienced enough to troubleshoot it.
A little help is greatly appreciated. Thank you for your time.
Here's the client side code (truncated to only show relevant parts):
<html> <head> <script src="js/gen_validatorv4.js" type="text/javascript"></script> </head> <body> <form method="post" action="contact.php" name="contactform"> <div class="row collapse-at-2 half"> <div class="6u"> <input name="name" placeholder="Name" type="text" /> </div> <div class="6u"> <input name="email" placeholder="Email" type="text" /> </div> </div> <div class="row half"> <div class="12u"> <textarea name="message" placeholder="Message"></textarea> </div> </div> <div class="row half"> <div class="12u"> <ul class="actions"> <li><input type="submit" value="Send Message" /></li> <li><input type="reset" value="Clear form" /></li> </ul> </div> </div> </form> <script type="text/javascript"> var myformValidator = new Validator("contactform"); myformValidator.addValidation("name","req", "Please provide your name."); myformValidator.addValidation("email","req", "Please provide your email."); myformValidator.addValidation("message","req", "Please enter your message."); myformValidator.addValidation("email","email", "Please enter a valid email address."); </script> </body> </html> I have posted this problem in the PHP section but someone suggested I take it here because the hangup is likely in the JS. I have tried removing the JS validator with varying results; sometimes the form still requires double-clicking and sometimes it works fine. Please see my original post below:
hi guys i have a problem my mail dosent send if some data is entered in the textbox. if data is there it says page not found. If no data and i say submit it submits the same page and a blank email is sent. the form is used in the middle of the entire page. <form name="enquiry" action="<?php echo get_bloginfo('wpurl') .'/home/' ?>" method="POST" id="enquiry" > <div id="registerrow"> <div id="texttitle">Naam:</div> <input type="text" class="textboxdiv" name="name" id="name"> </div> <div id="registerrow"> <div id="texttitle">Email:</div> <input type="text" class="textboxdiv" name="email" id="email"> </div> <div id="registerrow"> <div id="texttitle">Telefoonnr.:</div> <input type="text" class="textboxdiv" name="phone" id="phone"> </div> <div id="registerrow"> <div id="texttitle">KvK nr.:</div> <input type="text" class="textboxdiv" name="kvknr" id="kvknr"> </div> <input name="Submit" type="submit" id="btnregister" /> </form> <?php include_once('mail_class.php'); require_once('mail_class.php'); if ($_POST['Submit']){ $name = $_POST['name']; $phone = $_POST['phone']; $msga = $_POST['kvknr']; $to = "nrocks@gmail.com"; $subject = "Enquiry for infosites"; $mailmsg = "<table width='772' border='2' cellpadding='0' bordercolor='#0099FF'>"; $mailmsg .= "<tr bgcolor='#0099FF'>"; $mailmsg .= "<td height='34' colspan='2' bgcolor='#91C8FF'><p align='center' style='font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14pt;font-weight: bold;'><strong>Enquiry Form</strong></p></td>"; $mailmsg .= "</tr>"; $mailmsg .= "<tr>"; $mailmsg .= "<td height='38'><span style='font-family: Georgia, 'Times New Roman', Times, serif; font-weight: bold'><strong>Name:</strong></span></td>"; $mailmsg .= "<td height='38' > $name </td>"; $mailmsg .= "</tr>"; $mailmsg .= "<tr>"; $mailmsg .= "<td height='38'><span style='font-family: Georgia, 'Times New Roman', Times, serif; font-weight: bold'><strong>Phone No:</strong></span></td>"; $mailmsg .= "<td height='38' > $phone </td>"; $mailmsg .= "</tr>"; $mailmsg .= "<tr>"; $mailmsg .= "<td height='43'><span style='font-family: Georgia, 'Times New Roman', Times, serif; font-weight: bold'><strong>Enquiry For:</strong></span></td>"; $mailmsg .= "<td height='43'><span style='font-family: Georgia, 'Times New Roman', Times, serif; font-weight: bold'> $enquiry </span></td>"; $mailmsg .= "</tr>"; $mailmsg .= "<tr bgcolor='#0099FF'>"; $mailmsg .="<td height='35' colspan='2' bgcolor='#91C8FF'><p align='center' class='style1'> </p></td>"; $mailmsg .="</tr>"; $mailmsg .="</table>"; $headers = "From: ".$_POST['email']."\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; if (mail($to , $subject , $mailmsg, $headers)) { echo 'Mail Send Succesfully'; } else { echo 'Mail was not send, Try again'; } } ?> </div> thanks hi i need help on posting multiple inputs in a single button...while using mysql_fetch_array here is my codes: <? $re6 = mysql_query('select username from users where course = "BSIT" and yearlevel = "FOURTH"'); ?> <br /> <h1>Post Grade</h1> <h1>IT, Fourth Year</h1> <br />Please fill the following form to send The Grade<br /> <? $n = 0; while($row = mysql_fetch_row($re6)) { echo'<form action="grade_post.php" method="post">'; echo'Recipient<span class="small">(Username)</span><input type="text" value="'.$row['username'].'" readonly="readonly" id="recip" name="recip[' . $n . ']" />'; echo'Subject<input type="text" value="'.htmlentities($otitle, ENT_QUOTES, 'UTF-8').'" id="title" name="title[' . $n . ']" />'; echo'<input type="hidden" value="FOURTH" id="year" name="year[' . $n . ']" />'; echo'<input type="hidden" value="FIRST" id="sem" name="sem[' . $n . ']" />'; echo'Grade<input type="text" id="message" name="message[' . $n . ']" ><br />'; ++$n; } ?> i get all my recipients in every input type, but when i tried to post it in my database not all of them are posted rather only one of them are posted in my database ...what i want to happen is that all of my recipients in every input type will be posted in my database with different ids'...help pls... You would think the answer would be all over the Internet and easy to find, but it’s not. I have searched many times, and in all the multitude of search results I have still never found an adequate usable answer. The MOST you ever find is someone saying how easy it is with PHP, but they don’t tell you how, even when the person they are answering asks them (odd). You can be that one in a billion person who finally answers it for real and helps someone out. I have a simple HTML form with data fields first_name, last_name, email, phone, country, a few hidden inputs, and a single submit button, like so: (Please note: the method is GET, not Post.) <form action="https://MyDomainOnMyServer.com/MyPHPScript.php”> <input type="text" name="first_name" value="" /> <input type="text" name="last_name" value="" /> <input type="text" name="email" value="" /> <input type="text" name="phone" value="" /> <input type="hidden" name="type" value="type123"> <input type="hidden" name="project" value="new123"> <select required name="country"> <option value="">Choose your country</option> <option value="US">United States</option> <option value="CA">Canada</option> <option value="GB">United Kingdom</option> <option value="Many More">Many More Countries</option> </select> <input type="submit" value="Submit Form" /> </form> NOTE: Originally, the form action would have been: action="https://TheirExampleDomainOnTheirRemoteServer.com/TheirRemotePHPScript.php" name="form1234" Upon clicking the single submit button only, what I need to have happen is this: 1. Send me an email to whatever@whatever.tld containing all the form submission data 2. Place the form submission data into a MySQL database having the corresponding data fields 3. Send the form submission contents including the hidden input values to "https://TheirExampleDomainOnTheirRemoteServer.com/TheirRemotePHPScript.php" name="form1234" AS IF that had remained set as the original form action to begin with So basically what I’m trying to obtain is the cleanest possible PHP script that will do those three things, which is essentially what others have asked for over the years in search results I have found, but no one has ever provided it in a clear instance that works. If I can just see such a script, I should be able to see how it works and then do what I need. Thanks. Reply 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 . 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 I am having this error while running my php script using ajax. Everything seems to be fine but I do not know why it is giving this error. Code: [Select] <br /> <b>Notice</b>: Undefined index: amount in <b>C:\wamp\www\...\add_bid.php</b> on line <b>3</b><br /> {"error":"yes","fieldErrors":null} Here is my code here is .php code which contains the form Code: [Select] <?php session_start(); $auctionid = $_POST['auction_id']; include "design/header.php"; include "DB/db.php"; ?> <div class="contents" id="bid_contents"> <?php $q = "SELECT * FROM bids WHERE productid='$auctionid' ORDER BY bidid DESC LIMIT 0,1"; $query = mysql_query($q) or mysql_error(); //echo $q; $row = mysql_fetch_assoc($query) or mysql_error(); $current_bid = $row['current_bid']; $thumbnail = mysql_query("SELECT * FROM products WHERE productid='$auctionid'"); $row_thumb = mysql_fetch_assoc($thumbnail); $thumb = $row_thumb['thumbnail']; $title = $row_thumb['product_title']; ?> <div id="thumb"> <img src='<?php echo $thumb ?>' border='none' /><br /> <?php echo $title."<br />"; echo "<b>Current Bid:</b> Eur ".$current_bid; ?> <form name="bid_form" id="bid_form"> <input type="text" name="amount" size="5" /> <input type="button" name="place_bid_btn" id="bid_btn" value="Place Bid" /> <div id="message"></div> </form> </div><!-- thumb --> </div> <?php include "design/footer.php" ?> here is .js file for ajax Code: [Select] $(function() { $('#bid_btn').click(function() { var url = 'add_bid.php'; var query = $('#bid_form').serialize(); alert(query); $.ajax({ type: 'POST', url: url, query: query, dataType: 'json', success: function(data) { if(data.error == 'no') { $('#message').css('display','none'); } else { $('#message').html(data.fieldErrors).css('display','block'); } } }); }); }); and here is where i get data from previous .php file and the problem seems to be in this page. I guess. Name of this page is add_bid.php Code: [Select] <?php session_start(); $bid = $_POST['amount']; $error = 'yes'; $msg = $bid; $JSON_array = array('error' => $error, 'fieldErrors' => $msg); $JSON_response = json_encode($JSON_array); header('Content-type: application/json'); echo $JSON_response; ?> I am adding jquery library and javascript file in my header.php file so it is fine. Please help Dear All, I am trying to check which button is clicked inside the same php file and from there i will do some coding, I tried to echo some text but not working. PHP: <?php include('dbcon.php'); include('session.php'); $result=mysqli_query($con, "select * from staff where OracleID='$session_id'")or die('Error In Session'); $row=mysqli_fetch_array($result); if (isset($_POST["inside"])){ echo 'inside'; } else{ echo 'outside'; } ?> HTML: <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="form-wrapper"> <center> <form action="home.php" method="POST"> <h3>Welcome: <?php echo $row['StaffName']; ?> </h3> <?php if ($row['ClockedIn'] == True and $row['ClockedOut'] == False) {echo "You already clockedIn today, please clockOut"; echo '<button hidden> type="submit" class="buttonstyle" >Clock Time IN!</button>'; echo '<button type="submit" name = "out" class="buttonstyle">Clock Time OUT!</button>';} ?> <?php if ($row['ClockedOut'] == False and $row['ClockedIn'] == False) {echo '<button type="submit" name = "inside" class="buttonstyle" >Clock Time IN!</button>'; echo '<button type="submit" name = "out" class="buttonstyle" >Clock Time OUT!</button>';} ?> <?php if ($row['ClockedIn'] == True and $row['ClockedOut'] == True) {echo "You already clockedIn and ClockedOut today!"; echo '<button hidden> type="submit" class="buttonstyle" >Clock Time IN!</button>'; echo '<button hidden> type="submit" class="buttonstyle">Clock Time OUT!</button>';} ?> </form> </center> </div> </body> </html> Please help on this please. try to give difference in points Code: [Select] <?php if ($_SERVER['REQUEST_METHOD'] == 'POST'){ $db = mysql_connect("localhost", "*******" , "*****")or die("Error connecting to database: " . mysql_error()); $db_used = mysql_select_db("pskkorg_drp1", $db)or die("Could not select database: " . mysql_error()); $user_name = mysql_real_escape_string($_POST['username'],$db); $query = mysql_query("SELECT * FROM student WHERE Username = '$user_name'",$db) or die(mysql_error()); if(mysql_num_rows($query) == 1){ echo "Login successful, welcome back " . $user_name . ""; }else{ echo "Login unsuccessful, please ensure you are using the correct details"; } }else{ echo "Error"; } ?> take a look at this code, is there anything wrong?... it always come out the error output when i test it. when i enter this url, http://www.pskk.org/LMS/LMSscripts/FirstTimeUser10.php?Username=149090 it come out Error. suppose it will appear Login Successful since the username 149090 exist in the database. //here is the code. For some reason it searches the first time, but the second search loads everything. testing at: mnmotorsports.com // searcha.php <?php require("head.php");?> <table width="800" border="1"><tr><td width="550"></td><td> <form method="post" action="searcha.php?go" id="searchform"> <input type="text" name="name"> <input type="submit" name="submit" value="Search"> </form> </td></tr> <tr><td height ="300"> <?php echo "searching"; // connect to host require("connect.php"); // retrieve data $name = $_POST['name']; echo " any card name matching: <b>'".$name."'</b>"; $query = "SELECT * FROM ".$tname." WHERE name LIKE '%".$name."%'"; $result = mysql_query($query) or die(mysql_error()); $SearchCntr=0; while($row = mysql_fetch_array($result)){ $SearchCntr++; echo "<table border='1' width='500'>"; echo "<tr><td>".$row['edition']." | <a href='#'>".$row['name']."</a> | ".$row['manacost']." | ".$row['price']."</td></tr>"; echo "</table>"; } echo $SearchCntr." SEARCH RESULTS</body></html>"; ?> </td><td></td> </tr> </table> <?php require("footer.php"); ?> Hi there, I wrote a pretty simple html form that inputs data into my database. I've included a truncated version of it, There are a lot more fields. Basically when i hit the submit it processes input.php but after its been successful the page is still at input.php in the browser Is there anyway to take the page back to the page i was using to input data Code: [Select] <form action="insert.php" method="post"> <p>Adornment Name: <br> <input type="text" name="name"> <br> <br> Quality: <br> <select name="quality"> <option value="Other">Other Not Listed</option> <option value="Superior">Superior</option> <option value="Greater">Greater</option> <option value="Lesser">Lesser</option> <option value="Raid">Raid</option> <option value="Faction">Faction</option> </select> </form> Code: [Select] include 'db_connect.php'; $sql="INSERT INTO $db_table (name, quality) VALUES ( '$_POST[name]', '$_POST[quality]')"; if (!mysql_query($sql,$db)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($db) ?> hello, I was wondering if it is possible to get all the data sent by a html form via post/get method and use it somehow. it is difficult to explain what i mean, i don't mean to say how to get data normally i.e.. by using variables for example $data = $_POST['data']; that can only get only one field that is "data". The reason i am looking for this is because i have many forms that will have to use the mail() function, the problem is creating variables for each from then use the mail() function to send it will be time consuming. and the fields are different in different forms. I have noticed the similar technology used by mailmyform . com, they capture the data in any html form posted to their php page and mail it to the given email. i created an array like this while{ $ir = 0; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['id_sub']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['seminar_topic']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['seminar_mark']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['attendance']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['internal_mark']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['external_mark']; $ir++; } echo "<input type='hidden' name='ar_std' id='ar_std' value='$stud' /> </table>" ; and it is able to print in the same page using foreach ($stud as $v1) { echo "$v1\n<br>"; foreach ($v1 as $v2) { echo "$v2\n<br>"; } } and in the next page $ar_stud[]=$_POST["ar_std"]; I'm getting an error PHP Warning: Invalid argument supplied for foreach() in save.php on line 25 PHP Stack trace: Friends I am new to php and i have to submit my coursework in php by 3rd dec, I stuck at one place where i have to upload multiple photo and one can see all the photo he has uploaded and can edit or delete that photo so i have done uploading now i am showing those pics in table by running loop and generating tr and td but now i have two buttons with each row edit and delete now when i clicked on one delete or edit that pic should be delete or give text box to edit description of pic, Please help me how to do that....... From my experience, using Google's sitemap generator to generate a sitemap is not that good. It creates page that you do not want to show up. I am wondering what the best method is for creating a sitemap of a website so that only certain pages of the website show up on Google?
Hi, I'm new to PHP/MySQL and need some help getting my query to work for my selection list: The selection list is built with: <form action='processformmissing.php' method='POST'> <fieldset> <legend>Choose Department</legend> <select name='depart'> <option value=''></option> <?php while ($row = mysqli_fetch_array($result)) { extract($row); echo "<option value='$department'>$department</option>\n"; } ?> </select> <p><input type='submit' value='Select Department' /></p> </fieldset> </form> The data is then sent to: $depart = $_POST['depart']; $deptlike = "%".$depart."%"; echo "<p>$depart</p>"; echo "<p>$deptlike</p>"; $query = "SELECT * FROM lifecerts INNER JOIN employees ON lifecerts.cid = employees.cid WHERE department LIKE '$deptlike' ORDER BY employees.name"; Hitting the submit button from my selection list form seems to be working fine because when I echo my data ($depart and $deptlike) it is giving me the correct value, but the query doesn't give me any results. However, if my post data comes from a text box instead of a selection list, my query works fine. Any thoughts on what I'm doing wrong??? Many thanks! |