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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:13:37+00:00 2026-06-01T07:13:37+00:00

Please I need your help with my script. I’m trying to insert values into

  • 0

Please I need your help with my script. I’m trying to insert values into maintable, but before I insert, I have to check if a row have an exact match compared to the one I’m inserting. If there’s a match then it should echo Record Exists, and if not it should go ahead and insert into the table. The problem is that it is returning 0 for $duplicate, when actually there is a row that matches the entries that I’ve entered in the HTML page, thereby it goes ahead and inserts the duplicate.
Please what could the problem be?

{
    $query = mysql_query("SELECT m.matric_no, m.course_code, m semester_name, m.level, m.session 
                          FROM  maintable AS m 
                          WHERE m.matric_no = '".$matric_no."'
                          AND m.course_code = '".$course_code."'
                          AND m.semester_name = '". $semester_name."'
                          AND m.level = '".$level."'
                          AND m.session = '".$session."'") ;

    $duplicate = mysql_num_rows($query);

    if ($duplicate > 0 ) 
        echo "$duplicate" ;
    {
        echo "Record Exists"     
    }
    else
    {

        $query = "INSERT INTO maintable (matric_no, course_code, semester_nam,          session, level) 
                   VALUES ('".$matric_no."', 
                       '".$course_code."',
                       '".$semester_name."',
                       '".$session."', 
                       '".$level."')" ;
        mysql_query($query) or
            die (mysql_error());   

        echo"Record Inserted"; 
    }

Please forgive my formatting, I typed on a mobile, I didn’t mean disrespect to this community.

  • 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-01T07:13:38+00:00Added an answer on June 1, 2026 at 7:13 am

    Your formatting’s a bit all over the place, which is why you’re finding it so hard to spot errors when they occur. Try sticking to a consistent format style. This should do the trick:

    $check = mysql_query("SELECT * FROM maintable WHERE matric_no = '$matric_no' AND course_code = '$course_code' AND m.semester_name = '$semester_name' AND m.level = '$level' AND m.session = '$session'");
    
    if(mysql_num_rows($check))
    {
       echo 'Record exists!';
    }
    else
    {
       $query = "INSERT INTO maintable (matric_no, course_code, semester_nam, session, level) VALUES ('$matric_no','$course_code','$semester_name','$session','$level')";
       mysql_query($query) or die (mysql_error());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please i need your help with my script. Whenever i include AND maintable.semester_name =
please i need you help with my script.. I'm trying to echo some content
please I need your help with a Linq expression: I have nested objects with
Hi, I have made this simple script but I need to have it check
Please i need your help with how to include INDEXES in my tables, i've
Please help! I need to produce a Crystal Report with multiple data columns, but
I need some help! Please. I am trying to develop a very very simple
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
I am beginner on WPF and need your help. Problem: I have 4 buttons
I need some help with a script I am developing. I have some advertisements.

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.