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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:47:43+00:00 2026-06-02T21:47:43+00:00

(this is my fist post) I have written a PHP-script to enter a data-set

  • 0

(this is my fist post)
I have written a PHP-script to enter a “data-set” into a MySQL database.
Before I enter the data, I want to check, if the “data-set” is already in the database.

My problem: It only works for a few data-sets (yes, I am sure I didn’t forget upper and lowercase)
so here is the script (you don’t need the german comments… ):

<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<title>Playlist</title>

<link rel="stylesheet" type="text/css" href="style.css" />

<script type="text/javascript">
setTimeout("self.location.href='index.php'",6000);
</script>

</head>
<body>
<div id="enterbody">
<?php
include ('conf.php');


mysql_select_db("$datenbank");

//Zeit
$date = date("d-m-Y");

//Post 2 var
$inp = $_POST["inp"];
$titel = $_POST["titel"];
$link = $_POST["link"];

//Länge der Strings
$l_inp = strlen($inp);
$l_titel = strlen($titel);
$l_link = strlen($link);

//eingabestrings in kleine zeichen umwandeln
$s_inp = strtolower($inp);
$s_titel = strtolower($titel);

//datenbankstrings in kleine zeichen umwandeln


//Ausgabe

echo "Länge des Interpreten: $l_inp (max: 50)</br>";
echo "Länge des Titels: $l_titel (max: 50)</br>";
echo "Länge des Links: $l_link (max: 42)</br>";

if ($inp == "" or $titel == "")
{
    echo "Bitte fülle die notwendigen Felder aus!";
}
else
{
    if ($l_inp > 50 or $l_titel > 50 or $l_link > 42)
    {
        echo "Der Interpret/Titel/Link ist zu Lange, deshalb wurde er nicht in die Datenbank eingetragen!";
    }
    else
    {       
            //stringkonvertierung nicht vergessen
            $inp_einlesen = mysql_query("SELECT inp FROM $tabelle WHERE inp='$inp'");
                $titel_einlesen = mysql_query("SELECT titel FROM $tabelle WHERE titel='$titel'");

                if (mysql_num_rows($inp_einlesen) == 1 and mysql_num_rows($titel_einlesen) == 1)
                {
                        echo "<b>$inp</b> mit dem Track <b>$titel</b> ist schon in der Datenbank vorhanden, deshalb wird der Datensatz nicht eingetragen";
                }
                else
                {

                $entry = "INSERT INTO playlist (inp, titel, link, date) VALUES('$inp','$titel','$link', NOW())";
                $enter_data = mysql_query($entry);


                if ($enter_data == true)
                {
                    echo "Deine Daten wurden gespeichert! Weiterleitung...";
                }
                else
                {
                                echo "Fehler beim Eintragen der Daten...";
                        }

                }
    }
}



mysql_close($connection);
?>
</div>




</body>
</html>
  • 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-02T21:47:45+00:00Added an answer on June 2, 2026 at 9:47 pm

    On this line:

    if (mysql_num_rows($inp_einlesen) == 1 and mysql_num_rows($titel_einlesen) == 1)
    

    You’re just testing for one result. Maybe you have multiple results? Maybe two records have the “inp_einlesen” match and only one matches for the ‘titel_einlesen’? In other words, if your dataset already has duplicates, this line won’t find them unless there is only one duplicate of each field.

    Another thing besides upper/lower case is trailing spaces. Be sure to use trim() to remove trailing whitespace.

    The other thing you might want to standardize is how you’re handling escapes. If someone enters data with apostrophes in it, you’ll need to either manually escape this or deal with it at a lower level, like with magic_quotes.

    Also, the code here as you’ve presented it is susceptible to a MySQL injection attack. Be sure to read the PHP man pages for “mysql_real_escape_string.”

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

Sidebar

Related Questions

Fist off, been lurking for years, hopefully this post will be helpful to more
This is my fist stackoverflow post so please be gentle with me! I'm sure
I have ask this kind of question before, but it seems my previous question
I have two svn . Fist is trunk -foldoer 1 -script and Second one
This has been a rather problematic issue on numerous occasions. We have alot of
this is my code that I write it but I want to use LINQ
I have this method: public static IEnumerable<T> ExecuteReaderSp<T>(string sp, string cs, object parameters) where
please help me to style this list , I need to set different background
i need to insert 4 column in sql table fist 2 column i have
I have `a string example = this site holds all the examples from 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.