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

  • Home
  • SEARCH
  • 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 8794943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:19:11+00:00 2026-06-13T23:19:11+00:00

First stackoverflow question ever woot! FUNCTION : To check and see if data exist

  • 0

First stackoverflow question ever woot!

FUNCTION : To check and see if data exist before allowing INSERT – trying to make it non-case senstive and as open as possbile since the title I’m trying to avoid a dup is only for a specifc artistid (explained below)

The table row structure is as follows

  • id (auto_increment)
  • artist (specfic id number only assigned to that artist)
  • title (what we are trying to make sure we don’t get a dupicate only for this artist

ISSUE : Does not get needed data from database or post defined error, might be wrong in if statement = unknown exactly what is issue

$_POST[‘title’]; is passed from user input

            if (isset($submit)) {
                $date = date("Ymd");
                $cleanTitle =  $_POST['title'];
                $querytitle = mysql_real_escape_string($_POST['title']);
                $queryalbum = mysql_real_escape_string($_POST['album']);

                // Check to see if Title exist for specfic Artist
                $checkTitle = mysql_query("SELECT * from lyrics WHERE artist = '$artist'");
                if (!$checkTitle) {
                    die('Query Failed');
                } 
                if ($checkTitle == $cleanTitle)  {
// do whatever
}
                print_r($checkTitle); // the data returned from the query

UPDATE : INSERT IGNORE wouldn’t work sicne I’m inserting the data via $artist and need to check and see if title exist on that artist first. or i might be wrong. i’m unsure on how to do it
$artist is a specfic ID number defined higher in the code

  • 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-13T23:19:12+00:00Added an answer on June 13, 2026 at 11:19 pm

    Your code was incorrect, but this should work:

    if (isset($submit)) {
        $date = date("Ymd");
        $cleanTitle =  $_POST['title'];
        $querytitle = mysql_real_escape_string($_POST['title']);
        $queryalbum = mysql_real_escape_string($_POST['album']);
        // !!! $artist is not actually set anywhere here..
        $checkTitle = mysql_query("SELECT * from lyrics WHERE artist = '$artist'");
        if (!$checkTitle) {
            die('Query Failed');
        } 
        /* now that you have run the query, you need to get the result: */
        // (This is assuming your query only returns one result)//
        $result = mysql_fetch_array($checkTitle);
        // now check the value for 'title'
        if ($result['title'] == $cleanTitle)  {
            // do whatever
        }
        print_r($result); // the data returned from the query
    }
    

    You were running the query, but you were not getting the results of the query. You use mysql_fetch_array() to get the results. To get the results of multiple entries, you can use the following:

    // will print the 'title' for each results
    while ($row = mysql_fetch_array($checkTitle)) {
        echo $row['title'];
    }
    

    Now with all of that said, you should know that mysql_* is going through a deprecation process and should be replaced with mysqli or PDO. Please read the following:

    Please, don’t use mysql_* functions in new code. They are no longer maintained and the
    deprecation process has begun on it. See the
    red box? Learn about prepared statements instead, and use
    PDO or MySQLi – this article will help you decide which. If you choose
    PDO, here is a good tutorial.

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

Sidebar

Related Questions

This is my first question ever at stackoverflow, hope I make sense out of
First question ever on stackoverflow. Been reading for some time now, while trying to
First question on Stackoverflow (.Net 2.0): So I am trying to return an XML
First question ever asked at stackoverflow. So, problem is: Two accordion declarations on document.ready
This is my first question ever here on stackoverflow! I've been searching for a
My first stackoverflow question, hope I do it right.. I'm trying to build a
first question ever here on stackoverflow: i want to escape html inside php AND
This is my first question ever on StackOverflow, hurray! I can honestly say I
For my first ever StackOverflow question... android.graphics.Color only contains static utility methods, it isn't
Ok; my first stackoverflow question. I have been trying to use our local Nexus

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.