0

Hi I am having trouble with this code:

<?php
//init.inc.php file

session_start();

mysql_connect('mysql.host.com', 'username', 'password');
mysql_select_db('DB name');

include('include');

// Get users from table
function fetch_users() {

$result = mysql_query('SELECT 'user_id' AS 'id', 'user_username' AS 'username' FROM profile'); // Error on this line: Parse error: syntax error, unexpected T_STRING on line 14

$users = array();

while ($row = mysql_fetch_assoc($result) !== false) {

     $users[] = $row;
}

return $users();

}

?>

I dont know how to fix this. I would be glad if you helped.

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by phorce
0

Try this:

<?php
//init.inc.php file

session_start();

mysql_connect('mysql.host.com', 'username', 'password') or die(mysql_error());
mysql_select_db('DB name');

include('include'); // whatever your including, meh!

// Get users from table
function fetch_users() {

$query = "SELECT user_id AS id, user_name AS username FROM profile";
$result = mysql_fetch_array($query);

$users = array();



while ($row = mysql_fetch_assoc($result) !== false) {

     $users[] = $row; // you need to specificially identify which row to include, e.g. $row['username'];
}

return $users;

}

?>
0

It now says an error: Parse error: syntax error, unexpected T_STRING on line 15. Here is my code:

<?php
//init.inc.php file

session_start();

// Get users from table
function fetch_users() {

$query = mysql_query('SELECT `user_id` AS `id`, `user_name` AS `username` FROM profile');

$users = array();

while ($row = mysql_fetch_assoc($result) !== false) {

     $users[] = $row; // you need to specificially identify which row to include, e.g. $row['username'];

}
return $users;
}
?>

The YouTube video I watched to get this is here: http://www.youtube.com/watch?v=dsgnKTuQeMw&feature=autoplay&list=SP074EAEF57B0DA2A4&playnext=3

0

Try this:

<?php
//init.inc.php file

session_start();

// Get users from table
function fetch_users() {

$query = mysql_query('SELECT `user_id` AS `id`, `user_name` AS `username` FROM profile');

$users = array();

while(($row = mysql_fetch_assoc($query)) !== false)
{
    $users[] = $row;

}
return $users;
}
?>

I'm an idiot.. Sorry!

Edited by phorce

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.