PHP - Mysql_fetch_array () Expect Parameter 1 To Be Resource
the below is a simple search code.. I have listed the error at the end
<div id="searchdiv"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div id="searchdivtext">Info :</div> <input type="text" name="search" id="searchdivtextbox"> <input type="submit" id="searchdivbtn" name="submit"> </form> </div> <?php if (isset($_POST['submit'])) // perform search only if a string was entered. { mysql_connect('localhost','root','') or die('Could not connect to mysql ' . mysql_error()); // error message mysql_select_db("infosite") or die(mysql_error()); $query = "select * from wp_usermeta WHERE Name='$search'"; $result = mysql_query($query); echo "$result"; if ($query) { echo "Here are the results:<br><br>"; echo '<div id="maincontainer">'; echo '</div>'; while ($r = mysql_fetch_array($result,MYSQL_ASSOC)) { // Begin while $ts = $r["TimeStamp"]; $name = $r["Name"]; $last = $r["Last"]; $email = $r["email"]; $comment = $r["comment"]; echo "<tr> <td>$ts</td> <td>$name</td> <td>$last</td> <td>$email</td></tr> <tr> <td colspan=4 bgcolor=\"#ffffa0\">$comment</td> </tr>"; } // end while echo "</table>"; } else { echo "problems...."; } } else { echo "Search string is empty. <br> Go back and type a string to search"; } ?> </div> I get the following error Warning : mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\wordpress\wp-content\themes\info-site\results.php on line 85 thanks Similar TutorialsWhen I run my code outside of a function it works but when i put it on this function I get these three errors: 1. mysql_fetch_array() expects parameter 1 to be resource, null given on line 20 which is: "while($row = mysql_fetch_array($result, MYSQLI_ASSOC))" 2. on line 19: mysqli_query() expects parameter 1 to be mysqli, null given which is: "$result = mysqli_query($dbc, $q);" 3. on line 19: Undefined variable: dbc Here is the function call: <h5>Latest Posts</h5> <div class="box"> <div class="content"> <ul> <?php latestpost(); ?> </ul> </div> </div> Here is the function: require_once ('mysqli_connect.php'); function latestpost() { $q = "SELECT * FROM posts p, threads t, users u where t.thread_id = p.thread_id and u.user_id = t.user_id ORDER BY p.posted_on DESC LIMIT 0, 5"; $result = mysqli_query($dbc, $q); while($row = mysql_fetch_array($result, MYSQLI_ASSOC)) { extract($row); echo "<li><a target='_blank' href='http://localhost/sample/forum/viewtopic.php?f=". $p.post_id."&t=".$t.thread_id."'> <strong>".$subject."</strong></a><br /><small>Member since ". $p.posted_on."</small></li>"; } } Here is the connection: <?php mysqli_connect.php is: DEFINE ('DB_USER', 'username'); DEFINE ('DB_PASSWORD', 'password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'database'); // Make the connection: $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); // Set the encoding... mysqli_set_charset($dbc, 'utf8'); // end 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! Hey guys, i was recently making a new PHP code and when i tested it out it gave me this error: Code: [Select] mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\tools\edit_infos.php on line 167 I don't know what the problem is. Here is 'Line 167': Code: [Select] //Line 167 $dnn = mysql_fetch_array(mysql_query('select username,password,email,desc,keys,logo,webclient,forums,hiscores,chatbox,staff,newstitle,newsimage,news,op1,op2,op3 from users where username="'.$_SESSION['username'].'"')); $username = htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8'); $password = htmlentities($dnn['password'], ENT_QUOTES, 'UTF-8'); $email = htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8'); $desc = htmlentities($dnn['desc'], ENT_QUOTES, 'UTF-8'); $keys = htmlentities($dnn['keys'], ENT_QUOTES, 'UTF-8'); $logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8'); $webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8'); $forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8'); $hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8'); $chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8'); $staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8'); $newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8'); $newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8'); $news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8'); $op = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8'); $opp = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8'); $oppp = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8'); And here is the whole page code if needed. Code: [Select] <?php include('config.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" /> <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" /> <title>Edit my personnal informations</title> </head> <body> <div class="header"> <a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Members Area" /></a> </div> <?php //We check if the user is logged if(isset($_SESSION['username'])) { //We check if the form has been sent if(isset($_POST['username'], $_POST['password'], $_POST['passverif'], $_POST['email'], $_POST['desc'], $_POST['keys'], $_POST['logo'], $_POST['webclient'], $_POST['forums'], $_POST['hiscores'], $_POST['donate'], $_POST['chatbox'], $_POST['staff'], $_POST['newstitle'], $_POST['newsimage'], $_POST['news'], $_POST['op1'], $_POST['op2'], $_POST['op3'], $_POST['desc'])) { //We remove slashes depending on the configuration if(get_magic_quotes_gpc()) { $_POST['username'] = stripslashes($_POST['username']); $_POST['password'] = stripslashes($_POST['password']); $_POST['passverif'] = stripslashes($_POST['passverif']); $_POST['email'] = stripslashes($_POST['email']); $_POST['desc'] = stripslashes($_POST['desc']); $_POST['keys'] = stripslashes($_POST['keys']); $_POST['logo'] = stripslashes($_POST['logo']); $_POST['webclient'] = stripslashes($_POST['webclient']); $_POST['forums'] = stripslashes($_POST['forums']); $_POST['hiscores'] = stripslashes($_POST['hiscores']); $_POST['donate'] = stripslashes($_POST['logo']); $_POST['chatbox'] = stripslashes($_POST['chatbox']); $_POST['staff'] = stripslashes($_POST['staff']); $_POST['newstitle'] = stripslashes($_POST['newstitle']); $_POST['newsimage'] = stripslashes($_POST['newsimage']); $_POST['news'] = stripslashes($_POST['news']); $_POST['op1'] = stripslashes($_POST['op1']); $_POST['op2'] = stripslashes($_POST['op2']); $_POST['op3'] = stripslashes($_POST['op3']); } //We check if the two passwords are identical if($_POST['password']==$_POST['passverif']) { //We check if the password has 6 or more characters if(strlen($_POST['password'])>=6) { //We check if the email form is valid if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email'])) { //We protect the variables $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $email = mysql_real_escape_string($_POST['email']); $desc = mysql_real_escape_string($_POST['desc']); $keys = mysql_real_escape_string($_POST['keys']); $logo = mysql_real_escape_string($_POST['logo']); $webclient = mysql_real_escape_string($_POST['webclient']); $forums = mysql_real_escape_string($_POST['forums']); $hiscores = mysql_real_escape_string($_POST['hiscores']); $donate = mysql_real_escape_string($_POST['donate']); $chatbox = mysql_real_escape_string($_POST['chatbox']); $staff = mysql_real_escape_string($_POST['staff']); $newstitle = mysql_real_escape_string($_POST['newstitle']); $newsimage = mysql_real_escape_string($_POST['newsimage']); $news = mysql_real_escape_string($_POST['news']); $op = mysql_real_escape_string($_POST['op1']); $opp = mysql_real_escape_string($_POST['op2']); $oppp = mysql_real_escape_string($_POST['op3']); //We check if there is no other user using the same username $dn = mysql_fetch_array(mysql_query('select count(*) as nb from users where username="'.$username.'"')); //We check if the username changed and if it is available if($dn['nb']==0 or $_POST['username']==$_SESSION['username']) { //We edit the user informations if(mysql_query('update users set username="'.$username.'", password="'.$password.'", email="'.$email.'", desc="'.$desc.'", keys="'.$keys.'", logo="'.$logo.'", webclient="'.$webclient.'", forums="'.$forums.'", hiscores="'.$hiscores.'", chatbox="'.$chatbox.'", staff="'.$staff.'", newstitle="'.$newstitle.'", newsimage="'.$newsimage.'", news="'.$news.'", op1="'.$op1.'", op2="'.$op2.'", op3="'.$op3.'" where id="'.mysql_real_escape_string($_SESSION['userid']).'"')) { //We dont display the form $form = false; //We delete the old sessions so the user need to log again unset($_SESSION['username'], $_SESSION['userid']); ?> <div class="message">Your informations have successfuly been updated. You need to log again.<br /> <a href="connexion.php">Log in</a></div> <?php } else { //Otherwise, we say that an error occured $form = true; $message = 'An error occurred while updating your informations.'; } } else { //Otherwise, we say the username is not available $form = true; $message = 'The username you want to use is not available, please choose another one.'; } } else { //Otherwise, we say the email is not valid $form = true; $message = 'The email you entered is not valid.'; } } else { //Otherwise, we say the password is too short $form = true; $message = 'Your password must contain at least 6 characters.'; } } else { //Otherwise, we say the passwords are not identical $form = true; $message = 'The passwords you entered are not identical.'; } } else { $form = true; } if($form) { //We display a message if necessary if(isset($message)) { echo '<strong>'.$message.'</strong>'; } //If the form has already been sent, we display the same values if(isset($_POST['username'],$_POST['password'],$_POST['desc'], $_POST['keys'], $_POST['logo'], $_POST['webclient'], $_POST['forums'], $_POST['hiscores'], $_POST['donate'], $_POST['chatbox'], $_POST['staff'], $_POST['newstitle'], $_POST['newsimage'], $_POST['news'], $_POST['op1'], $_POST['op2'], $_POST['op3'])) { $pseudo = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8'); if($_POST['password']==$_POST['passverif']) { $password = htmlentities($_POST['password'], ENT_QUOTES, 'UTF-8'); } else { $password = ''; } $email = htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8'); $desc = htmlentities($_POST['desc'], ENT_QUOTES, 'UTF-8'); $keys = htmlentities($dnn['keys'], ENT_QUOTES, 'UTF-8'); $logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8'); $webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8'); $forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8'); $hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8'); $chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8'); $staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8'); $newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8'); $newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8'); $news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8'); $op = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8'); $opp = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8'); $oppp = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8'); } else { //otherwise, we display the values of the database $dnn = mysql_fetch_array(mysql_query('select username,password,email,desc,keys,logo,webclient,forums,hiscores,chatbox,staff,newstitle,newsimage,news,op1,op2,op3 from users where username="'.$_SESSION['username'].'"')); $username = htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8'); $password = htmlentities($dnn['password'], ENT_QUOTES, 'UTF-8'); $email = htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8'); $desc = htmlentities($dnn['desc'], ENT_QUOTES, 'UTF-8'); $keys = htmlentities($dnn['keys'], ENT_QUOTES, 'UTF-8'); $logo = htmlentities($dnn['logo'], ENT_QUOTES, 'UTF-8'); $webclient = htmlentities($dnn['webclient'], ENT_QUOTES, 'UTF-8'); $forums = htmlentities($dnn['forums'], ENT_QUOTES, 'UTF-8'); $hiscores = htmlentities($dnn['hiscores'], ENT_QUOTES, 'UTF-8'); $chatbox = htmlentities($dnn['chatbox'], ENT_QUOTES, 'UTF-8'); $staff = htmlentities($dnn['staff'], ENT_QUOTES, 'UTF-8'); $newstitle = htmlentities($dnn['newstitle'], ENT_QUOTES, 'UTF-8'); $newsimage = htmlentities($dnn['newsimage'], ENT_QUOTES, 'UTF-8'); $news = htmlentities($dnn['news'], ENT_QUOTES, 'UTF-8'); $op = htmlentities($dnn['op1'], ENT_QUOTES, 'UTF-8'); $opp = htmlentities($dnn['op2'], ENT_QUOTES, 'UTF-8'); $oppp = htmlentities($dnn['op3'], ENT_QUOTES, 'UTF-8'); } //We display the form ?> <div class="content"> <form action="edit_infos.php" method="post"> You can edit your informations:<br /> <div class="center"> <label for="username">Username</label><input type="text" name="username" id="username" value="<?php echo $username; ?>" /><br /> <label for="password">Password<span class="small">(6 characters min.)</span></label><input type="password" name="password" id="password" value="<?php echo $password; ?>" /><br /> <label for="passverif">Password<span class="small">(verification)</span></label><input type="password" name="passverif" id="passverif" value="<?php echo $password; ?>" /><br /> <label for="email">Email</label><input type="text" name="email" id="email" value="<?php echo $email; ?>" /><br /> <label for="desc">Webclient/Server Description</label><textarea name="desc" id="desc" rows="3" value="<?php echo $desc; ?>"></textarea><br /> <label for="keys">Webclient/Server Tags<span class="small">(Seperate with comma's)</span></label><input type="text" name="keys" id="keys" value="<?php echo $keys; ?>" /><br /> <label for="logo">Website/Server Logo Link</label><input type="text" name="logo" id="logo" value="<?php echo $logo; ?>" /><br /> <label for="webclient">Webclient Link</label><input type="text" name="webclient" id="webclient" value="<?php echo $webclient; ?>" /><br /> <label for="forums">Forums Link</label><input type="text" name="forums" id="forums" value="<?php echo $forums; ?>" /><br /> <label for="hiscores">Hiscores Link</label><input type="text" name="hiscores" id="hiscores" value="<?php echo $hiscores; ?>" /><br /> <label for="chatbox">Chatbox Html</label><textarea name="chatbox" rows="3" id="chatbox" value="<?php echo $chatbox; ?>" ></textarea><br /> <label for="staff">Staff Page Link</label><input type="text" name="staff" id="staff" value="<?php echo $staff; ?>" /><br /> <label for="newstitle">News Article Title</label><input type="text" name="newstitle" id="newstitle" value="<?php echo $newstitle; ?>" /><br /> <label for="newsimage">News Article Image Link<span class="small">(Displayed under title)</span></label><input type="text" name="newsimage" id="newsimage" value="<?php echo $newsimage; ?>" /><br /> <label for="news">News Article</label><textarea name="news" rows="3" id="news" value="<?php echo $news; ?>" ></textarea><br /> <label for="op1">Optional Link #1</label><input type="text" name="op" id="op" value="<?php echo $op; ?>" /><br /> <label for="op2">Optional Link #2</label><input type="text" name="opp" id="opp" value="<?php echo $opp; ?>" /><br /> <label for="op3">Optional Link #3</label><input type="text" name="oppp" id="oppp" value="<?php echo $oppp; ?>" /><br /> <input type="submit" value="Send" /> </div> </form> </div> <?php } } else { ?> <div class="message">To access this page, you must be logged.<br /> <a href="connexion.php">Log in</a></div> <?php } ?> <div class="foot"><a href="<?php echo $url_home; ?>">Go Home</a> - <a href="http://www.webestools.com/">Webestools</a></div> </body> </html>Anyway, i hope someone can help me solve this. Thanks HELP ME TO CHANGE THE ERROR <?PHP //Include connection to database include('connect.php'); //Get posted values from form $status=$_POST['status']; $date=$_POST['date']; //Strip slashes $status = stripslashes($status); $date = stripslashes($date); //Strip tags $status = strip_tags($status); $date = strip_tags($date); //Inset into database $insert_status = mysql_query(" insert into status (status) value ('$status')") or die (mysql_error()); $insert_status = mysql_query("insert into status (date) value ('$date')") or die (mysql_error()); while($row = mysql_fetch_array($insert_status)) { (ERROR IS IN THIS LINE) $status=$row['status']; $date=$row['date']; } //Line break after every 80 $status = wordwrap($status, 80, "\n", true); //Line breaks $status=nl2br($status); //Display status from data base echo '<div class="load_status"> <div class="status_img"><img src="blankSilhouette.png" /></div> <div class="status_text"><a href="#" class="blue">Anonimo</a><p class="text">'.$status.'</p> <div class="date">'.$date.' · <a href="#" class="light_blue">Like</a> · <a href="#" class="light_blue">Comment</a></div> </div> <div class="clear"></div> </div>'; ?> Code: [Select] <?php $limit=12; if(isset( $_GET['page'])) $page=$_GET['page']; if($page<=0) $page = 1; else {$start=0;} $sql=mysql_query('select * from tbl_gallery where status=1 AND category_name="0"'); $count=mysql_num_rows($sql); $totalcount=ceil($count/$limit); $start=($page-1)*$limit; $s=mysql_query('select * from tbl_gallery where status=1 AND category_name="0" limit $start, $limit'); while($result=mysql_fetch_array($s)){ $start++; ?> MOD EDIT: code tags added. Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\New\cartnisya.php on line 15 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\New\cartnisya.php on line 74 CODE $db = mysql_connect("localhost", "root",""); mysql_select_db("vinnex",$db); mysql_query("Delete From temptransaction",$db); //mysql_query("Delete From temporderdetails",$db); $Username = $_POST['Username']; $Password = $_POST['Password']; $result = mysql_query("Select TransNo From transaction", $db); $myrow = mysql_fetch_array($result); if ($myrow=='') { $TransNo='1000'; $q = mysql_query("Select Username, Lastname, Firstname From customer where Username=$Username, Lastname=$Lastname, Firstname=$Firstname "); $myrow1 = mysql_fetch_array($q); $Username = $myrow1['Username']; $Firstname = $myrow1['Firstname']; $Lastname = $myrow1['Lastname']; $name = $Firstname. " ".$Lastname; $sql1 = " INSERT INTO temptransaction (TransNo, Username, Firstname, Date) VALUES ('$TransNo', '$Username', '$Firstname', '$Date')"; $result = mysql_query($sql1) or die(mysql_error()); } else { $sql = mysql_query("Select max(TransNo) maxTransNo From transaction", $db); $myrow1 = mysql_fetch_array($sql); $orderno = $myrow1['maxTransNo']+1; $sql = mysql_query("Select Username, Lastname, Firstname From customer where Username=$Username, Lastname=$Lastname, Firstname=$Firstname"); $myrow1 = mysql_fetch_array($sql); $Username = $myrow1['Username']; $Firstname = $myrow1['Firstname']; $Lastname = $myrow1['Lastname']; $Date = date('m/d/y'); $sql1 = " INSERT INTO temptransaction (TransNo, Username, Firstname, Date) VALUES ('$TransNo', '$Username', '$Firstname', '$Date')"; $result = mysql_query($sql1) or die(mysql_error()); } please help masters im just newbie in php. I have that error repeated alot : here are the other errors Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given i n C:\Users\Andrew Hunt\Desktop\iFox.snap\Engines\MySQL\MySQL.php on line 14 Warning: mysql_free_result() expects parameter 1 to be resource, boolean given i n C:\Users\Andrew Hunt\Desktop\iFox.snap\Engines\MySQL\MySQL.php on line 15 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given i n C:\Users\Andrew Hunt\Desktop\iFox.snap\Engines\MySQL\MySQL.php on line 14 Warning: mysql_free_result() expects parameter 1 to be resource, boolean given i n C:\Users\Andrew Hunt\Desktop\iFox.snap\Engines\MySQL\MySQL.php on line 15 The first 20 lines look like this : Code: [Select] final class MySQL { const ASSOC = MYSQL_ASSOC; public static function Connect($func_host, $func_user, $func_pass) { return mysql_connect($func_host, $func_user, $func_pass); } public static function Select($func_database) { return mysql_select_db($func_database); } public static function &Query($func_query) { return mysql_query($func_query); } public static function FetchArray(&$func_res, $func_type) { return mysql_fetch_array($func_res, $func_type); } public static function FreeResult(&$func_res) { return mysql_free_result($func_res); } public static function Error() { return mysql_error(); } public static function GetData($func_statement) { $func_retVal = array(); $func_res = self::Query($func_statement); while($func_line = self::FetchArray($func_res, MySQL::ASSOC)) $func_retVal[] = $func_line; MySQL::FreeResult($func_res); return $func_retVal; } public static function Insert($func_table, $func_data) { Thanks for help and the mysql info is correct.. Hey all, The mysql_query function is failing in the show function and I'm not sure why: function index($item){ db_connect(); $query = "SELECT * FROM $item ORDER BY $item.id DESC"; $result = mysql_query($query); $result = db_result_to_array($result); return $result; } function show($item, $id){ db_connect(); $query = sprintf("SELECT * FROM $item WHERE $item.id = '%s", mysql_real_escape_string($id)); $result = mysql_query($query); $row = mysql_fetch_array($result); return $row; } //Stuff that belongs in view $books = index('books'); foreach($books as $book){ echo $book['title'].'</ br>'; } $book = show('books', 1); echo $book['title'].'</ br>'; Thanks for any response. Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\websiteku\modul\laporan\laporan.php on line 48 $query2 = "SELECT count(*) as jum1 FROM transaksi WHERE nama_kategori = '$namaBidang' AND nama_bayar = Uang"; $hasil2 = mysql_query($query2); $data3 = mysql_fetch_array($hasil2); $jumGol1 = $data3['jum1'];help me guys, how i fix this problem ?? I can't find what's wrong with the code... <?php $Sql = "select team1, team2, t1outcome, t2outcome, winner from coupons where user='$User'"; $Result = mysql_query($Sql, $Link); print "<table cellpadding=0 cellspacing=0 border=0>"; print "<tr>"; print "<td align=left valign=top> </td>"; print "<td align=left valign=top> </td>"; print "</tr>"; while($Row = mysql_fetch_array($Result)){ if($Row[team1] == $Row[winner]){ print "<tr>"; print "<td align=left valign=top> </td>"; print "<td align=left valign=top><bold>$Row[team1]</bold> - $Row[team2] $Row[t1outcome]-$Row[t2outcome]</td>"; print "</tr>"; } else { print "<tr>"; print "<td align=left valign=top> </td>"; print "<td align=left valign=top>$Row[team1] - $Row[team2] $Row[t1outcome]-$Row[t2outcome]</td>"; print "</tr>"; } } print "</table>"; mysql_close($Link); ?> Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\ajaxpages\attendance\student_attendance.php on line 7 <?php $i=1;?> <?php error_reporting();include("../../connect.php"); session_start(); $class_id = $_POST['class_id']; $query = mysql_query("SELECT * FROM attendance WHERE class='$class_id' ORDER BY student ASC "); while($row = mysql_fetch_array($query)) ####LINE 7<---------------------------------------- { ?> <li><div class="num"><?php print $i++?></div><?php print $row['student']; ?></li> <?php }?> Hey, all. I'm new to php/mysql. I'm getting the warning: Quote mysql_fetch_array() expects parameter 1 to be resource, string...line 39 with reference to the mysql_fetch_array function in the following code: mysql_select_db("calculators", $con); $query = "SELECT * FROM calculator WHERE Abbreviation = '" . $_GET['abbreviation'] . "'"; $result = mysql_query($query, $con); while($row = mysql_fetch_array($result)) { //some code... } The code runs fine, but I'd like to know why I'm getting the warning. I've looked at similar post on this forum and other forums and can't quite get a straight answer. Thanks a bunch, Davis hey. im new to php and i get this error and i dnt know how to make it r8.here is my code and also i get undefined index for name/comment/submit but they all seems to work fine.please help <?php require('contact.php'); $name=$_POST["name"]; $comment=$_POST["comment"]; $submit=$_POST["submit"]; if($submit){ if($name&&$comment){ $insQry=mysql_query("INSERT INTO `comment`.`comment` (`name`,`comment`) VALUES ('$name','$comment')"); }else{ echo "pleace Fill All the Fields"; } } ?> <?php $getqry=mysql_query("SELECT * FROM comment ORDER BY id DECS"); while($grows=mysql_fetch_array($getqry)){ $id=$grows['id']; $name=$grows['name']; $comment=$grows['comment']; echo $name . "<br />".$comment."<br />"."<hr />"; } ?> I am getting the below error message: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.9\www\a.php on line 78 The two issues a 1. The red text I need to somehow use the DISTINCT function as it is duplicating a person for every skill they have. 2. The blue text is causing the error above, if I remove the join it works but assigns every possible skill to the person (because skill table and resource table are not joined). I therefore need the join there but without the error. My code is below: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Search Contacts</title> <style type="text/css" media="screen"> ul li{ list-style-type:none; } </style> </head> <p><body> <h3>Search Contacts Details</h3> <p>You may search either by first or last name</p> <form method="post" action="a.php?go" id="searchform"> <input type="text" name="name"> <input type="submit" name="submit" value="Search"> </form> <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ $name=$_POST['name']; //connect to the database $db=mysql_connect ("127.0.0.1", "root", "") or die ('I cannot connect to the database because: ' . mysql_error()); //-select the database to use $mydb=mysql_select_db("resource matrix"); //-query the database table $sql="SELECT * FROM ((resource l inner join resource_skill ln on l.Resource_ID = ln.Resource_ID) inner join skill n on ln.Skill_ID = n.Skill_ID) WHERE First_Name LIKE '%" . $name . "%' OR Last_Name LIKE '%" . $name ."%' OR Skill_Name LIKE '%" . $name ."%'"; //-run the query against the mysql query function $result=mysql_query($sql); //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $First_Name =$row['First_Name']; $Last_Name=$row['Last_Name']; $Resource_ID=$row['Resource_ID']; //-display the result of the array echo "<ul>\n"; echo "<li>" . "<a href=\"a.php?id=$Resource_ID\">" .$First_Name . " " . $Last_Name . "</a></li>\n"; echo "</ul>"; } } else{ echo "<p>Please enter a search query</p>"; } } } //end of our letter search script if(isset($_GET['id'])){ $contactid=$_GET['id']; //connect to the database $db=mysql_connect ("127.0.0.1", "root", "") or die ('I cannot connect to the database because: ' . mysql_error()); //-select the database to use $mydb=mysql_select_db("resource matrix"); //-query the database table $sql="SELECT * FROM ((resource l inner join resource_skill ln on l.Resource_ID = ln.Resource_ID) inner join skill n on ln.Skill_ID = n.Skill_ID) WHERE Resource_ID=" . $contactid; //-run the query against the mysql query function $result=mysql_query($sql); //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $First_Name =$row['First_Name']; $Last_Name=$row['Last_Name']; $Mobile_Number=$row['Mobile_Number']; $Email_Address=$row['Email_Address']; $Level=$row['Level']; $Security_Cleared=$row['Security_Cleared']; $Contract_Type=$row['Contract_Type']; $Contract_Expiry=$row['Contract_Expiry']; $Day_Rate=$row['Day_Rate']; $Post_Code=$row['Post_Code']; $Skill_Name=$row['Skill_Name']; //-display the result of the array echo "<ul>\n"; echo "<li>" . $First_Name . " " . $Last_Name . "</li>\n"; echo "<li>" . $Mobile_Number . "</li>\n"; echo "<li>" . "<a href=mailto:" . $Email_Address . ">" . $Email_Address . "</a></li>\n"; echo "<li>" . $Level . "</li>\n"; echo "<li>" . $Security_Cleared . "</li>\n"; echo "<li>" . $Contract_Type . "</li>\n"; echo "<li>" . $Contract_Expiry . "</li>\n"; echo "<li>" . $Day_Rate . "</li>\n"; echo "<li>" . $Post_Code . "</li>\n"; echo "<li>" . $Skill_Name . "</li>\n"; echo "</ul>"; } } ?> </body> </html> Full error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\MyWebsite\poll\functions.php on line 28 Been working all day to set up some stuff in my website. Now currently working on the poll. Been stuck on this error and I don't know what to do. That's the function that throws this: Any help would be appreciated. Code: [Select] function getPoll($pollID){ $query = "SELECT * FROM polls LEFT JOIN pollAnswers ON polls.pollID = pollAnswers.pollID WHERE polls.pollID = " . $pollID . " ORDER By pollAnswerListing ASC"; $result = mysql_query($query); //echo $query;jquery $pollStartHtml = ''; $pollAnswersHtml = ''; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $pollQuestion = $row['pollQuestion']; $pollAnswerID = $row['pollAnswerID']; $pollAnswerValue = $row['pollAnswerValue']; if ($pollStartHtml == '') { $pollStartHtml = '<div id="pollWrap"><form name="pollForm" method="post" action="poll/functions.php?action=vote"><h3>' . $pollQuestion .'</h3><ul>'; $pollEndHtml = '</ul><input type="submit" name="pollSubmit" id="pollSubmit" value="Vote" /> <span id="pollMessage"></span></form><>'; } $pollAnswersHtml = $pollAnswersHtml . '<li><input name="pollAnswerID" id="pollRadioButton' . $pollAnswerID . '" type="radio" value="' . $pollAnswerID . '" /> ' . $pollAnswerValue .'<span id="pollAnswer' . $pollAnswerID . '"></span></li>'; $pollAnswersHtml = $pollAnswersHtml . '<li class="pollChart pollChart' . $pollAnswerID . '"></li>'; } echo $pollStartHtml . $pollAnswersHtml . $pollEndHtml; } This is a new error for me. I tried looking through some older posts and so far nothing had fixed it and thus I am stumped. Any idea what could be throwing this error? Code: [Select] <table> <?php //open DB connection include 'dbconn.php'; $sql = "select * tbl_test"; $result = mysql_query($sql,$conn); print $sql; while ($row = mysql_fetch_array($result)){ $status = $row['status']; $space = $row['spacename']; if ($status=="reserved") { echo <<<END <tr> <td style="background-color:#F00; color:#FFF;" align="center">Reserved</td> </tr> END; } else { echo <<<END <tr> <td align="center">$space</td> </tr> END; } } ?> </table> <?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 Hi! So I'm working for someone, and they want me to fix this error in a PHP file.. Here is the code: <?php include_once('config.php'); $online = mysql_query("SELECT * FROM bots WHERE status LIKE 'Online'"); $offline = mysql_query("SELECT * FROM bots WHERE status LIKE 'Offline'"); $dead = mysql_query("SELECT * FROM bots WHERE status LIKE 'Dead'"); $admintrue = mysql_query("SELECT * FROM bots WHERE admin LIKE 'True'"); $adminfalse = mysql_query("SELECT * FROM bots WHERE admin LIKE 'False'"); $windows8 = mysql_query("SELECT * FROM bots WHERE so LIKE '%8%'"); $windows7 = mysql_query("SELECT * FROM bots WHERE so LIKE '%7%'"); $windowsvista = mysql_query("SELECT * FROM bots WHERE so LIKE '%vista%'"); $windowsxp = mysql_query("SELECT * FROM bots WHERE so LIKE '%xp%'"); $unknown = mysql_query("SELECT * FROM bots WHERE so LIKE 'Unknown'"); $totalbots = mysql_num_rows(mysql_query("SELECT * FROM bots")); $onlinecount = 0; $offlinecount = 0; $deadcount = 0; $admintruecount = 0; $adminfalsecount = 0; $windows8count = 0; $windows7count = 0; $windowsvistacount = 0; $windowsxpcount = 0; $unknowncount = 0; while($row = mysql_fetch_array($online)){ $onlinecount++; } while($row = mysql_fetch_array($offline)){ $offlinecount++; } while($row = mysql_fetch_array($dead)){ $deadcount++; } while($row = mysql_fetch_array($admintrue)){ $admintruecount++; } while($row = mysql_fetch_array($adminfalse)){ $adminfalsecount++; } while($row = mysql_fetch_array($windows8)){ $windows8count++; } while($row = mysql_fetch_array($windows7)){ $windows7count++; } while($row = mysql_fetch_array($windowsvista)){ $windowsvistacount++; } while($row = mysql_fetch_array($windowsxp)){ $windowsxpcount++; } while($row = mysql_fetch_array($unknown)){ $unknowncount++; } $statustotal = $onlinecount + $offlinecount + $deadcount; $admintotal = $admintruecount + $adminfalsecount; $sototal = $windows7count + $windowsvistacount + $windowsxpcount + $unknowncount; ?> Can anyone tell me the error here, can how to fix it? Hi Guys, I have been working on a recursive select box that will allow sub-categories and keep getting the error: <b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>test.php</b> on line <b>22</b><br / i have a table as follows: Code: [Select] CREATE TABLE IF NOT EXISTS `ost_help_topic` ( `topic_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `isactive` tinyint(1) unsigned NOT NULL DEFAULT '1', `noautoresp` tinyint(3) unsigned NOT NULL DEFAULT '0', `priority_id` tinyint(3) unsigned NOT NULL DEFAULT '0', `dept_id` tinyint(3) unsigned NOT NULL DEFAULT '0', `CatParent` bigint(11) unsigned DEFAULT NULL, `topic` varchar(32) NOT NULL DEFAULT '', `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`topic_id`), UNIQUE KEY `topic` (`topic`), KEY `priority_id` (`priority_id`), KEY `dept_id` (`dept_id`) ) Code: [Select] <?php $db_host = "localhost"; $db_un = "user"; $db_pass = "pass"; $Item_DB = "data"; $table = "ost_help_topic"; $link = mysql_connect($db_host, $db_un, $db_pass); $tab = " "; // this is 8 spaces, which works as a pseudo-tab character inside the <option>s $tablvl = 1; function print_kids($pos) { // $pos is the current position inside the hierarchy (curr item's ID) global $link; global $tab; global $tablvl; $pos = ($pos?$pos:null); $query = "SELECT * from $table WHERE isactive=1 AND CatParent".($pos == null ? " IS NULL" : "=".$pos); // NULL parent == top level item. For 0-parents, replace " IS NULL" with "=0" $res = mysql_db_query($Item_DB, $query, $link); if (!$res) print(mysql_error()); while($row = mysql_fetch_array($res)) { $has_kids = mysql_fetch_array(mysql_db_query($Item_DB, "SELECT * from $table where isactive=1 AND CatParent=$row[0]", $link)) != null; print("<option value=\"$row[0]\">"); for ($i=0; $i<$tablvl; $i++) print($tab); print("$row[6]</option>\n"); if ($has_kids) { $tablvl++; print_kids($row[0]); // <span class="posthilit">recursive</span> call $tablvl--; } } } $numrows = 1; $res = mysql_db_query($Item_DB, "SELECT * FROM $table", $link); while (mysql_fetch_array($res)) $numrows++; // Yes, I'm sure there's a more efficient way to do this <img src="./images/smilies/icon_razz.gif" alt=":P" title="Razz" /> print("<select name=\"hierarchy\" size=\"$numrows\">\n"); print("<option value=\"null\" selected=\"selected\">Root of all items</option>\n"); print_kids(0); print("</select>"); mysql_close($link); ?> |