0

Hi, just wondering where I seem to be going wrong? It looks ok to me, I'm fairly new to php so I'm using tutorials.

I keep getting this error:

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in G:\xampp\htdocs\xampp\Assignment\reports.php on line 60

this is a small college project so I know about it being weak against mysql injection.

should be inserting field names from my table anywhere??

    <!DOCTYPE html>
<html lang="en">
<head>
<title> Exercise 3</title>
<meta charset="utf-8">
</head>
<body>
<?php
    $name = “Frank”;
    $age = “28”;
    var_dump($name);
    echo "<br>";
    print_r($name);
    echo "<br>";
    var_dump($age);
    echo "<br>";
?>
</body>
</html>
Christian Giupponi
  • 7,108
  • 10
  • 61
  • 106
proJ
  • 9
  • 3
  • You're using a bunch of deprecated functions, guaranteeing you're learning exactly the wrong things. Read the big red warning at the top of the documentation: http://www.php.net/mysql_query. The stuff you're learning now is actively being removed from the language. Drop this stuff and learn PDO instead. – user229044 Dec 05 '13 at 05:29
  • use mysql_error() to check for the errors like mysql_connect("localhost","admin","admin") or die(mysql_error());//database connection mysql_select_db("employee") or die("selection failed"); $order = "SELECT * FROM employees ORDER BY name"; $userdata = mysql_query($order) or die("query not executed"); – R R Dec 05 '13 at 05:30
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – h2ooooooo Dec 06 '13 at 15:40

1 Answers1

1

Check your return values.

mysql_query:

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

$userdata = mysql_query($order); has returned a boolean false, indicating an error occurred. You've then invoked mysql_fetch_row and passed that boolean false in, hence your error.

user229044
  • 222,134
  • 40
  • 319
  • 330
  • i know an error occurred but im wondering if people with greater php/mysql knowledge could help a girl out here? – proJ Dec 05 '13 at 05:27
  • better explanation +1 – R R Dec 05 '13 at 05:27
  • You've missed the point. The error you're seeing is because you failed to handle an earlier error, and passed a bad value into a function. – user229044 Dec 05 '13 at 05:28
  • @RishabhRaj It's the same explanation I had before, just more long-winded. Guess you don't like succinct answers. – user229044 Dec 05 '13 at 05:30
  • @meagar as i knew the OP is new to PHP coding so i thought she would like a detailed explanation. – R R Dec 05 '13 at 05:32