PHP - Extract() Expects Parameter 1 To Be Array, Help Please
I'm a newbie . I've been stuck on this error message for 2 days:
I get this error message: extract() expects parameter 1 to be array, boolean given in C:\x\xampp\htdocs\user_personal.php on line 30 Code: [Select] <?php $query = 'SELECT about_me, job, hobbies, contact FROM site_user u JOIN site_user_profile p ON u.user_id = p.user_id WHERE username = "' . mysql_real_escape_string($_SESSION['username'], $db) . '"'; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_array($result); extract($row); mysql_free_result($result); mysql_close($db); ?> I think joining table is hard, I just want to create a profile that would be linked to a user name. Please be my friend and help me so I can have PHP phun time. Similar TutorialsProblem: "Warning: extract() expects parameter 1 to be array, null given in C:\x\xampp\htdocs\pages\user_personal.php on line 32" - error also found on lines 33 and 38. and none of the information is displayed. Goal: I'm trying to retrieve profile information and multiple user inserted pictures and display the pictures through a while loop from one query. <?php $query = 'SELECT u.name_id, i.bio, i.exhib, p.product_code FROM user u LEFT JOIN profile i ON u.name_id = i.name_id LEFT JOIN ecomm_products p ON u.name_id = p.product_code WHERE u.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '" and p.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '"'; $result = mysql_query($query, $db) or die(mysql_error()); extract($bio); //line 32 extract($exhib); //line 33 $odd = true; while ($row = mysql_fetch_array($result)) { echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">'; $odd = !$odd; extract($rows); line 38 echo '<td><a href="' . $dir . '/' . $row['product_code'] . '.jpg">'; echo '<img src="' . $thumbdir . '/' . $row['product_code'] . '.jpg">'; echo '</a></td>'; echo '</tr>'; } echo "</table>"; echo "<p>"; ?> <ul> <li>Biography: <?php echo $bio; ?></li> <li>Exhibitions: <?php echo $exhib; ?></li> </ul> Hi, Am hoping someone can please help. I've the following code: $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); $chosen_method = explode(':', reset($chosen_methods) );
The first line returns the warning: I've tried the following: $chosen_method = ''; $chosen_method = NULL; $chosen_methods = array(); Sadly, none have worked. What am I missing? Thanks PHP Warning: file_exists() expects parameter 1 to be string, array given in /home/mysite/public_html/display.mysite.com/wp-content/themes/mytheme/form.php on line 9 PHP Warning: file_exists() expects parameter 1 to be string, array given in /home/mysite/public_html/display.mysite.com/wp-content/themes/mytheme/form.php on line 13I have a form that is having some issues and in the error log I see a bunch of these warnings. What is wrong with this?? I numbered the offending lines below (lines 9 & 13) Thanks for any help on this. function CheckExistance($VUrl) { /*9*/ if ( file_exists($VUrl) ) echo $VUrl; /*13*/ elseif ( file_exists(str_replace('www.display.mysite.com','www.display.com', $VUrl)) ) echo str_replace('www.display.mysite.com','www.mysite.com', $VUrl); else echo str_replace('www.mysite.com','www.display.mysite.com', $VUrl); } Edited by damion, 02 July 2014 - 06:01 PM. if($pid != "") { $bname = $_REQUEST['bname']; $btitle = $_REQUEST['btitle']; $btags = $_REQUEST['btags']; $bdesc = $_REQUEST['bdesc']; $btext = $_REQUEST['btext']; $bimg = $_REQUEST['bimg']; $bimgalt = $_REQUEST['bimgalt']; $data = ""; if($bname!="") { $data = $data." 'bname' => ".$bname.", "; } if($btitle!="") { $data = $data."'btitle' => ".$btitle.", "; } if($btags!="") { $data = $data."'btags' => ".$btags.", "; } if($bdesc!="") { $data = $data."'bdesc' => ".$bdesc.", "; } if($btext!="") { $data = $data."'btext' => ".$btext.", "; } if($bimg!="") { $data = $data."'bimg' => ".$bimg.", "; } if($bimgalt!="") { $data = $data."'bimgalt' => ".$bimgalt.", "; } $data = $data."'pid ' =>". $pid.", " ; $data = "[".$data."]"; $build = ""; if($bname!="") { $build = $build." page_name = :bname,"; } if($btitle!="") { $build = $build." page_title = :btitle,"; } if($btags!="") { $build = $build." page_tags = :btags,"; } if($bdesc!="") { $build = $build." page_desc = :bdesc,"; } if($btext!="") { $build = $build." page_text = :btext,"; } if($bimg!="") { $build = $build." page_img = :bimg,"; } if($bimgalt!="") { $build = $build." page_imgalt = :bimgalt,"; } $build = $build." page_id = :pid"; $sql = "UPDATE pages SET ".$build." WHERE page_id=:pid"; echo $sql."<br /><br />"; echo $data."<br /><br />"; $stmt= $pdo->prepare($sql); $stmt->execute($data); Result of echo SQL and Data
UPDATE pages SET page_name = :bname, page_title = :btitle, page_tags = :btags, page_desc = :bdesc, page_text = :btext, page_img = :bimg, page_imgalt = :bimgalt, page_id = :pid WHERE page_id=:pid Market Net is the place for you to find those goodies you saw on the markets, buy them online and support small local businesses. Watch this space for more information. Test #D hvac , 'bimg' => supportlocal.jpg, 'bimgalt' => Support Local Small Businesses, 'pid ' =>106, ] Yet I am getting said error message. What am I doing wrong? I am trying to create a simple voting form. Everything goes well until I submit and then I get a Warning: mysqli_error() expects exactly 1 parameter, 0 given on line 79 error. I am assuming it is not pulling the ID correctly but as I am new to php and mysqli I cannot exactly say if it the way the code is written or if I am calling the parameter incorrectly in the query. Again I am new to to this so please be gentle. Below is my code. It pulls the drop down list correctly and echo's correctly but I believe my post query to be a little out of wack. Could someone point me in the correct direction? It would be very appreciated.
<form action="businesstype_update.php" method="post"> <?php if(isset($_POST['voteall'])){ $vote_lg = "update membertest where id={$row_lg['id']} set vote=vote+1"; $run_lg = mysqli_query($con, $vote_lg) or die(mysqli_error()); } $result_lg = mysqli_query($con, "SELECT id, business FROM membertest WHERE businesstype='large'"); echo "Vote for large business of the year! <SELECT name='business'>\n"; echo "<option>Select a large business</option>"; while($row_lg = $result_lg->fetch_assoc()) { echo "<option value='{$row_lg['id']}'>{$row_lg['business']}</option>\n"; } echo "</select></br></br>\n"; echo "<input type='submit' name='voteall' value='voteall'>"; $result_lg->close(); $con->close(); May I know what does this mean, this is the code which they are referring to. I have tried troubleshooting, still could not find the cause, appreciate if anyone can help? Thanks Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\inetpub\vhosts\championtutor.com\httpdocs\inc\elements\t_reg_post1.php on line 204 /**INSERT into tutor_musical_background table**/ foreach($musics as $music) { $query6 = "INSERT INTO tutor_musical_background (tutor_id, musical_instrument_id) VALUES ('$tutor_id', '$music')"; $results6 = mysqli_query($dbc, $query6) or die(mysqli_error()); i get this error Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\website\viewvideos.php on line 25 Code: [Select] $addviews = $views + 1; $query = mysql_query("UPDATE headlines SET views='$addviews' WHERE id=$viewid"); $rows = mysql_fetch_assoc($query); i dont get whats wrong Hi all, I have received this error, and I could clearly recall I did not actually change any content in the file. May I know how should I debug it? Thanks Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\inetpub\vhosts\abc.com\httpdocs\inc\php\tutor\t_reg_post1.php on line 163 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 ?> 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"; } I keep getting this error when I run the following code: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\vitamin-k-tracker\my-meal-planner.php on line 29 Code: [Select] <?php include 'top.php'; ?> <?php if (!loggedin()) {//1 if start header('Location: need-to-log-in-mmp.php'); }//1 if end ?> <title>My Meal Planner - Vitamin K Tracker</title> </head> <div id="container"> <?php include 'header.php'; ?> <?php include 'nav.php'; ?> <?php //do sql query to return the foods and nutrients that a person added to their que // // we're doing a left join between the foods and user foods table connected by the id $queryc = "SELECT `foods.id`, `foods.name`, `foods.source`, `users_foods.food_id` FROM `foods` LEFT JOIN users_foods ON foods.id=users_foods.food_id"; $query_runc = mysql_query($queryc); //error on the line below: while ($rowc = mysql_fetch_array($query_runc)){ echo 'ok'; } ?> <div id="content-container"> <div id="content_for_site"> <h2>My Meal Planner</h2> <br /> My Meal Que: <br /> <ul> <form> <li><input type="checkbox" name="meal_one" value="meal_one" /> Meal One</li> How many servings will you have? <input type="text" name="meal_one_servings"><br /><br /> <li><input type="checkbox" name="food_one" value="food_one" /> Food One</li> How many servings will you have? <input type="text" name="meal_one_servings"> </form> </ul> <input type="submit" value="delete" name="delete"><br /> <input type="submit" value="add to calendar" name="add_to_calendar"> <br /><br /> <a href="create-a-meal.php">Create A Meal & add to your Meal Que</a><br /> <a href="find-a-meal.php">Find a Meal or Food to Add to your Meal Que</a> </div> <div id="clear"></div> <?php include 'footer.php'; ?> </div> </div> Hi, I'm by no means an expert in php but I use and continually try and figure out how to update some very old soccer stats scripts that break from time to time when newer versions of php are released. Anyway, I would appreciate any pointers with this error please: Warning: mysqli_query() expects parameter 3 to be integer, object given in /blah/blah/blah.php on line 81 The code is: 79 - mysqli_query($connection,"INSERT INTO seasons SET 80 - SeasonID = '$seasonid', 81 - SeasonPlayerID = '$player_id'",$connection) 82 - or die(mysqli_error($connection)); Server is running php 7.2.28 Thanks in advance. 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. } After overcoming this-> error "Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the futu use mysqli or PDO instead in this-> $myconnection = mysql_connect($server, $user, $pass);" by changing mysql_query to mysqli_query($con, $query), I started getting this specific error on line 106= $result = mysqli_query($myconnection, $query) or $this->debugAndDie($query);
Warning: mysqli_query() expects parameter 1 to be mysqli, null given on line 106=="$result = mysqli_query($myconnection, $query) or $this->debugAndDie($query);"
This header wont go, I tried $myconnection = mysql_connect($query); and it says expecting 2 parameters.
Please I'm open to ideas to solve this,
<snip - code is posted in next post>
Edited by mac_gyver, 05 June 2014 - 03:28 PM. removed code not in code tags as the op posted it later 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 Hi guys, I received an error, could anyone explain this current error? Thanks Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in D:\inetpub\vhosts\championtutor.com\httpdocs\questionnaire.php on line 32 Hello im geting this error what im ding wrong? Code: [Select] PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/admincom/public_html/tsue/library/plugins/movie_plugin.php on line 7 line 7 is: while ($row = mysqli_fetch_array($sql)) { code he Code: [Select] $query = mysqli_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB); $sql = mysqli_query($query, "SELECT `membername`, `filename`, `tid`, `info_hash`, `name`, `description`, `cid`, `size`, `added`, `leechers`, `seeders`, `times_completed`, `owner`, `options`, `nfo`, `sticky`, `flags`, `mtime`, `ctime`, `download_multiplier`, `upload_multiplier` FROM `tsue_members`, `tsue_torrents`, `tsue_attachments` WHERE `memberid`='owner' AND `content_type`='torrent_images' AND `content_id` = `tid` LIMIT 0, 10"); while ($row = mysqli_fetch_array($sql)) { $movie_plugin_row = ''; $uploader = $row['membername']; $description= $row['description']; $dydis= $row['size']; $name= $row['name']; $leechers= $row['leechers']; $owner= $row['owner']; $filename= $row['filename']; $nunx= $row['tid']; $seeders= $row['seeders']; eval("\$movie_plugin_row = \"".$TSUE['TSUE_Template']->LoadTemplate('movie_plugin_row')."\";"); $movie_plugin .= $movie_plugin_row; } I've just started to learn PHP and I'm having a little trouble. I'm trying to stick with OOP but I'm having trouble with it. I've coded a database connection and I'm trying to take data from a form and insert it into a database. I've managed to do it without OOP but I can't get it to work with. The code is below. Any help would be great. I have a file for the form, which should take the data and the php should insert it into the table - <?php // Get the PHP file containing the dbConnect class require('../../configuration.php'); // Get the PHP file containing the dbConnect class require('../../lib/db.class.php'); // Checks whether a form has been submitted. If so, carry on if ($_POST) { // Creates an instance of dbConnect $link = new dbConnect(); // Creates a SQL query $insertQuery = 'INSERT INTO content SET title = "' . $_POST['title'] . '", alias = "' . $_POST['alias'] . '", category = "' . $_POST['category'] . '", summary = "' . $_POST['summary'] . '", content = "' . $_POST['content'] . '"'; $result = $link->query($insertQuery, $link); } ?> <body> <form action="" method="post"> <div> <label for="title">Title:</label> <textarea id="title" name="title" rows="1" cols="30"> </textarea> </div> <div> <label for="alias">Alias:</label> <textarea id="alias" name="alias" rows="1" cols="30"> </textarea> <div> <label for="category">Category:</label> <textarea id="category" name="category" rows="1" cols="30"> </textarea> </div> <div> <label for="summary">Summary:</label> <textarea id="summary" name="summary" rows="6" cols="40"> </textarea> </div> <div> <label for="content">Content:</label> <textarea id="content" name="content" rows="12" cols="40"> </textarea> </div> <div> <input type="submit" value="Add Article" /> </div> </form> This is my class to connect to the db - class dbConnect extends siteConfig { var $theQuery; var $link; // Function to connect to the database public function dbConnect() { // Load configuration from parent class $config = siteConfig::getConfig(); // Get main config settings from the array that we just loaded $host = $config['hostname']; $user = $config['username']; $pass = $config['password']; $db = $config['database']; // Connect to the DB $link = mysql_connect('localhost', 'user', 'pass'); if (!$link) { $error = 'Unable to connect to the database server.'; echo $error; exit(); } } // Function to execute a database query public function query($link, $query) { $this->theQuery = $query; mysql_query($this->link, $query); } // Function to get array of query results public function getArray($result) { return mysql_fetch_array($result); } // Function to close the connection public function closeConnection() { mysql_close($this->link); } } I also have a config file. I'm not using it atm but I thought I'd show it anyway as it may help - class siteConfig { var $config; function getConfig() { $config['site_url'] = 'localhost/edencms'; $config['hostname'] = 'localhost'; $config['username'] = 'user'; $config['password'] = 'pass'; $config['database'] = 'edencms'; } } After filling out the form and sending it, I get the following error: Quote Warning: mysql_query() expects parameter 2 to be resource, object given in C:\xampp\htdocs\EdenCMS\lib\db.class.php on line 39 It seems like $link isn't staying as a resource once the dbConnect is called. If I print it in the dbConnect function, it shows it's a resource but if I try to print it after, it shows as an object. I'm not sure why. As I said, I'm new, so go easy |