Jump to content

Help needed with this script


sbo

Recommended Posts

Hi,

Yesterday morning i decided to install an opensource program to manage my personal library.

It is called Distributed Library Project; it appears to be no longer maintained.

Anyway, it fills all my needs and this is all that matters to me.

I made a fisrt install on a non conected computer under Ubuntu with SQL, PHP, etc. : everything worked fine.

But with the program installed online, i always get an error message.

Part of the script :

function Book($id) {
$this->id = $id;
$db = database_connect();
$sql =
"SELECT holder.username AS holder, holder.feedback AS holderFeedback, " .
"u.username, u.address, u.apartment, u.feedback, u.zipcode, " .
"l.status, l.current_holder, l.date_back, " .
"l.authorfirst, l.authorlast, l.title, l.review, l.section " .
"FROM dlp_library l, dlp_user u " .
"LEFT JOIN dlp_user holder ON (l.current_holder = holder.id) " .
"WHERE l.id = '$id' AND l.user_id = u.id";

$result = mysql_query($sql, $db);
if ($row = mysql_fetch_array($result)) {
$this->owner = safeHTML($row["username"]);
$this->address = safeHTML($row["address"]);
$this->apartment = safeHTML($row["apartment"]);
$this->feedback = safeHTML($row["feedback"]);
$this->zipcode = safeHTML($row["zipcode"]);
$this->status = safeHTML($row["status"]);
$this->current_holder = safeHTML($row["current_holder"]);
$this->date_back = safeHTML($row["date_back"]);
$this->authorfirst = safeHTML($row["authorfirst"]);
$this->authorlast = safeHTML($row["authorlast"]);
$this->title = safeHTML($row["title"]);
$this->review = safeHTML($row["review"]);
$this->section = safeHTML($row["section"]);
$this->holder = safeHTML($row["holder"]);
$this->feedback = safeHTML($row["feedback"]);
}
}

error line (37) :
if ($row = mysql_fetch_array($result)) {

error on the page :

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home.10.4/xxx/www/biblio/include/Book.inc on line 37

Help is greatly needed !!

Thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/31694-help-needed-with-this-script/
Share on other sites

It tells you the problem
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
What does this mean? Well, your $result variable is not a valid resource.
I think your connection: $db = database_connect(); is failing.

Also, there's a forum for third party stuff :http://www.phpfreaks.com/forums/index.php/board,34.0.html

:)
Then you need to think a bit more...you're getting very descriptive errors and ignoring them.
It says there is an unknown column. Look at your sql. Does dlp_library have a column called current_holder?

I don't know JOINS very well, you should read up on them to make sure your query is right. The problem is in your SQL.
I have already checked the column 'current_holder' of course.

Messages are very descriptive but they do not reveale the real problem.

Ok, i think i have a problem with the version of PHP, or syntax, or i don't know ...

This script works fine under PHP4 with the same database ...
also u need to fill in ur username password and database names in database_connect

[code]function Book($id) {
$this->id = $id;
$db = database_connect(username,password,database);
$sql =
"SELECT holder.username AS holder, holder.feedback AS holderFeedback, " .
"u.username, u.address, u.apartment, u.feedback, u.zipcode, " .
"l.status, l.current_holder, l.date_back, " .
"l.authorfirst, l.authorlast, l.title, l.review, l.section " .
"FROM dlp_library l, dlp_user u " .
"LEFT JOIN dlp_user holder ON (l.current_holder = holder.id) " .
"WHERE l.id = '$id' AND l.user_id = u.id";

$result = mysql_query($sql, $db);
if ($row = mysql_fetch_array($result)) {
$this->owner = safeHTML($row["username"]);
$this->address = safeHTML($row["address"]);
$this->apartment = safeHTML($row["apartment"]);
$this->feedback = safeHTML($row["feedback"]);
$this->zipcode = safeHTML($row["zipcode"]);
$this->status = safeHTML($row["status"]);
$this->current_holder = safeHTML($row["current_holder"]);
$this->date_back = safeHTML($row["date_back"]);
$this->authorfirst = safeHTML($row["authorfirst"]);
$this->authorlast = safeHTML($row["authorlast"]);
$this->title = safeHTML($row["title"]);
$this->review = safeHTML($row["review"]);
$this->section = safeHTML($row["section"]);
$this->holder = safeHTML($row["holder"]);
$this->feedback = safeHTML($row["feedback"]);
}
}

line (37) :
while($row = mysql_fetch_array($result)) {[/code]
I finally found the solution :
http://www.oscommerce-fr.info/faq/qa_info.php?qID=198

This is the modified script :

  function Book($id) {
    $this->id = $id;
    $db      = database_connect();
    $sql      =
      "SELECT holder.username AS holder, holder.feedback AS holderFeedback, " .
      "u.username, u.address, u.apartment, u.feedback, u.zipcode, " .
      "l.status, l.current_holder, l.date_back, " .
      "l.authorfirst, l.authorlast, l.title, l.review, l.section " .
      "FROM (dlp_library l, dlp_user u) " .
      "LEFT JOIN dlp_user holder ON (l.current_holder = holder.id) " .
      "WHERE l.id = '$id' AND l.user_id = u.id";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.