PHP - Reset() Expects Parameter 1 To Be Array, Null Given
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 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 Hey guys,
Earlier I mentioned making search criteria in my database. I also had to put in something to make it add to the database. I made some code like this:
<form id="form" name="form" method="post" action="Website2.php"> <p> <label for="Genre">Genre</label> <input type="text" name="Genre" id="Genre" /> </p> <p> <label for="Naam">Naam</label> <input type="text" name="Naam" id="Naam" /> </p> <p> <label for="Jaar">Jaar</label> <input type="text" name="Jaar" id="Jaar" /> </p> <p> <label for="Regisseur">Regisseur</label> <input type="text" name="Regisseur" id="Regisseur" /> </p> <p> <input type="submit" name="Verzenden" id="Verzenden" value="Verzenden" /> </p> </form> <?php $Genre = $_POST["Genre"]; $Naam = $_POST["Naam"]; $Jaar = $_POST["Jaar"]; $Regisseur = $_POST["Regisseur"]; /*Hier hoeft geen verbinden meer gemaakt te worden met de database*/ if (isset($_POST['Verzenden']) && trim($_POST['Verzenden'])!=''){ $sql = "INSERT INTO Movies (Genre, Naam, Jaar, Regisseur) VALUES ('$Genre', '$Naam', '$Jaar', '$Regisseur')"; $resultaat = mysqli_query($db, $sql); $verbreken = mysqli_close($db); echo "De gegevens van $Naam zijn opgeslagen in de database.";} else echo 'Hier kunt u iets toevoegen'; ?>However it didn't work. I got the problem "Warning: mysqli_query() expects parameter 1 to be mysqli, null given in... on line 119" Can you guys 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. Problem: "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> 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()); 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 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 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 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. 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 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 I'm an extreme newbie and have this current error on my site. The error states: Warning: mktime() expects parameter 4 to be long, string given in featured_product.php on line 75 <?php for ($i = 0; $i < $num_rows; $i++) { $id = mysql_result($result,$i,"id"); $title = mysql_result($result,$i,"title"); $featured = mysql_result($result,$i,"featured"); $feature_date = mysql_result($result,$i,"feature_date"); $feature_date_arr = explode("-",$feature_date); $feat_date = mktime(0,0,0,$feature_date_arr[0],$feature_date_arr[1],2000+$feature_date_arr[2]); if ( ($feat_date+($featured*24*60*60))<time() ) { $db2->query("UPDATE product_catalog SET featured = 0 WHERE id='$id'"); $featured = 0; } else { $featured = 1; $db2->query("UPDATE product_catalog SET featured = 1 WHERE id='$id'"); } ?> Any ideas on how to correct this? Thanks! 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> 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; } 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. } 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"; } |