試圖獲取非對象的屬性 (Trying to get property of non-object)


問題描述

試圖獲取非對象的屬性 (Trying to get property of non‑object)

那是什麼劑量???</p>


參考解法

方法 1:

The problem is that you are interrupting your query with additional single quotes.

You have to change the following code

'%'".$searchTerm."'%'

to this:

'%".$searchTerm."%'
  ^             ^ 
 dropped the single quotes here (^)

Maybe mysqli_error() is sometimes useful to recognize this type of errors.

方法 2:

Pulled from my comment and as a complimentary answer to the other given by swidmann's:

If you're looking for specific words, then don't use the LIKE operator, but a simple WHERE col='x' then use num_rows() as you have now will suffice.

If a LIKE isn't needed, don't use it. LIKE is for foot, footing, afoot, bigfoot, etc. when passing foot in the query.

  • It may give you more results than you're really looking to get, depending the use and placement of the % wildcard.

Consult the following on the LIKE operator:

Other reference:


HTML stickler:

  • </br> that should read as <br/> or <br>

If you view the HTML source (in Firefox for example), you will see the following in red:

End tag "br".

The / character is just that; an "end" tag.

I.e.: <p>Text</p> with opening and closing "p" tags.

It's best to have proper HTML and avoiding any notices.

The W3 validator (HTML checker) https://validator.w3.org/nu/#textarea

will return:

Error: End tag br.

From line 11, column 1; to line 11, column 5

llo world↩</br>↩Hi↩</

When using:

<!doctype html>

<head>
<title>test</title>
</head>

<body>

<p>
Hello world
</br>
Hi
</p>

</body>

</html>

(by MrBswidmannFunk Forty Niner)

參考文件

  1. Trying to get property of non‑object (CC BY‑SA 2.5/3.0/4.0)

#mysqli #MySQL #Database #PHP






相關問題

如何第一次創建 mysqli 數據庫? (how can I creates a mysqli database for first the first time?)

使用 jquery autosuggest 從多個表中選擇 (select from multiple tables with jquery autosuggest)

無法連接 - 數據庫或編碼錯誤 (Could Not Connect - Database or Coding Error)

mysqli忽略表中的第一行 (mysqli ignoring the first row in a table)

從數據庫導入的鏈接以 UTF8 截斷 (imported link from database cut off at UTF8)

試圖獲取非對象的屬性 (Trying to get property of non-object)

獲取 php 和 mysqli 中插入數據的 ID (Get Id of inserted data in php and mysqli)

WAMP 和 mysqli::real_connect(): (HY000/2002)? (WAMP and mysqli::real_connect(): (HY000/2002)?)

如何將 MySQLi 準備好的語句的結果放入關聯數組中? (How can I put the results of a MySQLi prepared statement into an associative array?)

測試選擇查詢是否找到結果 (Testing if a Select Query found results)

為什麼我的正確連接嘗試在 apache2 下失敗但在 cli 下失敗? (Why is my correct connection attempt failing under apache2 but not under cli?)

在帶有數組的 IN 語句之後,在 WHERE 語句中使用更多佔位符 (Use more placeholders in WHERE statement after IN statement with arrays)







留言討論