Successful query execution is achieved in phpMyAdmin but fails when attempted in PHP

Is there a reason why a query in PHP may not return the same data as it does in phpMyAdmin SQL?

$query = "UPDATE `boards` SET `contestPlaces`=0, `contestPlacesFilled`=0";  
$result = mysql_query($query) or die("ERROR:QUERY_FAILED timeset 8" . mysql_error()); 

$query = "UPDATE `playerspoints` SET `points`=0";   
$result = mysql_query($query) or die("ERROR:QUERY_FAILED timeset 9" . mysql_error());

$query = "SELECT `avatarId`, `points` FROM `contestants`"; 
$result = mysql_query($query) or die("ERROR:QUERY_FAILED timeset 10" . mysql_error());

$qualified = array();

while($row = mysql_fetch_row($result));
{
    print_r($row);
    $qualified[] = $row;
} `

Result: Array ( [0] => ) SUCCESS.

There are no errors being returned, but the result is empty. In contrast, the query runs successfully in phpMyAdmin SQL tab. I am connected to the database correctly as I have run queries before this one. This particular query fails without an apparent reason. What steps should I take to identify what's going wrong?

The user I am connected with has the following privileges:

SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, CREATE VIEW, EVENT, TRIGGER, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EXECUTE

Answer №1

Get rid of the semicolon in this code snippet:

while($row = fetch_assoc($result))
                                      ^

Answer №2

//Here is the most recent code snippet in PHP version 5.7.14 that connects to a database, however, it was not functioning correctly. //After investigating, I discovered that the database collation was set to 'latin_swedish' instead of 'utf_general_ci'. //It's crucial to pay attention to even small mistakes as they can impact your entire project.

<?php
$mysqli_hostname = "localhost";
$mysqli_user = "root";
$mysqli_password = "krunal";
$mysqli_database = "krunal";
$bd = mysqli_connect($mysqli_hostname, $mysqli_user,  $mysqli_password,$mysqli_database);  
if(mysqli_connect_errno()){die("database connection  failed");}
?>

<?php 
$sql= "SELECT * FROM `done`;";
$result=mysqli_query($bd,$sql);
if(!$result){
die("database query failed". mysqli_connect_error()."    (".mysqli_connect_errno().")");}?>

<?php while($row=mysqli_fetch_row($result)){
var_dump($row); }?>

<?php mysqli_close($bd);?>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to utilize req.query, req.params, or req.* beyond its original scope without the need to store it in a database?

Looking to streamline my code and apply the DRY pattern, I've been working on creating a helper function for my express http methods. The structure of each method is similar, but the req.params format varies between them. Here's how I attempted t ...

Is it possible to pass a parameter to a PHP controller using JavaScript without relying on jQuery or AJAX?

Is it possible to achieve the task at hand? That's the main question here. My goal is to extract data from a popup window and then, upon closing it, send this extracted content to a PHP controller for further processing. I'm facing conflicts wi ...

Enable access for Google to only one specific folder while restricting access to the rest of the website

UPDATE: I'm not satisfied with using robots.txt for this. This code snippet blocks the entire site from Google. I need a way to keep this code working while still allowing Google to access one specific folder on the site. RewriteEngine On RewriteBas ...

Querying data from a MYSQL database using the SELECT and WHERE

Can someone help me retrieve the content of a single cell in my table using this code? session_start(); $username = $_SESSION["username"]; // Establish database connection mysql_connect("localhost", "root", "*!#@%#") or die(mysql_error()); // Select Dat ...

PHP is having trouble updating the database when multiple radio buttons are selected. It appears that only the most recent radio button selected will be updated in the database

In my form, there are 2 numbers and 4 radio buttons for each. Only one option can be selected per number. When the form is submitted, only the database for question 2 will be updated. However, if question 2 is left blank, then question 1's database w ...

The route to /admin is unreachable with Laravel

Recently, I began a new project using Laravel 5.7 and implemented the standard Laravel Auth with artisan. As part of this process, a new route was added to routes/web.php as shown below: Route::get('/home', 'HomeController@index')-> ...

No files were found in the request when using PHP's cURL

I need assistance in converting this curl request to PHP. curl -X POST -F "file=@test_img.jpg" "http://127.0.0.1:5000/FileUploading/UploadImage/"test_img.jpg" The above curl request works properly with the following flask-RESTful code class UploadImage( ...

Is there a requirement to download and set up any software in order to utilize Highchart?

I've been working on a project to create a program that displays highcharts, but all I'm getting is a blank page. Here's my code: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charse ...

transmitting information using dataURL

Hey there! So I've got this code that does a neat little trick - it sends a dataURL to PHP and saves it on the server. In my JS: function addFormText(){ $('body').append('<input type="hidden" name="img_val" id="img_val" value="" /& ...

What is the best approach to merging multiple arrays to create a new array in CodeIgniter?

Here are two arrays provided below, where I want to combine the first key of the first array with the second key of the second array to create a new array. [animals1] => Array ( [0] => Horse [1] => Dog1 ...

Having trouble with Laravel retrieving unique values from a MySQL column? Let's troubleshoot and

I'm attempting to retrieve unique values for a dropdown from a specific column, I've tested these queries in my controller, however, the results are coming back empty. Attempted Controller Query 1 public function create() { $categories = Ca ...

Utilizing the bootstrap grid system, we can arrange three tables horizontally in

Can someone help me figure out how to print 3 tables per row on a page using the bootstrap grid layout? Currently, all tables are being printed vertically. Here is the code snippet: foreach($allmonths as $ind){ echo "<table>"; //echo "res ...

The PHP version displayed on phpinfo() is behind the version shown on the terminal

Recently, I encountered a versioning issue with my PHP on macOS. Surprisingly, the terminal displays PHP 7.4.2 as expected; however, when I pulled up phpinfo() on my project, it showed PHP 7.1.23. All the resources and posts I came across discussed discre ...

Trouble With OnClick and On/Off Class Script Functionality in Chrome and Internet Explorer

I am working on a page with two iframes and a basic navigation bar. The navigation bar links are set up to target one of the iframes and replace its content when clicked. However, I am having trouble highlighting the currently selected link in the iframe - ...

Explain the usage of the "with" statement in php

Upon discovering this code snippet within a recently installed Laravel bundle, I am puzzled by the usage of with(). There doesn't seem to be any declaration for it anywhere in the code. public static function of($query) { $ins = with(new static); ...

A guide on linking a jQuery dialog to an HTML element once the data has been updated with an AJAX response

On my PHP page, I have implemented a jQuery script to open a dialog window. The code for this is as follows: <script type="text/javascript"> $(document).ready(function() { var $loading = $('<img src="loading.gif" ...

Server lacks Nginx rewriting capabilities

I need to adjust the nginx configuration so that index.php in the public_html folder handles all requests except for files and folders. Although I know how to do this in htaccess, like the following: RewriteEngine on RewriteBase / RewriteCond %{REQUEST_F ...

Retrieving a targeted element from an array

I have a MySQL query that is returning an array when I use print_r(): $data = Array ( [2] => Array ( [0] => Array ( [sale_order_value_id] => 3 [sale_order_id] => 2 [name] => Comprobante Fiscal [value] => Consumidor Final [price] => 0. ...

When trying to parse an XML file in PHP that contains multiple children, I am encountering an issue where only the

When trying to parse an XML-file using "file_get_contents" with a foreach loop, I encountered an issue. Within the XML-file, there are multiple children () that I want to list in the following format: <a href="https://rssdomain.com/the-impact-of-brexit ...

Populating hidden fields in Javascript with mouseover event trigger - Pre-click action

Seeking a solution for another issue, I stumbled upon the capability to execute JavaScript on mouseover. Here is what I want to execute: $(document).ready(function(){ function myPayment() { var value = document.mortgagecalc.value_input.value; var rate ...