{"id":12154,"date":"2022-09-29T21:02:45","date_gmt":"2022-09-29T15:32:45","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/"},"modified":"2022-09-29T21:02:45","modified_gmt":"2022-09-29T15:32:45","slug":"solved-error-when-running-sql-syntax","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/","title":{"rendered":"[Solved] Error when running SQL syntax"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-31601458\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"31601458\" data-parentid=\"31238706\" data-score=\"4\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>The error:<\/p>\n<blockquote>\n<p>Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given <\/p>\n<\/blockquote>\n<p>is almost <em>always<\/em> because you&#8217;ve tried to execute a query and it&#8217;s failed for some reason, but you&#8217;ve continued on blindly anyway.<\/p>\n<p>Upon failure, <code>mysqli_query<\/code> <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/php.net\/manual\/en\/mysqli.query.php\">will return false<\/a> rather than a <code>mysqli_result<\/code> and, if you then attempt to use that boolean <code>false<\/code> value in something like <code>mysqli_num_rows<\/code>, that&#8217;s <em>exactly<\/em> the error you&#8217;ll see.<\/p>\n<p>As a first point, you should <em>always<\/em> check the return value of functions that can fail, that&#8217;s just good practice. Continuing blindly and hoping for the best is not really a way to produce robust code.<\/p>\n<hr>\n<p>Having said that, you then have to move on to <em>why<\/em> the query has failed. A large proportion of SQL problems become obvious if you just <em>print out the query before trying to execute it.<\/em> It looks like you&#8217;ve eventually done this since one of your comments states that your query is:<\/p>\n<pre><code>SELECT * FROM Workhours WHERE AFNumber=\"AF1475\" AND ( NOT LIKE '')\n<\/code><\/pre>\n<p>This is <em>not<\/em> a valid SQL statement, hence the problem. Now, despite the fact it appears to be using a different table name (an earlier edit of your question <em>did<\/em> have a matching table name), it corresponds closely to your <code>$sql3<\/code> variable<sup>1<\/sup>:<\/p>\n<pre><code>$sql3 = \"SELECT * FROM Work WHERE ID='\".$_GET[\"id\"].\"' AND (\".$row['Field'].\" NOT LIKE '\".$_POST[$tempname].\"')\";\n<\/code><\/pre>\n<p>Hence it appears that neither <code>$row['Field']<\/code> nor <code>$_POST[$tempname]<\/code> are actually set to anything.<\/p>\n<p><em>That&#8217;s<\/em> where you need to concentrate your effort, to find out exactly why they <em>aren&#8217;t<\/em> set.<\/p>\n<p>For a start, it seems rather unwise to be using <code>$row[anything]<\/code> <em>after<\/em> the loop processing the rows has finished. It may well be that you need to move that code to <em>within<\/em> the loop to get it working but, without more information and context, that&#8217;s really just conjecture (though educated conjecture).<\/p>\n<hr>\n<p><sup>1<\/sup> If it&#8217;s <em>not<\/em> the right query (I&#8217;ve just noticed it also uses <code>ID<\/code> rather than <code>AFNumber<\/code>), then the problem lies elsewhere other than the code you&#8217;ve shown. However, the method used to find the problem will remain the same: find the problematic query, print it out before execution, then work out why it&#8217;s malformed.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Error when running SQL syntax <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] The error: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given is almost always because you&#8217;ve tried to execute a query and it&#8217;s failed for some reason, but you&#8217;ve continued on blindly anyway. Upon failure, mysqli_query will return false rather than a mysqli_result and, if you then attempt to use that boolean false &#8230; <a title=\"[Solved] Error when running SQL syntax\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/\" aria-label=\"More on [Solved] Error when running SQL syntax\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[340,339,341],"class_list":["post-12154","post","type-post","status-publish","format-standard","hentry","category-solved","tag-mysql","tag-php","tag-sql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Error when running SQL syntax - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Error when running SQL syntax - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] The error: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given is almost always because you&#8217;ve tried to execute a query and it&#8217;s failed for some reason, but you&#8217;ve continued on blindly anyway. Upon failure, mysqli_query will return false rather than a mysqli_result and, if you then attempt to use that boolean false ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-29T15:32:45+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Error when running SQL syntax\",\"datePublished\":\"2022-09-29T15:32:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/\"},\"wordCount\":349,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"mysql\",\"php\",\"sql\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/\",\"name\":\"[Solved] Error when running SQL syntax - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-29T15:32:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Error when running SQL syntax\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Error when running SQL syntax - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Error when running SQL syntax - JassWeb","og_description":"[ad_1] The error: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given is almost always because you&#8217;ve tried to execute a query and it&#8217;s failed for some reason, but you&#8217;ve continued on blindly anyway. Upon failure, mysqli_query will return false rather than a mysqli_result and, if you then attempt to use that boolean false ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/","og_site_name":"JassWeb","article_published_time":"2022-09-29T15:32:45+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Error when running SQL syntax","datePublished":"2022-09-29T15:32:45+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/"},"wordCount":349,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["mysql","php","sql"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/","url":"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/","name":"[Solved] Error when running SQL syntax - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-29T15:32:45+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-error-when-running-sql-syntax\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Error when running SQL syntax"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/12154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=12154"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/12154\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=12154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=12154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=12154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}