問題描述
試圖獲取非對象的屬性 (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 MrB、swidmann、Funk Forty Niner)