Jump to content

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ntubookb/domains/ntubookbrowser.co.uk/public_html/books.php


Recommended Posts

<?php

//session status block

include "connect_to_mysql.php";

?>

<?php

//script error reporting

//error reporting

error_reporting(E_ALL);

ini_set('display_errors','1');

?>

 

<?php

//parse form data to database

//parse the form data and add inverntory items to the system

//CHANGE ALL VALUES TO SUIT NEEDS OF CURRENT DATABASE

//FORM DATA AND ADD BOOK TO THE SYSTEM DATABASE

if (isset($_POST['BOOKNAME'])) {

 

    $BOOKNAME = mysql_real_escape_string($_POST['BOOKNAME']);

$BOOKPRICE = mysql_real_escape_string($_POST['BOOKPRICE']);

$CATEGORY = mysql_real_escape_string($_POST['CATEGORY']);

$BOOKDESCRIPTION = mysql_real_escape_string($_POST['BOOKDESCRIPTION']);

// See if that product name is an identical match to another product in the system

$sql = mysql_query("SELECT ID FROM BOOK WHERE BOOKNAME='$BOOKNAME' LIMIT 1");

    

// Add this product into the database now

$sql = mysql_query("INSERT INTO BOOK (BOOKNAME, BOOKPRICE, BOOKDESCRIPTION, CATEGORY, DATE) 

        VALUES('$BOOKNAME','$BOOKPRICE','$BOOKDESCRIPTION','$CATEGORY',now())") or die (mysql_error());

     $pid = mysql_insert_id();

// Place image in the folder 

$newname = "$pid.jpg";

move_uploaded_file( $_FILES['fileField']['tmp_name'], "inventory_images/$newname");

echo 'Book Successfully Uploaded <a href="index.php"><b>Click Here To Go To Home Page</b></a>';

    exit();

}

?>

 

<?php

//this block grab the whole list for viewing

//THIS BLOCKS GRABS THE WHOLE LIST FOR VIEWING

$product_list = "";

$sql = mysql_query("SELECT * FROM BOOK ORDER BY date_added DESC");

$productCount = mysql_num_rows($sql); // count the output amount

if ($productCount > 0) {

while($row = mysql_fetch_array($sql)){

$ID = $row["ID"];

   $BOOKNAME = $row["BOOKNAME"];

$CATEGORY = $row["CATEGORY"];

$BOOKDESCRIPTION = $row["BOOKDESCRIPTION"];

$BOOKPRICE = $row["BOOKPRICE"];

$product_list = "Product ID: $ID - <strong>$BOOKNAME</strong> - $$BOOKPRICE - <em>Added $date_added</em>        • <br />";

$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));

}

} else {

$product_list = "There are currently no books for sale, check back soon !";

}

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>NTU Book Browser</title>

<link rel="stylesheet" href="style.css" />


 

<script>

$(function() {

$("#text-one").change(function() {

$("#text-two").load("textdata/" + $(this).val() + ".txt");

});

});

</script>

</head>

 

<body>

<div id="wrapper">

 

    <?php include_once("template_header.php");?>

        

<div id="wrapper_content">

      

 

        

        <div id="headers">

<h2> Books </h2>

        </div>

        

        <div id="main">

        

        <div id="add_item">

        <p><i> <a href="books.php#bookForm">+Sell Book</a></i></p>

        </div>

        

       

<?php echo $product_list; ?>

        

        

        

        <a name="bookForm" id="bookForm"></a>

        <h3> Add New Book Form </h3>

        <form action="books.php" enctype="multipart/form-data" name="myForm" id="myform" method="post">

    <table width="90%" border="0" cellspacing="0" cellpadding="6">

      <td align="right">Book Name</td>

        <td><select name="CATEGORY" id="text-one">

<option selected value="base">Select Book Category</option>

<option value="biomedicalscience">Biomedical Science</option>

<option value="history">History</option>

<option value="spanish">Spanish</option>

<option value="economics">Economics</option>

<option value="sportsscience">Sports Science</option>

<option value="forensicsscience">Forensics Science</option>

<option value="computersystems">Computer Systems</option>

<option value="english">English</option>

<option value="psychologyandeducation">Psychology and Education</option>

</select>

        </td>

 

<br />

<td align="right"></td>

        <td>

<select name="BOOKNAME" id="text-two">

<option>Select Book</option>

</select>

        </td>

      </tr>

      <tr>

        <td align="right">Book Price</td>

        <td><label>

          £

          <input name="BOOKPRICE" type="text" id="BOOKPRICE" size="12" />

        </label></td>

      </tr>

      <tr>

        

      <tr>

       

      <tr>

        <td align="right">Book Description</td>

        <td><label>

          <textarea name="BOOKDESCRIPTION" id="description" cols="64" rows="5"></textarea>

        </label></td>

      </tr>

      <tr>

        <td align="right">Book Image</td>

        <td><label>

          <input type="file" name="fileField" id="fileField" />

        </label></td>

      </tr>      

      <tr>

        <td> </td>

        <td><label>

          <input type="submit" name="button" id="button" value="Add Book" />

        </label></td>

      </tr>

    </table>

    </form>

        

        

        

        

        

        

        </div>

        

        

        

        

        

        

        

        

        

        

        

        

        

    

        

 

        <div id="footer">

    <?php include_once("template_footer.php");?>

        </div>

        

        

        

    </div>

</div>

    <div class="clear"></div>

</body>

</html>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.