Search the Community
Showing results for tags 'mysql_num_rows()'.
-
Hi, I want to make a select from mysql to show some data in page. To show a table with data from mysql but limited to only 5 and this to show total number of rows. I'm thinking to make two selects. SELECT count(*) FROM table1 and after that to use mysql_num_rows to count total number in that table. Then another SELECT name,prename FROM table1 LIMIT 1, 5 to show only first 5 rows. It's there a way to use only one select insted of two but having the same results ? Thanks
-
hey i was typing a smale login code but i keep geting this waring Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/u400486/domains/u400486.gluweb.nl/public_html/lekkerpittig/register.php on line 17 and it won't save on my table but i tink thats becouse of the waring can someone help out <?php include('config.php'); if($_SERVER['REQUEST_METHOD'] == 'POST'){ $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string(md5($_POST['password'])); if(empty($username)){ echo("you have to fill in an username!"); } else{ if(empty($password)){ echo("you have to fill in a password!"); } else{ $query = mysql_query("SELECT * FROM users WHERE username ='$username'"); $rows = mysql_num_rows($query); if($rows > 0){ die ("Username taken!"); }else{ $user_input = mysql_query("INSERT INTO users(username , password) VALUES('$username' , '$password')"); echo("succesfully registered!"); } } } } ?> <html> <head> <title>register</title> </head> <body> <form action="register.php" method="post"/> username: <input type="text" name="username"/> <br /> password: <input type="password" name="password"/> <br /> <input type="submit" value="resister!" /> </form> </body> </html>
-
<?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"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>NTU Book Browser</title> <link rel="stylesheet" href="style.css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <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>