PHP - Getting Empty Query Error
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); Similar TutorialsI'm not sure what i have done wrong here... all it says is "Query was empty" <?php SESSION_START(); ?> //some html <?php if($_SESSION['email']){ $mysql = "SELECT id,firstname FROM users WHERE 'id'='".$_SESSION['email']."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ session_destroy(); echo"Please <a href=\"/index.html\">Login</a> or <a href=\"/register.php\">Join Us.</a>"; }else{ $row = mysql_fetch_assoc($res); echo "welcome back, <a href=\"./index.php?act=profile&id=".$row['id']."\">".$row['firstname']."</a>\n"; } }else { echo"Please <a href=\"/index.html\">Login</a> or <a href=\"/register.php\">Join Us.</a>"; } ?> I know the following simple demonstration fails and what to do to rectify it (though with a lot of additional code is necessary), but I don't know why this is the behaviour. It would be great if someone could explain to me why, and what the neatest way of fixing it would be. Code: [Select] +----------+--------------+------+-----+---------+ | Field | Type | Null | Key | Default | +----------+--------------+------+-----+---------+ | Id | int(11) | NO | PRI | NULL | | Name | varchar(45) | YES | | NULL | | Number | int(9) | YES | | NULL | Code: [Select] $name = "Bradley Cooper"; $number = ""; $query = "INSERT INTO table (Id, Name, Number) VALUES (1, '$name', $number)"; mysql_query($query); Because the $number variable is empty, this simple query fails. Logically, one would think that nothing or NULL gets inserted to that field since the MySQL structure rule states that default is NULL, and since nothing is fed to it in the query, I think that it would automatically be NULL since if the column is omitted, that is exactly the value that will be inserted. Enclosing the variable with quotes is not preferable since this field accepts integers. Also, converting the variable to an integer by (int)$number results in a 0, which is not what I want either. Checking if the variable is empty of not, and if it is, assign $number = "''" so that the query would succeed by enclosing the empty string with single quotes. But this creates a lot of unnecessary code (some of my tables are 80 columns wide and the query therefore have equal amount of variables). So to summarise, why is this happening and how do I neatly avoid assigning quotes to the empty strings? In other words, how do I insert nothing when variables that usually contain an integer is on occation empty? Hi, I hope you guys can help me out. I only know basic PHP and also SQL. I haven't tried using connecting database yet. My problem is that I'm trying to INSERT a data into an existing table using access but when it reaches $rs = odbc_exec(); it returns an error that the query was empty. Here is the code: Code: [Select] $conn=odbc_connect('trial','',''); if (!$conn) {exit("Connection Failed: " . $conn);} $sql = "INSERT INTO Data (FirstName, LastName, BusinessName) VALUES ('$fname', '$lname', '$bname')"; $rs=odbc_exec($sql, $conn); $rs = @odbc_exec($conn,$sqlstring); if (!$rs) { echo "An error has occured. Please try again", odbc_errormsg($conn); } else { echo "The record was successfully inserted."; } odbc_close($conn); and here is the error: Quote An error has occured. Please try again[MySQL][ODBC 5.1 Driver][mysqld-5.5.20]Query was empty I really hope you could help me out. Thanks. 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 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> 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. Here is my code: // Start MySQL Query for Records $query = "SELECT codes_update_no_join_1b" . "SET orig_code_1 = new_code_1, orig_code_2 = new_code_2" . "WHERE concat(orig_code_1, orig_code_2) = concat(old_code_1, old_code_2)"; $results = mysql_query($query) or die(mysql_error()); // End MySQL Query for Records This query runs perfectly fine when run direct as SQL in phpMyAdmin, but throws this error when running in my script??? Why is this??? Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= new_code_1, orig_code_2 = new_code_2WHERE concat(orig_code_1, orig_c' at line 1 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=328006.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. Man, I'm having a rough week with questions--if you're following at home. Basically matching a Coach's first and last name to another table, which if matched will yield information about that coach's team. Code: [Select] // or get user by username $current_user = wp_get_current_user(); $current_first = $current_user->user_firstname; $current_last = $current_user->user_lastname; $current_id = $current_user->ID; echo '<div class="contact_form">'; echo $current_first . ' ' . $current_last .' :: '; $query = "SELECT * FROM schools WHERE coachFirst='".$current_first."' AND coachLast='".$current_last."'"; $result = mysql_query ($query); if(!$result) { echo 'There is not a match for your name.'; } else { while($school= mysql_fetch_array($result)) { echo $school['school'] . ' ' . $school['id']; include(ABSPATH ."wp-content/plugins/my-team/form.php"); } echo '</div>'; echo '<div class="roster">'; include(ABSPATH ."wp-content/plugins/my-team/roster.php"); echo '</div>'; } A friend of mine must of changed something on the site while I was asleep last night and now all the site says when you go to it is: Error Database query error Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:\xampp\htdocs\inc\utils.inc.php on line 449 I'm not exactly sure what he did since I can't contact him. Can anyone help me fix this? Hi guys , can someone help me with this code its giving me "query was empty Error" its connecting but...? and please find attached the entire php page for clarity. Thanks . <?php //connect database require_once "connect_to_mysqli.php"; //query the datbase $sqlcommand = "SELECT post_id, title, body From posts ORDER by post_id desc"; $query = mysql_query($sqlCommand) or die (mysql_error()); while($row = mysql_fetch_array($query)) { $title = $row["title"]; echo "<h3>$title</h3>"; } // Free the result set if it is large mysql_free_result($query); // close mysql connection mysql_close(); ?> Hello, i have one little problem and can't pass it. Problem is i need to call new sql query inside another query. Am trying to make accordion which will put result of first query($sql) like title and result of second query($sql2) like list of current item. All time am getting error : Quote Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt, SQL state S1000 in SQLExecDirect in ..... I know reasone is because i use query inside query so am trying to figure is there any way to bypass it or make it work. Example: Code: [Select] $sql="EXECUTE _PROCEDURE1 '".$date."',''.$code."; $rs=odbc_exec($conn,$sql); if (!$rs){exit("Error in SQL");} while (odbc_fetch_row($rs)){ $id_number=odbc_result($rs,"ID"); $name=odbc_result($rs,"NAME"); echo $id_number.' - '.$name; $sql2="EXECUTE _PROCEDURE2 '".$id_number."',''.$name."; $name=odbc_exec($conn,$sql2); while(odbc_fetch_row($popust)){ $detail = odbc_result($sql2,"DETAILS"); $detail2 = odbc_result($sql2,"DETAILS2"); $detail3 = odbc_result($sql2,"DETAILS3"); echo $detail.' - '.$detail2.' - '.$detail3; } } I hope i explained it well. Thanks. Hi all, having a strange problem with my query Its only returning some of my data, and in the format User 1 <br /> <br /> User 2 <br /> <br /> <br /> <br /> Code: [Select] $newmembers = "SELECT * FROM users WHERE linked_user IS NOT NULL ORDER BY datejoined LIMIT 6"; $nmresult = mysql_query($newmembers); while($row = mysql_fetch_array($nmresult)){ echo $row['linked_user']; echo "<br />";} ?> Hi, i'm currently coding a new inbox for my website, but ive got an error which says: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to='NoName' ORDER BY id DESC' at line 1 Im not sure why ive got that as everything seems to be fine :S My Code: $user=$_SESSION['username']; $get_messages = mysql_query("SELECT `id` FROM `inbox` WHERE to='$user' ORDER BY `id` DESC") or die("Error on line 9 - " . mysql_error()); Thanks for any help/advise given. Code: [Select] mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean i get that error with this code: $online_query = $link->simple_query('u_username', 'users', 'u_online=1 AND u_hidden != 1', '0u_username'); while($online_info = $link->fetch_array($online_query)) //THIS LINE THROWS THE ERROR the simple_query function is: function simple_query($fields, $table, $clause, $order) { global $link, $config; if(!empty($clause)) { $clause = "WHERE $clause"; } else { $clause = ''; } if(!empty($order)) { $direction = $order[0]; switch($direction) { case '0': $direction = 'ASC"'; break; case '1': $direction = 'DESC'; break; } $order = substr($order, 1, strlen($order)); $order = "ORDER BY $order $direction"; } $query = mysqli_query($this->link, "SELECT $fields FROM ".TBL_PREFIX."$table $clause $order"); return $query; } when i use a normal query instead of my simple_query function it works fine. it also worked fine before i made the database class. Where am i going wrong?  Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/omerbsh/hallofblogs.com/autoTwit/Library/database.php on line 13 Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/omerbsh/hallofblogs.com/autoTwit/Library/database.php on line 13 Error: The Query:INSERT INTO twitter_profiles VALUES('dfggffg','dgfgfdg','1') What I am looking for is that if any field in a database is empty, the form comes back and puts in the word "empty" into the web page, but not the database. I got this right now, it shows the first part fine, but the second part it doesn't show the "Empty" comment... I don't understand why... as far as I can tell the code is fine... Code: [Select] <?php //Nonconformity, Disposition, Comments and Comments & Additional Details echo '<div id="box3">'; if (!empty($row['Nonconformity']) || !empty($row['Disposition']) || !empty($row['Comments']) || !empty($row['CommentsAdditional_Details'])) { echo '<div id="non"><span class="b">Nonconformity: </span><br />' . $row['Nonconformity'] . '</div>'; echo '<div id="dis"><span class="b">Disposition: </span><br />' . $row['Disposition'] . '</div>'; echo '<div id="comm"><span class="b">Comments: </span><br />' . $row['Comments'] . '</div>'; echo '<div id="comma"><span class="b">Comments and/or Additional Details: </span><br />' . $row['CommentsAdditional_Details'] . '</div>';} else if (empty($row['Nonconformity']) || empty($row['Disposition']) || empty($row['Comments']) || empty($row['CommentsAdditional_Details'])) { echo '<div id="non"><span class="b">Nonconformity: </span><br />Empty</div>'; echo '<div id="dis"><span class="b">Disposition: <br /></span>Empty</div>'; echo '<div id="comm"><span class="b">Comments: <br /></span>Empty</div>'; echo '<div id="comma"><span class="b">Comments and/or Additional Details: </span><br />Empty</div>';} echo '</div>'; ?> |