-3

I'm trying to get data out of a mysql db and I have the login info saved in another file. The username is getting sent from my form to the page with the code and i'm getting a

Parse error: syntax error, unexpected '[', expecting ',' or ';' in C:\xampp\htdocs\waladmin\ipfinder.php on line 31.

I don't understand why its saying that though, everything looks fine.

Here's my PHP:

<?php
testinclude('db_login.php');

$con = mysql_connect($db_host,$db_username,$db_password);
//$con = mysql_connect('10.241.10.40','waladmin','waladmin');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$db_select=mysql_select_db($db_database);
if(!db_select)
{
die("Could not select the database. <br />".mysql_error());
}

$select = ' Select ';
$column = ' IP_Address,Workstation,Username ';
$from = ' FROM ';
$tables = ' admintable ';
$where = ' where Username = " & ControlChars.Quote & Username & Username &           ControlChars.Quote & "ORDER BY admintable.Time_Stamp DESC';
$query = $select.$column.$from.$tables.$where;

$result = mysql_query($query);
if(!result)
{
die("Could not query the database:  <br />".mysql_error());
}

while($result_row = mysql_fetch_row(($result))){
echo 'Username:  ' . result_row[2] . ' <br /> ';
echo 'Workstation: ' . result_row[2] . ' <br /> ';
echo 'IP Address:  ' . result_row[1] . ' <br /> ';
}
echo $con;
mysql_close($con)   
echo $con;
?>
hakre
  • 193,403
  • 52
  • 435
  • 836
Intelwalk
  • 671
  • 2
  • 13
  • 31
  • [Reference - What does this error mean in PHP?](http://stackoverflow.com/q/12769982/367456) – hakre Dec 15 '12 at 17:19

3 Answers3

2

change all the result_row[1/2] to $result_row[1/2]

Alon Eitan
  • 11,997
  • 8
  • 49
  • 58
  • 2
    That was it! Brilliant, I can't believe I missed it! – Intelwalk Oct 02 '11 at 06:00
  • Now I get Notice: Use of undefined constant db_select - assumed 'db_select' in C:\xampp\htdocs\waladmin\ipfinder.php on line 12 Notice: Use of undefined constant result - assumed 'result' in C:\xampp\htdocs\waladmin\ipfinder.php on line 25 Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\waladmin\ipfinder.php on line 30 Resource id #4 – Intelwalk Oct 02 '11 at 06:35
  • same thing `if (!db_select)` should be `if (!$db_select)`. and change the line `if(!result)` to `if(!$result)` – Alon Eitan Oct 02 '11 at 06:43
1

You are missing the $ in front of several references to $result_row. Since PHP sees constants, the [ is unexpected.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0

You have problem in last while loop...you missed $ sign and you also missed semicolumn too...

replace this code with respectives..

while($result_row = mysql_fetch_row(($result))){
echo 'Username:  ' . $result_row[2] . ' <br /> ';
echo 'Workstation: ' . $result_row[2] . ' <br /> ';
echo 'IP Address:  ' . $result_row[1] . ' <br /> ';
}
echo $con;
mysql_close($con);
echo $con;   
Rukmi Patel
  • 2,619
  • 9
  • 29
  • 41