-4

There's some error in this piece of code..can someone care to correct me?

$user_list=mysqli_query("SELECT 'id','username', FROM 'users' ");
    while($run_user=mysqli_fetch_array($user_list)){
        $user=$run_user['id'];
        $username=$run_user['username'];
        echo "<p><a href='send.php?user=$user'>$username</a></p>";
        }

From comments made below -

mysqli_query() expects at least 2 parameters, 1 given in D:\wamp\www\2\send.php on line 44

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
mee
  • 7
  • 5

2 Answers2

1

Ummm, see your SELECT query once, it's full of errors like below

  1. don't quote column names and table names else DB engine will think it as string literal rather a column.

  2. there is a extra , before FROM clause in your query.

Correct one should be

SELECT `id`,`username` FROM `users`
Rahul
  • 76,197
  • 13
  • 71
  • 125
  • i jus tried what u told me..still the same – mee Jun 26 '15 at 13:41
  • mysqli_query() expects at least 2 parameters, 1 given in D:\wamp\www\2\send.php on line 44..this is the error – mee Jun 26 '15 at 13:44
  • Hmm, someone downvoted ... not sure why though? Any idea??? – Rahul Jun 26 '15 at 13:48
  • ....was not me. but reason could be that db connection isn't in the answer? who knows if OP even has those setup too. – Funk Forty Niner Jun 26 '15 at 13:48
  • @Fred-ii-, LOL I have no idea about PHP brother ... saw the mistakes in query so answered :) – Rahul Jun 26 '15 at 13:49
  • 2
    however Rahul, the question itself is a real "can of worms". OP is posting all these other error messages and didn't bother reading and understanding tutorials. We are not a school after all ;-) I gave an upvote for the initial question. – Funk Forty Niner Jun 26 '15 at 13:50
  • @Fred-ii-, Yes, indeed it is. I feel like deleting my answer :) – Rahul Jun 26 '15 at 13:53
  • the choice is yours amigo ;-) best to just run away lol – Funk Forty Niner Jun 26 '15 at 13:53
  • @Fred-ii-, you are playing politics with me now ... :). I know that's what you want me to do ... LOL :) nice talking friend. Cheers. – Rahul Jun 26 '15 at 13:54
  • 1
    If I had put in an answer for the question and be faced with all of this, I would have no hesitated to delete my answer. We can't save them all.... *cheers* ;-) – Funk Forty Niner Jun 26 '15 at 13:56
-2

Just replace quotes with backtick also mysqli_query need connection in your first parameter

 $user_list=mysqli_query(PASS_YOUR_CONNECTION_VARIABLE,"SELECT `id`,`username` FROM `users`");
Saty
  • 22,443
  • 7
  • 33
  • 51