PHP - Moved: Ajax Php Triple Dropdown Is Empty.. Not Sure What Error!!!!
This topic has been moved to Ajax Help.
http://www.phpfreaks.com/forums/index.php?topic=328006.0 Similar TutorialsThis topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=331067.0 I have a form with dropdown list that is populated with values from Sql Server table. Now i would like to use this selected item in SQL query. The results of this query should be shown in label or text field. So when a user selects item from dropdown menu, results from SQL query are shown at the same time. I have two dropdown list at the moment in my form. First one gets all values from a column in table in SQL Server. And the second one should get a value from the same table based on a selection in first dropdown list.
When i load ajax.php i get 2 error mesages: This is my code so far. I have tried to do it with this Ajax script. But i can only get first dropdown to work. The second dropdown(sub_machinery) does not show values, when first dropdown item is selected. The second dropdown should show values from databse table with this query( *$machineryID* is first dropdown selected item): SELECT MachineID FROM T013 WHERE Machinery=".$machineryID. Index.php <!doctype html> <?PHP $server = "server"; $options = array( "UID" => "user", "PWD" => "pass", "Database" => "database"); $conn2 = sqlsrv_connect($server, $options); if ($conn2 === false) die("<pre>".print_r(sqlsrv_errors(), true)); echo " "; ?> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <section id="formaT2" class="formaT2 formContent"> <div class="row"> <div class="col-md-2 col-3 row-color remove-mob"></div> <div class="col-md-5 col-9 bg-img" style="padding-left: 0; padding-right: 0;"> <h1>Form</h1> <div class="rest-text"> <div class="contactFrm"> <p class="statusMsg <?php echo !empty($msgClass)?$msgClass:''; ?>"><?php echo $statusMsg; ?></p> <form action="connection.php" method="post"> <div>machinery</div> <select id="machinery"> <option value="0">--Please Select Machinery--</option> <?php // Fetch Department $sql = "SELECT Machinery FROM T013"; $machanery_data = sqlsrv_query($conn2,$sql); while($row = sqlsrv_fetch_array($machanery_data) ){ $id = $row['Id']; $machinery = $row['Machinery']; // Option echo "<option value='".$id."' >".$machinery."</option>"; } ?> </select> <div class="clear"></div> <div>Sub Machinery</div> <select id="sub_machinery"> <option value="0">- Select -</option> </select> <input type="submit" name="submit" id="submit" class="strelka-send" value="Insert"> <div class="clear"> </div> </form> </div> </div> </div> </div> </section> </script> <script type="text/javascript"> $(document).ready(function(){ $("#machinery").change(function(){ var machinery_id = $(this).val(); $.ajax({ url:'ajaxfile.php', type: 'post', data: {machinery:machinery_id}, dataType: 'json', success:function(response){ var len = response.length; $("#sub_machinery").empty(); for( var i = 0; i<len; i++){ var machinery_id = response[i]['machinery_id']; var machinery = response[i]['machinery']; $("#sub_machinery").append("<option value='"+machinery_id+"'>"+machinery+"</option>"); } } }); }); }); </script> </body> </html> Ajaxfile.php <?php $server = "server"; $options = array( "UID" => "user", "PWD" => "pass", "Database" => "database"); $conn2 = sqlsrv_connect($server, $options); if ($conn2 === false) die("<pre>".print_r(sqlsrv_errors(), true)); echo " "; $machineryID = $_POST['machinery']; // department id $sql = "SELECT MachineID FROM T013 WHERE Machinery=".$machineryID; $result = sqlsrv_query($conn2,$sql); $machinery_arr = array(); while( $row = sqlsrv_fetch_array($result) ){ $machinery_id = $row['ID']; $machinery = $row['MachineID']; $machinery_arr[] = array("ID" => $machinery_id, "MachineID" => $machinery); } // encoding array to json format echo json_encode($machinery_arr); ?>Edited May 6, 2019 by davidd What I am trying to do is to submit as POST values to database_write.php, from within the while statement. What is happening is I am getting the second row of data every time I change the primary button.
Currently database_write.php is just doing print_r($_POST), And my array is always the same, no matter which select box I choose from. How can I get the values to be associated with the row I am currently changing? Any help would be great, thanks.
What I have so far:
<table class="table table-bordered table-hover"> <thead> <th>Room Number</th> <th>Primary Caregiver</th> <th>Seconday Caregiver</th> </thead> <tbody class="list"> <?php $sql = 'SELECT alarm_device_id, alarm_description, alarm_device_type, notes FROM alarm_device where notes in (\'MSU\') ORDER BY alarm_description'; $retval = mysql_query( $sql, $con ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } $x=0; while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { $id = $row['alarm_device_id']; $alarm_description = $row['alarm_description']; echo '<form id="msu_form">'; echo "<tr><td>{$row['alarm_description']}</td>"; echo "<td>"; $query2 = "SELECT alert_device_id,alert_description FROM alert_device WHERE notes = 'MSU'"; $result2 = mysql_query($query2) or die("Error in alarm_device select:" . mysql_error()); $count2 = mysql_num_rows($result2); if($count2 > 0) { //echo '<select name='.$x.'>'; echo '<select id="Primary" name="primary" onchange="doAjaxPost(this)">'; while($row2 = mysql_fetch_array($result2)) { echo "<option value=".$row2['alert_device_id'].">".$row2['alert_description']."</option>"; } echo "</select>"; }else { echo "Please update alert device to this area"; } echo "</td>"; echo "<td>"; $query3 = "SELECT alert_device_id,alert_description FROM alert_device WHERE notes = 'MSU2'"; $result3 = mysql_query($query3) or die("Error in alarm_device select:" . mysql_error()); $count3 = mysql_num_rows($result3); if($count3 > 0) { echo '<select id="Secondary" name="secondary">'; while($row3 = mysql_fetch_array($result3)) { echo "<option value=".$row3['alert_device_id'].">".$row3['alert_description']."</option>"; } echo "</select>"; }else { echo "Please update alert device to this area"; } echo "</td>"; $aid = $id + $x; //echo $aid; //$ad = $alarm_description + $x; echo '<input type="hidden" id="ID" name="ID" value="'.$id.'"/>'; //echo '<input type="hidden" id="desc" name="desc" value="'.$ad.'"/>'; //echo '<td>'."<input type='submit' name='btnupdate' value='UPDATE' /></td>"; //echo '<td><input type="button" value="Ajax Request" onClick="doAjaxPost()"></td>'; echo '</form>'; $x = $x+1; } ?> <script> function doAjaxPost() { // get the form values var primary = $('#Primary').val(); var secondary = $('#Secondary').val(); var hidden = $('#ID').val(); //var desc = $(sel).parent().nextAll('#desc').val(); $.ajax({ type: "POST", url: "functions/database_write.php", data: $('#msu_form').serialize(), //data: "Primary="+primary+"&Hidden="+hidden+"&Secondary="+secondary, success: function(resp){ //we have the response alert("'" + resp + "'"); }, error: function(e){ alert('Error: ' + e); } }); } </script> </tr> </tbody> </table> how would I make it so that the option 'Remove (make blank)' would post an empty value? Quote <form action="/new/newrotastaffprocess.php" Method="POST"> <select name="username"> <?php $result = mysql_query("SELECT * FROM members") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { echo "<option value=\"" . htmlentities($row["username"]) . "\">" . htmlentities($row["username"]) . "</option>"; } echo "<option value='empty'>Remove (make blank)</option>"; ?> </select> </div> <div style="position:absolute; top:397px; left:570px;"> <form action="/new/newrotastaffprocess.php" METHOD="POST"> <input type = "hidden" value="<?php echo $wkbeg;?>" name="wkbeg"> <input type = "hidden" value="<?php echo $staffno;?>" name="staffno"> <input type = "submit" value="New!"> </form> As the title say, I can not for the life of me get the "$bank" content to display, no matter HOW much I try... Does anyone see any errors. I am sooooooo wiped out at this! main page <? $body = ' <script type="text/javascript" src="change-content.js"></script> <div id="addSold"> <form action="'.$_SERVER['REQUEST_URI'].'" method="post" name="form" autocomplete="off"> <fieldset id="Vehicle"> <legend>Vehicle</legend> <ul> <li><label for="Year">Year</label>'.$Year.'</li> <li><label for="Make">Make</label>'.$Make.'</li> <li><label for="Model">Model</label>'.$Model.'</li> <li><label for="Trim">Trim</label><input type="text" name="Trim" id="Trim" size="10" value="'.$trim.'" disabled="disabled"></li> </ul> <ul> <li><label for="Mileage">Mileage</label><input type="text" name="Mileage" id="Mileage" size="5" maxlength="6" value="'.$row['mileage'].'"></li> <li><label for="VIN">VIN</label><input type="text" name="VIN" id="VIN" size="23" maxlength="17" value="'.$row['vin'].'" disabled="disabled"></li> <li><label for="Color">Color</label>'.$Exterior.'</li> </ul> </fieldset> <fieldset id="Deal"> <legend>Deal</legend> <ul> <li> <label for="soldDte1">Date</label> <input type="text" name="soldDte1" id="soldDte1" size="1" maxlength="2" onkeyup="return autoTab(this, 2, event)" value="08"> / <input type="text" name="soldDte2" id="soldDte2" size="1" maxlength="2" onkeyup="return autoTab(this, 2, event)" value="30"> / <input type="text" name="soldDte3" id="soldDte3" size="1" maxlength="2" value="'.$year.'"> <a href="#"><img id="date_'.$row[stock].'" src="images/Icons/dateOff.png" onfocus="this.select();lcs(this)" onmouseover="MM_swapImage(\'date_'.$row[stock].'\',\'\',\'images/Icons/dateOn.png\',1)" onmouseout="MM_swapImgRestore()" alt="Choose Date"></a> </li> <li> <label for="salesman">Salesman</label> <select name="salesman" id="salesman"> <option></option> '.$salesmen.' </select> </li> </ul> <ul> <li> <label for="dealType">Deal Type</label> <select name="dealType" class="select-content" onchange="getFile(this.value)"> <option></option> <option value="AL">Auto Loan</option> <option value="Cash">Cash</option> <option value="CAC">Credit Acceptance</option> <option value="IH">In House</option> <option value="SAL">Sensible Auto</option> </select> </li> <li> <label for="tradeDrop">Trade</label> <select name="tradein" id="tradeDrop" onchange="show_hide_trade(this.value);"> <option value="No">No</option> <option value="Yes">Yes</option> </select> </li> </ul> </fieldset> <div id="Bank" class="view">'.$bank.'</div> </form> </div> '; ?> get_Bank.php <? if ($_GET['dealType'] == "AL") { $bank = ' <fieldset id="AL"> <legend>Auto Loan Figures</legend> <ul> <li><label for="price">Price</label><input type="text" name="price" id="price" class="price" size="7" onchange="currency(this)"></li> <li><label for="down">Down</label><input type="text" name="down" id="down" class="price" size="6" onchange="currency(this)"></li> <li><label for="tax">Tax</label><input type="text" name="tax" id="tax" class="price" size="6" onchange="currency(this)"></li> <li><label for="reg">Plates</label><input type="text" name="reg" id="reg" class="price" size="4" onchange="currency(this)"></li> <li><label for="gap">Gap</label><input type="text" name="gap" id="gap" class="price" size="4" onchange="currency(this)"></li> </ul> <ul> <li> <label for="pymtNum">--------------- Payment ---------------</label> <input type="text" name="pymtNum" id="pymtNum" size="3" maxlength="3" onkeyup="return autoTab(this, 3, event)"> @ <input type="text" name="pymtAmnt" id="pymtAmnt" class="price" size="5" onchange="currency(this)"> per <select name="pymtType"> <option value="Weekly" selected="selected">Week</option> <option value="Monthly">Month</option> </select> </li> <li><label for="APR">APR</label><input type="text" name="APR" id="APR" class="rate" size="6" value="19.00"></li> </ul> </fieldset> '; } elseif ($_GET['dealType'] == "CAC") { $bank = ' Credit Acceptance stuff goes here '; } else { $bank = 'You must choose a bank before continuing'; } ?> change-content.js Code: [Select] window.onload = init; // finds all <select> tags will class="select-content" and activates function function init() { var sel = document.getElementsByTagName("select"); for (var i=0; i<sel.length; i++){ if (sel[i].className == "select-content") { sel[i].onchange = getFile; } sel[i].selectedIndex = 0; } } function getFile (url) { var url = "AJAX/get_Bank.php?dealType="+ this.value; if (window.XMLHttpRequest) {xmlhttp=new XMLHttpRequest();} else {xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");} xmlhttp.open("GET",url,false); xmlhttp.send(); // a loop that looks through all <div>s on the page // and then replaces the id with the value and gets that file var divs = document.getElementsByTagName("div"); for (var i=0; i<divs.length; i++) { if(divs[i].id == "bank") { divs[i].id = this.value; divs[i].innerHTML=xmlhttp.responseText; } } } i skipped solving this the other day with an easier way but now i am stuck with this stumble again in another area and i have no way out.... so here it goes, i have an ajax dropdown box...i need to get the value that is selected by the user when it is clicked and then pass this value to a new pop window by appending to its url....any suggestions? Hello forum,
So I've been developing an app mostly in PHP, but am rather afraid of JS. Hope to fix that.
I have an AJAX dropdown using JQuery to search locations. It works great. However, I want to make it similar to what is seen on this site:
http://placefinder.com/
As you can see, the dropdown, when clicked populates a box. Then the user submits the form and the data is used in the application.
I have no clue how to make the form populate with data from the DB (I'm using mySQL) when clicked. So far, I've only been able to make it clickable as a URL (not what I want, obvioiusly!)
Is there a way to do this on a really small, simple script for starters? I'm certain their is, but don't even know where to begin.
Any help appreciated
I have an if (!empty criteria that is not showing up. My luck I probably just have put it in the wrong place, but I'm not sure. I need some help because this is the final point and my brain is fried. This is the code that is having the issue: Code: [Select] // We know both $ncmrsr AND $ncmrsc are blank if (!empty($row['ncmrsr']) && !empty($row['ncmrsc'])) { echo 'Show Text!.<br />';} All this is suppose to do is to "Show Text", nothing fancy, once it shows, I'll change what it says... The script doesn't fail, but it doesn't post. Can someone tell me why this isn't showing up and what I need to do to fix it? It would be so much better if this showed an error, but it doesn't, so I have to ask for help. Thanks in advance. Before you ask, yes the fields are in the database. 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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PDI NCMR - View</title> <link rel="stylesheet" type="text/css" href="../CSS/admin.css" /> </head> <body> <div id="logo"> <img src="../images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <?php require_once('../connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo'<h3 id="NCMR2">Non-Conforming Materials Report (NCMR: ' . $row['NCMR_ID'] . ')</h3>'; echo '<form id="all">'; echo '<fieldset>'; if (!empty($row['Added_By'])) { echo '<div id="ab"><tr><td><span class="b">Added By: </span></td><td>' . $row['Added_By'] . '</td></tr></div>';} if (!empty($row['Added_By_Date'])) { echo '<div id="abd"><tr><td><span class="b">On: </span></td><td>' . $row['Added_By_Date'] . '</td></tr></div>';} echo '<div id="box">'; echo '<div id="box1">'; if (!empty($row['Nexx_Part'])) { echo '<div id="np"><tr><td><span class="b">Nexx Part: </span></td><td>' . $row['Nexx_Part'] . '</td></tr></div>';} if (!empty($row['Nexx_Rev'])) { echo '<div id="nr"><tr><td><span class="b">Nexx Rev: </span></td><td>' . $row['Nexx_Rev'] . '</td></tr></div>';} if (!empty($row['Nexx_Part_Description'])) { echo '<div id="npd"><tr><td><span class="b">Nexx Part Description: </span></td><td>' . $row['Nexx_Part_Description'] . '</td></tr></div>';} if (!empty($row['NCMR_Qty'])) { echo '<div id="ncqt"><tr><td><span class="b">NCMR Qty: </span></td><td>' . $row['NCMR_Qty'] . '</td></tr></div>';} echo '<div id ="JSI">'; if (!empty($row['JO'])) { echo '<div id="JO"><tr><td><span class="b">JO: </span></td><td><br />' . $row['JO'] . '</td></tr></div>';} if (!empty($row['SN'])) { echo '<div id="SN"><tr><td><span class="b">SN: </span></td><td><br />' . $row['SN'] . '</td></tr></div>';} if (!empty($row['INV'])) { echo '<div id="INV"><tr><td><span class="b">INV: </span></td><td><br />' . $row['INV'] . '</td></tr></div>';} echo '</div>'; echo '<div id="box2">'; if (!empty($row['Nexx_Inventory_On_Hand'])) { echo '<div id="nioh"><tr><td><span class="b">Nexx Inventory On Hand: </span></td><td>' . $row['Nexx_Inventory_On_Hand'] . '</td></tr></div>';} if (!empty($row['Nexx_Inventory_Chk'])) { echo '<div id="nic"><tr><td><span class="b">Nexx Inventory Chk: </span></td><td>' . $row['Nexx_Inventory_Chk'] . '</td></tr></div>';} if (!empty($row['Supplier_Name'])) { echo '<div id="sun"><tr><td><span class="b">Supplier Name: </span></td><td>' . $row['Supplier_Name'] . '</td></tr></div>';} if (!empty($row['Supplier_Number'])) { echo '<div id="supn"><tr><td><span class="b">Supplier Number: </span></td><td>' . $row['Supplier_Number'] . '</td></tr></div>';} if (!empty($row['Manufacturer_Part_Number'])) { echo '<div id="mpn"><tr><td><span class="b">Manufacturer Part Number: </span></td><td>' . $row['Manufacturer_Part_Number'] . '</td></tr></div>';} if (!empty($row['Manufacturer_Serial_Number'])) { echo '<div id="msn"><tr><td><span class="b">Manufacturer Serial Number: </span></td><td>' . $row['Manufacturer_Serial_Number'] . '</td></tr></div>';} if (!empty($row['NCMR_ID'])) { echo '<div id="cnno"><tr><td><span class="b">NCMR ID: </span></td><td>' . $row['NCMR_ID'] . '</td></tr></div>';} echo '</div>'; echo '<div id="box3">'; if (!empty($row['Nonconformity'])) { echo '<div id="non"><tr><td><span class="b">Nonconformity: </span></td><td><br />' . $row['Nonconformity'] . '</td></tr></div>';} if (!empty($row['Disposition'])) { echo '<div id="dis"><tr><td><span class="b">Disposition: </span></td><td><br />' . $row['Disposition'] . '</td></tr></div>';} if (!empty($row['Comments'])) { echo '<div id="comm"><tr><td><span class="b">Comments: </span></td><td><br />' . $row['Comments'] . '</td></tr></div>';} if (!empty($row['CommentsAdditional_Details'])) { echo '<div id="comma"><tr><td><span class="b">Comments and/or Additional Details: </span></td><td><br />' . $row['CommentsAdditional_Details'] . '</td></tr></div>';} echo '<div id="poinfo">'; if (!empty($row['PO'])) { echo '<div id="po"><tr><td><span class="b">PO: </span></td><td>' . $row['PO'] . '</td></tr></div>';} if (!empty($row['PO_Date'])) { echo '<div id="pod"><tr><td><span class="b">PO Date: </span></td><td>' . $row['PO_Date'] . '</td></tr></div>';} if (!empty($row['Date_Received'])) { echo '<div id="dri"><tr><td><span class="b">Date Received: </span></td><td>' . $row['Date_Received'] . '</td></tr></div>';} echo '</div>'; echo '</div>'; echo '</fieldset>'; echo '</form>'; echo '</div>'; // We know both $ncmrsr AND $ncmrsc are blank if (!empty($row['ncmrsr']) && !empty($row['ncmrsc'])) { echo 'Show Text!.<br />';} } // End of check for a single row of user results else { echo '<p class="error">Please contact the web administrator, there seems to be an error!</p>'; } mysqli_close($dbc); ?> </body> </html> Trying to validate a form for empty input using empty() but when I introduced it to my code, I get the error... Quote Fatal error: Call to undefined function empty() in /srv/disk1/940225/www/domain.co.cc/contact_db/sanitize.php on line 13 Here is where I introduced it... Code: [Select] $message = $_POST['message']; if( !isset($message) || empty($message) ) { ...What am I doing wrong here? Thanks. I am getting an empty query error on this line Code: [Select] $mysql->query($insert); here is my code Code: [Select] if(isset($_POST['submit'])){ $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $companyName = $_POST['companyName']; $homePhone = $_POST['homePhone']; $cellPhone = $_POST['cellPhone']; $companyPhone = $_POST['companyPhone']; //checking the values are filled //echo $firstName. " " . $lastName . " " . $companyName . " " . $homePhone . " " . $cellPhone . " " . $companyPhone; $insert = $mysql->query("INSERT INTO names('firstName','lastName','companyName'), phone('home','cell','company') values('$firstName','$lastName','$companyName','$homePhone','$cellPhone','$companyPhone'"); $mysql->query($insert); if($insert){ echo "success"; } else { mysql_error(); } } I got a connection to the database, I tested for it. I can't find the problem. this is the error I get Warning: mysqli::query() [mysqli.query]: Empty query in C:\wamp\www\test\formData.php on line 23 which is this line Code: [Select] $mysql->query($insert); That's my first time to see this kind of issue.
The PROD environment: Godaddy, IIS7, PHP5.4.30
The Local environment: Linux, PHP 5.5.X
The framework: CodeIgniter 2.2.0
Process:
I have view have form to update multiple files.
echo form_open_multipart('admin/UploadFiles');The controller will do an initial check, if( isset($_SERVER["CONTENT_LENGTH"]) && ($_SERVER["CONTENT_LENGTH"]>((int)ini_get('post_max_size')*1024*1024))) { $this->session->set_flashdata('upload_error', 'Your file is too big to handle.'); redirect($_SERVER['HTTP_REFERER']); } else { if($_FILES['files']['error'][0] != 0) { $this->session->set_flashdata('upload_error', 'There are no files selected.'); redirect($_SERVER['HTTP_REFERER']); } else { $photo_info = array(); $photo_info = $_FILES['files']; $this->load->model('uploadfile'); $results = $this->uploadfile->UploadImages($photo_info); // My debug echo "<pre>"; print_r($results); echo "</pre>"; // redirect($_SERVER['HTTP_REFERER']); }In my model file, for debug purpose, I only put these lines. Since I have traced the code line one by one, finally found the 500 error happens here. if (!empty($this->CheckFileError($images))) { $results['fail'] = $this->CheckFileError($images); foreach($this->CheckFileError($images) as $err) $error_idx[] = $err['index']; }It happens on empty($this->CheckFileError($images)) //$this->CheckFileError($images) is an arrayIf I just "return $this->CheckFileError($images)", it has no error at all. But If I do the code above, it will give me Internal 500 error. After I change to count($this->CheckFileError($images)) == 0everthing works. All the other logics in the actual model are remain same. I only change this line. It has no problem at all in my local. Only when I run it on my Godaddy IIS share hosting. Initially I thought the temp folder to hold the files is not writable. I even spent whole night to talk to Godaddy guys, but no progress. Even I tried create .user.ini to change the "upload_tmp_dir", it still gave me 500 error. Tonight, I debugged my code lines one by one, tested it in local first, then tested in Godaddy. Finally I found the root cause for my internal 500 error. However, I don't know why empty() will cause this issue. Can anyone explain it? I Googled, but didn't find any userful information. The reason why I use IIS is because I write my most of the services in WCF. Thanks! Edited by TFT2012, 01 October 2014 - 12:33 AM. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=320119.0 How is it possible, in PHP, to display an error message next to a form input text field if a user is attempting to submit a form with empty fields? Moreover, how is it possible to remove the same error message when the user fills in the input field with the required data and/or refreshes the page? I have 2 files that I am working with: application.php and process.php.
application.php mainly has the HTML of the form. I am very new to learning PHP (I started learning it last week) and I have been searching for hours for a clear answer. I have already tried different methods for generating the error message including: using empty(), !isset, $_POST["name"] = "", etc, and have tried using session_start();, $row, echo, print, and other variables to try and display error message on the page, and I have tried using unset();, and = null, to try and remove the error message once the input field has been filled but all to no avail. Either the method I try only half works, or nothing works, and I cannot pinpoint which is the part that is not working. I only have 2 files to work with, and as an example of what I want to do is:
1. If the first name field is empty when the user clicks submit, an error message should appear next to the input. Is this possible with PHP? I'm trying to develop a Joomla plugin for 1.6/1.7 and from what I've read, future versions are supposed to be php E~STRICT compliant. I know that doesn't mean I have to fix this since it is just a notice, but I am curious how one would hide the error. Code: [Select] $task_array = explode('.', JRequest::getVar('task')); # Splits article.save $task = $task_array[1]; #This is line 58 I know it happens because $task_array is empty, but how can i wrap that in something to stop this Notice error? I've tried !empty() but that doesn't work. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=351379.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=325858.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=333348.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=312841.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=323434.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=314117.0 |