PHP - Warning: Mysql_num_rows() Expects Parameter
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\ipod\lib\connection.php on line 131
:S 129. function RecordCount ( $query ) 130. { 131. return mysql_num_rows( mysql_query( $query ) ); 132. } Similar TutorialsThis has been really annoying me for 2 hours now . I know its something silly Database Structure QuestionID int Question VarChar HelpDocument VarChar (Link) Posting Code: <!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> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js"></script> <script type="text/javascript" src="jquery.simpledialog/jquery.simpledialog.0.1.js"></script> <link rel="stylesheet" type="text/css" href="style.css" /> <link rel="stylesheet" href="ui.datepicker.css" type="text/css" media="screen" /> <link rel="stylesheet" href="jquery.simpledialog/simpledialog.css" type="text/css" media="screen" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/ libs/jquery/1.3.0/jquery.min.js"></script> <script type="text/javascript"> $(function() { $(".search_button").click(function() { var search_word = $("#search_box").val(); var dataString = 'search_word='+ search_word; if(search_word=='') { } else { $.ajax({ type: "GET", url: "getHelpDocuments.php", data: dataString, cache: false, beforeSend: function(html) { document.getElementById("insert_search").innerHTML = ''; $("#flash").show(); $("#searchword").show(); $(".searchword").html(search_word); $("#flash").html('<img src="ajax-loader.gif" /> Loading Results...'); }, success: function(html){ $("#insert_search").show(); $("#insert_search").append(html); $("#flash").hide(); } }); } return false; }); }); </script> <style> *{margin:0;padding:0;} ol.update { list-style:none; font-size:1.1em; margin-top:20px } ol.update li { height:70px; border-bottom:#dedede dashed 1px; text-align:left; } ol.update li:first-child { border-top:#dedede dashed 1px; height:70px; text-align:left } </style> </head> <body> <div id="AllContent"> <div id="header"> <br></br> <br></br> </div> <br></br> <div id="login"> </div> <br></br> <br></br> <br></br> <br></br> <br></br> <br></br> <br></br> <div id="RequestAccess"> <form method="get" action=""> <input type="text" name="search" id="search_box" class='search_box'/> <input type="submit" value="Search" class="search_button" /> </form> <div id="searchword"> Search results for <span class="searchword"></span></div> <div id="flash"></div> <ol id="insert_search" class="update"> </ol> </ul> </div> </div> </div> </div> </body> </html> PHP SCRIPT <?php if(isset($_GET['search_word'])) { $search_word=$_GET['search_word']; $search_word_new=mysql_escape_string($search_word); $search_word_fix=str_replace(" ","%",$search_word_new); $link = mysql_connect("localhost", "root", ""); mysql_select_db("blank", $link); $sql=mysql_query("SELECT HelpDocument FROM Questions WHERE Question LIKE '%$search_word_fix%' ORDER BY Question DESC LIMIT 20", $link); $count=mysql_num_rows($sql); if($count > 0) { while($row=mysql_fetch_array($sql)) { $msg=$row['Question']; $bold_word='<b>'.$search_word.'</b>'; $final_msg = str_ireplace($search_word, $bold_word, $msg); ?> <li><?php echo $final_msg; ?></li> <?php } } else { echo "<li>No Results</li>"; } } ?> getting this error Warning: mysql_num_rows() expects parameter 1 to be resource and it wont display the database fields after search Any help is deeply appreciated thanks Hey, this is my first post here, so bear with me: I'm new to PHP, and am trying to make an online store, right now I'm just making an admin inventory management, and so I'm using PHP to link to the database. Before any of this script, I link to the database and all that, so it's not an issue of connection. My issue is I keep getting the following message: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in "inventory_list.php" on line 38 Column count doesn't match value count at row 1 There used to be three or four other error messages, but I've been able to work out my mistakes and fix them. Here is my code, starting at Line 27: Code: [Select] <?php // Parse the form data and add inventory item to the system if (isset($_POST['product_name'])) { $product_name = mysql_real_escape_string($_POST['product_name']); $price = mysql_real_escape_string($_POST['price']); $category = mysql_real_escape_string($_POST['category']); $subcategory = mysql_real_escape_string($_POST['subcategory']); $details = mysql_real_escape_string($_POST['details']); // See if that product name is an identicle match to another in the system $sql = mysql_query("SELECT product_id FROM products WHERE product_name='$product_name' LIMIT 1"); $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0){ echo 'Sorry, you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>'; exit(); } // Add this product into the database now $sql = mysql_query("INSERT INTO product (product_name, price, category, subcategory, date_added) VALUES('$product_name','$price','$details','$category','$subcategory',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"); } ?> The line causing this issue is thus: Code: [Select] $productMatch = mysql_num_rows($sql); // count the output amount Does anyone know how to fix this for me? Thanks i am try to make a name, address search system into my website from my database. but i got this msg [Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampplite\htdocs\3\searchresult.php on line 54] my full php code i.e. searchresult.php is under...... what i have mistake..... searchresult.php <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php // TAKE THE INFORMATION FROM FORM. $search = $_GET['search']; // IF THERE IS NOT A KEYWORD GIVE A MISTAKE. if (!$search) echo "You didn't enter a keyword"; else { echo "<td>You searched for: <strong>$search </strong></td>"; mysql_connect('localhost','root',''); mysql_select_db('search'); $id=@$_GET['id']; //QUERY IS THE CODE WHICH WILL MAKE THE SEARCH IN YOUR DATABASE. //I WROTE AN EXPLANATION ABOUT IT AFTER THE CODE. $sql = "CREATE TABLE searchform \n" ."(\n" ."ID int NOT NULL AUTO_INCREMENT ,\n" ."FirstName varchar( 255 ) NOT NULL ,\n" ."LastName varchar( 255 ) NOT NULL ,\n" ."Email varchar( 255 ) NOT NULL ,\n" ."PhoneNumber varchar( 255 ) NOT NULL ,\n" ."PRIMARY KEY ( ID ) )";; $result1 = MySQL_query($query); if(!$result1) { echo MySQL_error()."<br>$query<br>"; } if(MySQL_num_rows($result1) > 5) { echo "<table width='750' align='center' border='0' cellspacing='0' cellpadding='0'>"; while($result2 = MySQL_fetch_array($result1)) { //A short description from category. $description = $result2['category']; $searchPosition = strpos($description, $search); $shortDescription = substr($description, $searchPosition, 150); // I added a link to results which will send the user to your display page. echo '<tr><td><p><strong><a href="displayresults.php?id='.$result2['id'].'">'.$result2['title'].'</strong></p></td></tr>'; echo "<tr><td>$shortDescription ...</td></tr>"; echo "<td>{$result2['name']} {$result2['surname']}</td><tr/>"; } echo "</table>"; }else { echo "No Results were found in this category.<br>"; }echo "<br>"; } ?> </body> </html> and searchform.php <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form action="searchresult.php" method="get"> <div align="center"> <p> <input name="search" type="text" size="60"/> <input name="submit" type="submit" value="Search" /> </p> </div> </form> </body> </html> i give it up after 4 h. please help me, what i do wrong Hi I'm having a bit of bother with my login. I created a login using this tutorial http://www.phpeasystep.com/phptu/6.html and it works perfectly. So i have attempted to change it to meet my own database. So basically i've changed the database, table names etc to meet my own. I haven't changed any other lines. When i run it i get an error message: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\checklogin.php on line 26 The code is below: Code: [Select] <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="final year project"; // Database name $tbl_name="tbl_user"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $mem_username=$_POST['mem_username']; $mem_password=$_POST['mem_password']; // To protect MySQL injection (more detail about MySQL injection) $mem_username = stripslashes($mem_username); $mem_password = stripslashes($mem_password); $mem_username = mysql_real_escape_string($mem_username); $mem_password = mysql_real_escape_string($mem_password); $sql="SELECT * FROM $tbl_name WHERE username='$mem_username' and password='$mem_password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $mem_username and $mem_password, table row must be 1 row if($count==1){ // Register $mem_username, $mem_password and redirect to file "login_success.php" session_register("mem_username"); session_register("mem_password"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> Line 26 is $count=mysql_num_rows($result); I'm baffled as to why the test database worked. I tried another test database but got the same error. baffled.com Hope someone can help MOD EDIT: [code] . . . [/code] tags added. I have tired to search this up but get nothing back.. :@ This error is on line 18 on line 18 is Code: [Select] if (mysql_num_rows($result) == 1) { Quote Notice: Undefined variable: result in C:\xampp\htdocs\Exam_Online\Staff_login\Staff_login_process.php on line 18 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Exam_Online\Staff_login\Staff_login_process.php on line 18 Wrong Username or Password This is the error message. Code: [Select] if (mysql_num_rows($result) == 1) { // Set username session variable $_SESSION['ID'] = $_POST['ID']; header("location:Staff_Menu.php"); } else { echo"Wrong Username or Password"; } <?php if(isset($_POST['submit'])){ $name = $_POST['name']; } ?> <form method="POST" action="hist1.php"> <br /> <input type="hidden" name="name" value="<?php echo $name ?>" /> <?php $q = mysql_query("SELECT * FROM histact1 ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question1 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q1"><br /><br /> <label class="items">1st Question :</label> <br /> <center> <textarea class="textareaQ" name="question1" readonly><?php echo $question1; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad1" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad1" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad1" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q2"><label title="Proceed to 2nd Question">Next</label></a> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> <br /><br /> <?php $q = mysql_query("SELECT * FROM histact1 ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question2 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q2"><br /><br /> <label class="items">2nd Question :</label> <br /> <center> <textarea class="textareaQ" name="q2" readonly><?php echo $question2; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad2" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad2" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad2" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q1"><label title="Proceed to 1st Question">Back</label></a> | <a class="nxt" href="#q3"><label title="Proceed to 3rd Question">Next</label></a> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> <br /><br /> <?php $q = mysql_query("SELECT * FROM histact1 ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question3 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q3"><br /><br /> <label class="items">3rd Question :</label> <br /> <center> <textarea class="textareaQ" name="q3" readonly><?php echo $question3; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad3" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad3" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad3" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q2"><label title="Proceed to 2nd Question">Back</label></a> | <a class="nxt" href="#q4"><label title="Proceed to 4th Question">Next</label></a> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> <br /><br /> <?php $q = mysql_query("SELECT * FROM histact1 ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question4 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q4"><br /><br /> <label class="items">4th Question :</label> <br /> <center> <textarea class="textareaQ" name="q4" readonly><?php echo $question4; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad4" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad4" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad4" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q3"><label title="Proceed to 3rd Question">Back</label></a> | <a class="nxt" href="#q5"><label title="Proceed to 5th Question">Next</label></a> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> <br /><br /> <?php $q = mysql_query("SELECT * FROM histact1 WHERE question != '$question1' AND question != '$question2' AND question != '$question3' AND question != '$question4' ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question5 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q5"><br /><br /> <label class="items">5th Question :</label> <br /> <center> <textarea class="textareaQ" name="q5" readonly><?php echo $question5; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad5" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad5" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad5" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q4"><label title="Proceed to 4th Question">Back</label></a> | <input type="submit" title="Submit Answers" name="submit" class="submit" value=" Submit " onclick="return confirm('Are you sure you want to submit your answers?\nYou can review your answer by click the Back link')" /> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> </form> Edited by mac_gyver, 09 October 2014 - 10:51 AM. code in code tags please The 2 errors I am getting a Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\searchstock2.php on line 36 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\searchstock2.php on line 38 I am trying to search a table and return results, all fields are VARCHAR except ID (integer), here is part of my code; $link = mysql_connect("localhxxxxx","xxx",""); //(host, username, password) mysql_select_db("wadkin", $link) or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from stocklist where Stock Number like \'%$trimmed%\'OR Name like \'%$trimmed%\' OR Category like \'%$trimmed%\'"; if ($numresults=mysql_query($query)); $row = mysql_fetch_assoc($numresults); if ($row['COUNT(*)'] == 0); $numrows=mysql_num_rows($numresults); if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } // Determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["Name"]; echo "$count.) $title" ; $count++ ; } $row = mysql_fetch_assoc($numresults); = line 36 $numrows=mysql_num_rows($numresults); = line 38 Hi guys, I'm new to forums so hopefully someone can help me. I keep getting the following error: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Blog2\checklogin.php on line 27 My code is: Code: [Select] // Define $blog_user_name and $blog_user_password $blog_user_name=$_POST['blog_user_name']; $blog_user_password=$_POST['blog_user_password']; // To protect MySQL injection (more detail about MySQL injection) $blog_user_name = stripslashes($blog_user_name); $blog_user_password = stripslashes($blog_user_password); $blog_user_name = mysql_real_escape_string($blog_user_name); $blog_user_password = mysql_real_escape_string($blog_user_password); $sql="SELECT * FROM $tbl_name WHERE username='$blog_user_name' and password='$blog_user_password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); //THIS IS LINE 27 // If result matched $blog_user_name and $blog_user_password, table row must be 1 row if($count==1){ // Register $blog_user_name, $blog_user_password and redirect to file "index.php" session_register("blog_user_name"); session_register("blog_user_password"); header("location:index.php"); } else { echo "Wrong Username or Password"; } ob_end_flush(); Please can someone help I have know idea what the problem could be. Thanks. Hi guys, I have an error msg here, "Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\inetpub\vhosts\championtutor.com\httpdocs\tutor_registration3.php on line 598". I have highlighted the error line in red, do you guys have any idea what went wrong? Thanks <?php $dbc = mysqli_connect('localhost', '111', '111', '111') or die(mysqli_error()); $query = "SELECT sl.subject_level_id, sl.level_id, sl.subject_id, tl.name AS level_name, ts.name AS subject_name " . "FROM tutor_subject_level AS sl " . "INNER JOIN tutor_level AS tl USING (level_id) " . "INNER JOIN tutor_subject AS ts USING (subject_id) "; $sql = mysqli_query($dbc, $query) or die(mysqli_error()); echo'<table><tr>'; // Start your table outside the loop... and your first row $count = 0; // Start your counter while($data = mysqli_fetch_array($sql)) { /* Check to see whether or not this is a *new* row If it is, then end the previous and start the next and restart the counter. */ if ($count % 5 == 0) { echo "</tr><tr>"; $count = 0; } echo '<td><input name="subject_level[]" type="checkbox" id="'.$data['subject_level_id'].'" value="'.$data['subject_level_id'].'"/>'; echo '<label for="'.$data['subject_name'].'">'.$data['subject_name'].'</label></td>'; $count++; //Increment the count } echo '</tr></table><br/><br/>'; //Close your last row and your table, outside the loop ?> My brain isn't working... I am trying to get this Prepared Statement to pull Events from my database and display them, but get this error... Quote Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /Users/user1/Documents/DEV/++htdocs/01_MyProject/events_9.php on line 30 Here is my code... Code: [Select] <?php // Initialize a session. session_start(); // Access Constants. require_once('config/config.inc.php'); // Initialize variables. $eventExists = FALSE; // Connect to the database. require_once(ROOT . 'private/mysqli_connect.php'); // ******************** // Build Event Query * // ******************** $id=1; // Build query. $q = 'SELECT id, name, location, date FROM show WHERE id=?'; // Prepare statement. $stmt = mysqli_prepare($dbc, $q); // Bind variable. mysqli_stmt_bind_param($stmt, 'i', $id); (The last line above is Line 30.) Debbie Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\mariyano\profile.php on line 37 Help me to solve this problem I just want to display the datas in table Thanks in advance Ive been having trouble. Im getting this error: Code: [Select] $select = mysql_query($query1); echo $select; $rows1 = mysqli_fetch_array($dbc, $select); I dont understand whats wrong. Hi
I am a student who is fairly new to PHP and MySQL. I have been working on creating a registration page for a website and I'm getting the following warnings when I've tested the page:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/ed12e2w/public_html/COMM2735/dynamic_website/registration.php on line 74 Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in /home/ed12e2w/public_html/COMM2735/dynamic_website/registration.php on line 80 I think that my query has failed but I'm not completely sure on what to change in order to solve this. Here is the section of code I'm having problems with: Attached Files register.php 733bytes 4 downloads Please help, This code is giving me the warning stated in the above given Subject line. And combo box is also not populating. Code: [Select] function populatecombo() { $dropdown = ""; $sqlcmb = "select wardno from wards"; mysql_query($sqlcmb) or die(mysql_error('Unable to query the table')); while($row = mysql_fetch_assoc($sqlcmb)) { $dropdown .= "\r\n<option value='{$row['wardno']}>'{$row['wardno']}</option>"; } echo $dropdown; } we did an exercise in IT class it was about how to inject php code in css code we took a template as an example to work on. i injected php code in the page "services.php"as instructed but it didn't work and i keep getting this error : Hi all, I have received a warning message, which it still puzzles me. I suspect it might be my inner join command, which I have coded it wrongly? Line 37 refers to this line - if (mysqli_num_rows($data) == 1) { Do you guys have any idea? Thanks Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in D:\inetpub\vhosts\123.com\http\viewprofile.php on line 37 Code: [Select] <?php // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = "SELECT tp.name, tp.nric, tp.gender, tp.race_id, r.race_name AS race" . "FROM tutor_profile AS tp " . "INNER JOIN race AS r USING (race_id) " . "WHERE tutor_id = '" . $_GET['tutor_id'] . "'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo '<table>'; if (!empty($row['name'])) { echo '<tr><td class="label">Name:</td><td>' . $row['name'] . '</td></tr>'; } if (!empty($row['nric'])) { echo '<tr><td class="label">NRIC:</td><td>' . $row['nric'] . '</td></tr>'; } if (!empty($row['last_name'])) { echo '<tr><td class="label">Last name:</td><td>' . $row['last_name'] . '</td></tr>'; } if (!empty($row['gender'])) { echo '<tr><td class="label">Gender:</td><td>'; if ($row['gender'] == 'M') { echo 'Male'; } if ($row['gender'] == 'F') { echo 'Female'; } echo '</td></tr>'; } if (!empty($row['race'])) { echo '<tr><td class="label">Race:</td><td>' . $row['race'] . '</td></tr>'; } echo '</table>'; //End of Table echo '<p>Would you like to <a href="editprofile.php?tutor_id=' . $_GET['tutor_id'] . '">edit your } // End of check for a single row of user results else { echo '<p class="error">There was a problem accessing your profile.</p>'; } mysqli_close($dbc); ?> I have created a script to insert data into a database, but it returns this. Code: [Select] Warning: mysql_select_db() expects parameter 2 to be resource, null given in /RJFWS198/testing/elemata_project/admin/elements/create_page.php on line 51 Here is the code Code: [Select] <?PHP //Protect Against Attacks if (empty($_SESSION['E_User'])) { die("Access Denied"); } ?> <?php if (!empty($_REQUEST['title']) && (!empty($_SESSION['E_User']))) { require_once('../Connections/default.php'); if (empty($_REQUEST['password'])) { $password = "0"; }else{ $password = $_REQUEST['password']; } if (empty($_REQUEST['menu_order'])) { $mo = "0"; }else{ $mo = $_REQUEST['menu_order']; } if (empty($_REQUEST['meta_keywords'])) { $meta_keywords = "0"; }else{ $meta_keywords = $_REQUEST['meta_keywords']; } if (empty($_REQUEST['meta_desc'])) { $meta_desc = "0"; }else{ $meta_desc = $_REQUEST['meta_desc']; } if (empty($_REQUEST['meta_copyright'])) { $meta_copyright = "0"; }else{ $meta_copyright = $_REQUEST['meta_copyright']; } $author = $_SESSION['E_User']; $date = date("m.d.y"); $day = date("d"); $month = date("n"); $year = date("Y"); $time = ''.date("g").''.date("i").''.date("a").''; $ptitle = $_REQUEST['title']; $post_content = $_REQUEST['postContent']; $searchable = $_REQUEST['seachable']; $locked = $_REQUEST['privacy']; $tags = $_REQUEST['tags']; $meta_robots = $_REQUEST['robots']; mysql_select_db($database_default, $default); mysql_query("INSERT INTO posts (`time`, `year`, `month`, `day`, `date`, `author`, `title`, `content`, `searchable`, `locked`, `password`, `menu_order`, `tags`, `meta_keywords`, `meta_desc`, `meta_robots`, `meta_copyright`) VALUES ('$time', '$year', '$month', '$day', '$date', '$author', '$ptitle', '$post_content', '$searchable', '$locked', '$password', '$mo', '$tags', '$meta_keywords', '$meta_desc', '$meta_robots', '$meta_copyright')"); } ?> I am trying to install a comments box, im new to php and mysql so havent been able to work this out for myself following other threads, hope someone can shed some light on the problem. The posts ive entered arent being returned to the page essentially and im getting the error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in commentbox.php on line 42. This is the code from the entire page. Code: [Select] <?php require('commentconnect.php'); $name=@$_POST['name']; $comment=@$_POST['comment']; $submit=@$_POST['submit']; if($submit) { if($name&&$comment) { $insert=mysql_query("INSERT INTO commenttable (name,comment) VALUES ('$name','$comment')"); /*header("Location: index.php");*/ echo "<script>document.location.href='index.php'</script>"; echo "<script>'Content-type: application/octet-stream'</script>"; } else { echo "Please fill out the fields"; } } ?> <div id="commentdiv"> <div id="commentinput"> <form action="index.php" method="POST"> <table> <tr><td>Name: </td><td><input type="text" name="name" /></td></tr> <tr><td colspan="2">Comment: </td></tr> <tr><td colspan="2"><textarea name="comment"></textarea></td></tr> <tr><td colspan="2"><input type="submit" name="submit" value="Comment" /></td></tr> </table> </form> </div> <div id="commentarea"> <?php $getquery=mysql_query("SELECT * FROM commenttable ORDER BY id DESC"); while($rows=mysql_fetch_array($getquery)) { $id=$rows['id']; $name=$rows['name']; $comment=$rows['comment']; $dellink="<a href=\"delete.php?id=" . $id . "\"> Delete </a>"; echo $name . '' . '<br />' . $comment . '<br />' . '<hr/>'; } ?> </div> </div> Any help is greatly appreciated! Hello, Im developing simple user registration system with my knowledge.but got this error with this file Code: [Select] <?php //database connection require_once("dbconnection/connect.php"); $success_massage =""; if (isset($_POST['hiddenstudentid'])) $passstudent_id=$_POST['hiddenstudentid']; else $passstudent_id=$_POST['student_id_hidden']; $sql=mysql_query("SELECT * FROM student WHERE StudentID=$passstudent_id"); echo $sql; while ($row=mysql_fetch_assoc($sql)) { $update_nic=$row['NIC']; $update_name=$row['Student_Name']; $update_addr=$row['Address']; $take_bday=$row['Birthday']; echo $take_bday; $update_bday=date('d',strtotime($take_bday)); $update_month=date('m',strtotime($take_bday)); $update_year=date('y',strtotime($take_bday)); $update_tele=$row['Telephone']; $update_email=$row['Email']; } if (isset($_POST['btnupdate'])) { $insert_nic=$_POST['nic_txt']; $insert_name=$_POST['name_txt']; $insert_addr=$_POST['address_txt']; $insert_bday=$_POST['bdate']; $insert_month=$_POST['bmonth']; $insert_year=$_POST['byear']; $insert_tele=$_POST['telephone_txt']; $insert_email=$_POST['email_txt']; $Birthday =date("$insert_year-$insert_month-$insert_bday");//Bday eka $Birthday ta set kereema. $sql="update student set NIC='$insert_nic',Student_Name='$insert_name',Address='$insert_addr',Birthday='$Birthday',Telephone='$insert_tele',Email='$insert_email' where StudentID=$passstudent_id" ; /*(Student_ID,NIC,Student_Name,Address,Birthday,Telephone,Email)values('$student_id','$insert_nic','$insert_name','$insert_addr','$Birthday','$insert_tele','$insert_email')";*/ //echo $sql; $result=mysql_query($sql) or die ("database error"); $success ="Records updated successfully"; $success_massage =$success; header('Location:editdisplay.php'); } if ($_POST['btndelete']=='DELETER') { $delete = "delete from student where StudentID=$passstudent_id"; $result =mysql_query($delete) or die ("data deleting error"); $delete_massage="Record deleted"; //$success_massage = $delete_massage; } if (isset($_POST['btncancel'])) { header ('Location:registration.php'); } ?> <!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>Untitled Document</title> <script type="text/javascript"> function GetConfirmation() { var res=confirm("Are you sure to delete this Student?"); if(res==true) { var btn=document.getElementById("btndelete"); btn.value="DELETER"; // alert ("YES"); document.editForm.submit(); } } </script> </head> <body> <form id="form1" name="form1" method="post" action=""> <table width="406" border="1"> <tr> <td width="149"> </td> <td width="241">Student Registration</td> </tr> <tr> <td>NIC</td> <td><label for="nic_txt"></label> <input type="text" name="nic_txt" id="nic_txt" value="<?php echo $update_nic ?>" /><input type="hidden" name="student_id_hidden" id="student_id_hidden" value="<?php echo $passstudent_id ?>" /> </td> </tr> <tr> <td>Name</td> <td><label for="name_txt"></label> <input type="text" name="name_txt" id="name_txt" value="<?php echo $update_name ?>" /><span style="color:#F00"><?php echo $massage_name?></span></td> </tr> <tr> <td>Address</td> <td><label for="address_txt"></label> <input type="text" name="address_txt" id="address_txt" value="<?php echo $update_addr ?>" /><span style="color:#F00"><?php echo $massage_address?></span></td> </tr> <tr> <td>Birthday</td> <td><label for="bdate"></label> <select name="bdate" id="bdate"> <option selected="selected"><?php echo $update_bday ?></option> <?php for ( $i=1;$i<=31;$i++) {echo '<option>'.$i.'</option>'; } ?> </select> <label for="bmonth"></label> <select name="bmonth" id="bmonth"> <option selected="selected"><?php echo $update_month ?></option> <?php echo '<option>'.'-month-'.'</option>'; for ($b=1;$b<=12;$b++) {echo '<option>'.$b.'</option>'; } ?> </select> <label for="byear"></label> <select name="byear" id="byear" /> <option selected="selected"><?php echo $update_year ?></option> <?php echo '<option>'.'-year-'.'</option>'; for ($b=1960;$b<=2000;$b++) {echo '<option>'.$b.'</option>'; } ?> </select><span style="color:#F00"><?php echo $massage_bday?></span></td> </tr> <tr> <td>Email</td> <td><label for="email_txt"></label> <input type="text" name="email_txt" id="email_txt" value="<?php echo $update_email?>" /></td> </tr> <tr> <td>Telephone</td> <td><label for="telephone_txt"></label> <input type="text" name="telephone_txt" id="telephone_txt" value="<?php echo $update_tele?>"/></td> </tr> <tr> <td> </td> <td><input type="submit" name="btnupdate" id="btnupdate" value="Update" /> <input type="submit" name="btndelete" id="btndelete" value="Delete" onclick="GetConfirmation()" /> <input type="submit" name="btncancel" id="btncancel" value="Cancel" /></td> </tr> </table> <?php echo $success_massage?> </form> </body> </html> got error from these codes in this file Code: [Select] if (isset($_POST['hiddenstudentid'])) $passstudent_id=$_POST['hiddenstudentid']; else $passstudent_id=$_POST['student_id_hidden']; $sql=mysql_query("SELECT * FROM student WHERE StudentID=$passstudent_id"); echo $sql; it is showing this error this this warning error.in here that details from DB will show in form.and im going to edit them from this file. please help me to find the error. |