1

enter image description here

I'm trying to fetch data from hashtag where is #a2 or #ar hashtag but not work with my code

$sql_query = mysqli_query($conn, "SELECT * FROM posts WHERE hashtag=#a2");
0

3 Answers 3

2

try this,

$data = "#a2";
$sql_query = mysqli_query($conn, "SELECT * FROM posts WHERE hashtag LIKE '%$data%'");
Sign up to request clarification or add additional context in comments.

3 Comments

You forgot to remove = after hashtag
should be $data=addslashes("#a2");
If someone sees $data="#a2" and replaces it with $data="#$_GET['tag']" you get sql injection.
1
$sql_query = mysqli_query($conn, "SELECT * FROM posts WHERE hashtag LIKE '%#a2%'");

Comments

0

You can also do it using your method but you just have to enclose #a2 in quotes like

$sql_query = mysqli_query($conn, "SELECT * FROM posts WHERE hashtag='#a2'");

Hope it helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.