mysqli

Search mysqli table with form and display results

老子叫甜甜 提交于 2021-02-16 21:30:56
问题 I'm searching a table with a form where the result could be from any of the 3 choices (cata, catb or catc) and then display the results, however my error warning keeps popping up and can't display the result? I'm stuck... <?php include("config.php"); $cata = $_POST['cata']; $catb = $_POST['catb']; $catc = $_POST['catc']; $query = "SELECT * FROM photos WHERE cata=? OR catb=? OR catc=?"; $conn = $db->prepare($query); $conn->bind_param("sss", $cata, $catb, $catc); if ($conn->execute()) { $result

How to get affected rows using mysqli?

醉酒当歌 提交于 2021-02-16 20:09:05
问题 I create function for make query in database: function mysqli($query){ $mysqli = new mysqli('test','test','test','test'); if (mysqli_connect_errno()) { printf("Bad connect: %s\n", mysqli_connect_error()); exit(); } $result = $mysqli->query("SET NAMES utf8"); $result = $mysqli->query("set character_set_client='utf8'"); $result = $mysqli->query("set collation_connection='utf8_general_ci'"); $result = $mysqli->query($query); $mysqli->close(); return $result; }; In next step I want get count

How to fix Trying to access array offset on value of type null error

↘锁芯ラ 提交于 2021-02-16 15:24:05
问题 I am creating a time table view using PHP, in which I am getting the lecture data according to the day and time. Here is the code which I have did $monday_lectures = "SELECT * from lectures where lecture_time = '11am to 1pm' and lecture_day = 'firday'"; $result_11to1 = mysqli_query($con, $monday_lectures); $m11to1 = mysqli_fetch_array($result_11to1); if ($m11to1["lecture_day"] == !'') { echo "<td>".$m11to1["lecture_name"]."</td>"; } else { echo "<td> no class</td>"; } But I am getting below

Loop mysqli_result

女生的网名这么多〃 提交于 2021-02-15 05:27:57
问题 I can't seem to figure out how to loop through the rows in this object array. For example, how would I echo the value in each row? $sql = "SELECT my_ids FROM manager WHERE is_live = 0"; $result = $db->query($sql); When I print_r($result); I get mysqli_result Object ( [current_field] => 0 [field_count] => 1 [lengths] => [num_rows] => 15 [type] => 0 ) 回答1: Try to loop on $result with foreach loop: <?php foreach($result as $key => $val) { echo "key is=> ".$key." and Value is=>".$val; } Keys will

How to get single column values using MySQLi?

孤街醉人 提交于 2021-02-13 05:44:08
问题 I am trying to get list or emails in a one-dimensional array from MySQL database. However, I am getting multidimensional array, rather then array: $query = "SELECT DISTINCT `EmailAddress` FROM `Emails` WHERE `JobID` = 1"; $result = $conn->query($query); if (!$result) { printf("Query failed: %s\n", $mysqli->error); exit; } while ($row = $result->fetch_row()) { $rows[] = $row; } $result->close(); $conn->close(); var_dump($rows); // This will return array(2) { [0]=> array(1) { [0]=> string(24)

PHP 7.4 and MySQL Connections

折月煮酒 提交于 2021-02-11 17:08:44
问题 I had posted this on another forum thinking that it was Ubuntu-related and MySQL wasn't playing nicely with PHP but then I realized that mysqli is indeed loading and communicating with it as phpinfo() shows that mysqli is running so the problem I've been having seems to relate to a change in PHP version 7.4 in the way it connects to the database. It is apparently related to the password so what changes to it would have to be made for it to work even if not backwards compatible? My local

PHP 7.4 and MySQL Connections

放肆的年华 提交于 2021-02-11 17:07:58
问题 I had posted this on another forum thinking that it was Ubuntu-related and MySQL wasn't playing nicely with PHP but then I realized that mysqli is indeed loading and communicating with it as phpinfo() shows that mysqli is running so the problem I've been having seems to relate to a change in PHP version 7.4 in the way it connects to the database. It is apparently related to the password so what changes to it would have to be made for it to work even if not backwards compatible? My local

Error: JSON.parse: unexpected non-whitespace character after JSON data

五迷三道 提交于 2021-02-11 15:52:08
问题 I have a problem with Json pars, I have seen tons of users had this problem I saw them all but I couldn't understand where my error is in my code! Sorry if this is duplicate! First file index.html: This is in the head section of the file: <script type="text/javascript"> function ajax_json_data(){ var databox = document.getElementById("databox"); var field1 = document.getElementById("field1").value; var results = document.getElementById("results"); var x = new XMLHttpRequest(); x.open( "POST",

Error: JSON.parse: unexpected non-whitespace character after JSON data

一世执手 提交于 2021-02-11 15:50:27
问题 I have a problem with Json pars, I have seen tons of users had this problem I saw them all but I couldn't understand where my error is in my code! Sorry if this is duplicate! First file index.html: This is in the head section of the file: <script type="text/javascript"> function ajax_json_data(){ var databox = document.getElementById("databox"); var field1 = document.getElementById("field1").value; var results = document.getElementById("results"); var x = new XMLHttpRequest(); x.open( "POST",

Use PHP MySQLi prepared statements without references?

限于喜欢 提交于 2021-02-11 12:35:12
问题 Is there a way to use MySQLi prepared statements without passing references? [Background: I'm extremely new to PHP and to MySQL but I inherited a private WordPress plugin to maintain and so I'm learning both as I go.] I understand that prepared statements are useful for preventing SQL injections and potentially also for speeding up queries (if the statements are kept around) but the need for referenced variables seems odd. Is the idea that one calls bind_param up front and then when making