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 7845243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:09:53+00:00 2026-06-02T17:09:53+00:00

I have a bit of an issue with a code I am trying to

  • 0

I have a bit of an issue with a code I am trying to write:

The purpose of the code is to check if two fields match from a row in a table (the two fields have already been pre-defined in the code, so field1 and field2). If they do match it displays the rest of the information in that row in a HTML table. If the two fields do not match then it echo’s a message.

Below is what I’ve got so far:

### Connects to db
$dbhost = 'localhost';
$dbuser = 'username';
$dbpass = 'password';
$dbname = 'dbname';
mysql_select_db($dbname);




echo ("<table width=\"580px\" class=\"board\" border=\>


      <form method=\"post\" action=\"check_data.php\">
        <tr>        
          <td>Field1</td>
          <td>
            <input type=\"text\" name=\"f1\" 
        size=\"20\">
          </td>
        </tr>
        <tr>
          <td>Field 2</td>
          <td>
            <input type=\"text\" name=\"f2\" size=\"40\">
          </td>
        </tr>
        <tr>
          <td align=\"right\">
            <input type=\"submit\" 
          name=\"submit value\" value=\"Check\">
          </td>
        </tr>
      </form>
      </table>")

Check_data.php contains:

   ### Connects to db
    $dbhost = 'localhost';
    $dbuser = 'username';
    $dbpass = 'password';
    $dbname = 'dbname';
    mysql_select_db($dbname);

         $id = $_POST['f1'];
                 $points = $_POST['f2'];
   ## Query
    $check = "SELECT * FROM table WHERE `field1` = '$f1' AND `field2` = '$f2'";;
mysql_query($check);
echo("<div class=\"successful\">Field 1 and Field 2 match.

$check</div>");

Any help would be greatly appreciated.

  • 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-02T17:09:54+00:00Added an answer on June 2, 2026 at 5:09 pm

    The code in check_data.php seems incomplete. I’d expect something like:

    $dbhost = 'localhost';
    $dbuser = 'username';
    $dbpass = 'password';
    $dbname = 'dbname';
    
    if (!mysql_connect($dbhost, $dbuser, $dbpass)) {
        die('Not connected : ' . mysql_error());
    }
    
    if (!mysql_select_db($dbname)) {
        die ('Can\'t use foo : ' . mysql_error());
    }
    
    $id = $_POST['f1'];
    $points = $_POST['f2'];
    $check = "SELECT * FROM table WHERE `field1` = '$id' AND `field2` = '$points'";
    $res = mysql_query($check);
    if (!$res) {
        die('Invalid query: ' . mysql_error());
    }
    
    if( mysql_num_rows($res) > 0 ){
        // fields match
    } else {
        // fields don't match
    }
    

    By the way, you should be careful, because this code could lead to SQL injection attacks, as @AndrewLeach pointed out.

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

Sidebar

Related Questions

I have run into a bit of a design issue with my code. I
Coming from Win32, I am having bit of an issue or a problem trying
I'm having a bit of an issue trying to get some PHP code to
I have a bit of an issue with a site I maintain. I have
I have an iframe issue ( little bit strange for me ) . The
hello fellow java developers. I'm having a bit of an issue here. I have
Having a bit of a weird issue... In my AppDelegate.m I have the following:
Alright, So I have an issue that is a bit weird. I am using
i have bit of code that causes an underflow: var t1, t2, delta: DWORD:
I'm trying to write a class that implements 64-bit ints for a compiler that

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.