Why is my code displaying "Resource id #6" instead of the actual names of the lecturer or student stored in the database

$query = mysqli_query($con,"SELECT position FROM employees WHERE id ='$empId' AND password = '$empPassword'");
echo ($query); 

This snippet of code searches for the employee's position in the database and then echoes it out.

Answer №1

When you use mysql_query, it returns a handle that can be used to get the results of the query using functions like mysql_fetch_array or mysql_fetch_object. You must pass the query handle to these functions, as shown in the example below:

$query = mysql_fetch_array($sql1);
$position = $query['position'];

Answer №2

foreach($row as $sql1)
{
print_r($row['table_value']);
}

Implement the following code snippet.

Answer №3

The reason behind this is that mysql_query provides a resource when it succeeds. To access the data from the obtained resource, you can utilize the following code snippet.

if($result){
while($row = mysql_fetch_assoc($result)){
 echo $row['position'];
}
}

Answer №4

Make sure to eliminate any spaces between ' & $ in your MySQL query.

$result = mysql_query("SELECT position FROM user WHERE id ='$id' AND password = '$password'",$con);
$row = mysql_fetch_assoc($result);
foreach ($row as $value)
{
    print_r ($value);
}

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

Refresh your webpage with new content and modified URLs without the need to reload using window.history.pushState

Hey everyone, I'm looking to incorporate window.history.pushState into my website, but I'm unsure of how to go about it... What I'm aiming for is to have a page dashboard.php and update the URL to dashboard.php?do=edit&who=me, while loa ...

The URL overwrites the Ajax transfer type

When making an ajax call using a generated URL from a paginator script, I encountered an issue. The URL was dynamically created as shown below: "http://192.168.1.23:8000/pricing/0/999/null/?page=9" A similar link is generated on the server: "https://xxx ...

Generating a JSON form to enable users to search for specific dates within a given range by utilizing the "datetime" data type

Currently, I am in the process of developing a form that can search for specific data within a JSON's datetime value. The objective is to retrieve information from the JSON that falls between the first and last dates entered by the user. However, desp ...

Using PHP and jQuery together to retrieve and verify URLs

Currently, I am exploring the possibility of combining jQuery and PHP code. Specifically, I want to extract a URL value using jQuery and then use PHP to check if that specific site exists. It is crucial for me to utilize jQuery in this scenario. Addition ...

Set the status to 0 when the user exits the browser

I am currently working on developing a straightforward system to indicate whether the user is online or not. However, I have encountered a specific issue. Once the user closes the tab or the browser, the ajax code fails to refresh the page that tracks use ...

Look up and access the file

My latest script is designed to search for a specific file in the current directory. If it doesn't find the file, it will move up one directory and try again. The script functions properly when the file is found. However, if the file is not present, ...

Pass a PHP string to C++

I have a question about passing a string from PHP to C++. I've been able to pass numbers successfully, but I'm running into issues with passing letters. Here's the PHP code that works: <?php $r = 5; $s = 12; $x = 3; $y = 4; $q = "Hell ...

Hide the div if the content is empty

Within a div created by the_content, there may be content or it could be null, resulting in an empty div that I want to hide. To address this issue, I attempted to store the content in variable $pageContent. However, upon declaring the variable, it either ...

Exploring the use of jQuery/JS for parsing and working with JSON

Hi everyone, I need some assistance with displaying data from an array created by a PHP file using JS/jQuery. Currently, I am working on implementing a points system for ZetaBoards which you can check out here. The points will be shown below the user' ...

Sorting of unique elements in an array using PHP

I have been exploring the functionality of the array_unique function and according to the manual, it should also sort the values. However, when I test it with my sample code, I am not seeing the values being sorted. Here is the code snippet: $input = arra ...

Creating a zip file from database or binary file content using PHP

I'm looking to create a zip file using PHP, however my source files are all stored in databases rather than on disk. The content of the files I need to pack is saved as binary data in one database, while the metadata is stored in another. I've ...

Include a computed value in Laravel model query

In my controller, I have a query like this: $post = Post::find($id); $comments = $post->comments; Each post can have multiple comments, and each comment belongs to a single post. The comments model has fields for id, comment, and tag. What I'm l ...

Customizing push notifications for multiple servers on iOS with unique messages

In my experience setting up push notifications in iOS projects, I have encountered an issue with message format when changing servers. When using my local machine or a dedicated server, the messages come through correctly. However, switching to web hosting ...

Arranging a multidimensional array based on key value pairs in PHP

My array contains states with key-value pairs representing companies. I need to sort the array for each state in descending order based on the company's value, with the highest value company listed first and the lowest value company listed last. arr ...

determining the percentile for a vast dataset

My database holds student information related to test codes and the marks they achieved for each test. I am looking to recalculate percentile marks for students corresponding to each test code. Although I have a code for a series of test codes, it is not ...

Identify and handle exceptions from nested PHP scripts

When I run nested scripts using include() within a master script, I am wondering if it is possible to detect and log any errors that may occur during the execution of the nested script, even if they were caught in a try/catch block within the nested script ...

Encountering an unknown error while trying to perform a build using sequelize and express

When trying to build with sequilize after retrieving data from a form and posting it, an error is encountered: TypeError: Cannot read property 'build' of undefined index.js router.post('/register', function(req, res){ var name = ...

Error in PHP XPath query occurs following DOM adjustment

Every time I attempt to XPath-query a recently created node, I encounter the message PHP Notice: Trying to get property of non-object in .... The structure of my XML file is as follows: <products xmlns='http://example.com/products'> ...

What is the best way to eliminate duplicate values from a column in a data set

Time To Status Off-Track On-Track 10:28 AM gf 6233 4 4 10:32 AM dd 3835 7 10:40 AM ss 3235 4 10:43 AM ww 6621 5 11:06 AM zz 3837 ...

Limit users to viewing a Joomla article only once

I'm trying to figure out a way to customize Joomla so that only one view of certain articles is allowed per user. My goal is to make the article appear grayed out and prevent users from clicking on it after they have viewed it once. If anyone has any ...