Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8184157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:24:19+00:00 2026-06-07T01:24:19+00:00

I’m very new to using MySql and am having trouble retrieving values from my

  • 0

I’m very new to using MySql and am having trouble retrieving values from my database. I was under the impression that i was going about it the correct way but my echo statements don’t print anything.

I’d appreciate some help. My code is below. I know i’ll have to add security later on like sanitizing user input.

<?php
            $email = $_POST['email'];
            $password = $_POST['password'];
            $hashedPass = sha1($password);

            if ((!isset($email)) || (!isset($password))) {
                //Visitor needs to enter a name and password
                echo "Data not provided";
            } else {
                echo "Received details $email and $password <br/>";
                // connect to mysql
                $mysql = mysqli_connect("localhost", "root", "root");
                if(!$mysql) {
                echo "Cannot connect to PHPMyAdmin.";
                exit;
                } else {
                echo "Connected to phpmyadmin <br/>";
                }
            }
            // select the appropriate database
            $selected = mysqli_select_db($mysql, "languageapp");
            if(!$selected) {
                echo "Cannot select database.";
                exit;
            } else {
                echo "DB Selected"; 
            }
            // query the database to see if there is a record which matches
            $query = "select count(*) from user where email = '".$email."' and password = '".$hashedPass."'";
            $result = mysqli_query($mysql, $query);
            if(!$result) {
                echo "Cannot run query.";
                exit;
            }

            $row = mysqli_fetch_row($result);
            $count = $row[0];

            $userdata = mysqli_fetch_array($result, MYSQLI_BOTH);
            echo $userdata[3];
            echo $userdata['firstName'];

            if ($count > 0) {   
                echo "<h1>Login successful!</h1>";
                echo "<p>Welcome.</p>";
                echo "<p>This page is only visible when the correct details are provided.</p>";
            } else {
                // visitor's name and password combination are not correct
                echo "<h1>Login unsuccessful!</h1>";
                echo "<p>You are not authorized to access this system.</p>";
            }
            ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:24:22+00:00Added an answer on June 7, 2026 at 1:24 am

    I believe the problem is that you call twice the *fetch* family function which will cause the $userdata to be empty.

    From the documentation mysql_fetch_row will fetch the next row and move the internal data pointer ahead. So when you call mysqli_fetch_array($result, MYSQLI_BOTH) and I suppose the user/password is unique there is nothing to retrieve. Also another mistake you did is that your SELECT doesn’t retrieve the actual user data, but just the count number for the user/password combination. So your userdata will be always incorrect, even if you fetch the data right.

    So change your query to something like that:

     $query = "select * from user where email = '".$email."' and password = '".$hashedPass."' LIMIT 1";
    

    Then use mysql_fetch_array to check if the entry exist and then retrieve the user data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a view passing on information from a database: def serve_article(request, id): served_article
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.