Results 1 to 7 of 7

Thread: Error at school project

  1. #1
    Join Date
    Sep 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Error at school project

    I have a student that came to me with a error he had at a school php project. I searched for the problem, but i could'nt find it.

    This is the code:
    PHP Code:
    <?php
    // Db gegevens:
    $db_user="root";
    $db_password="";
    $db_host="localhost";
    $db_database="school";

    // Database connectie:
    function database_connect(){
        global 
    $db_host$db_database$db_user$db_password;

        
    $db_link = @mysql_connect("$db_host","$db_user","$db_password"); 
        
    $sql_error mysql_error();

        if (!
    $db_link) { 
            echo 
    "Er heeft zich een fout opgetreden met het verbinden met de database.<br>";
            echo 
    "$sql_error"
            exit;
        }
      
       if (!@
    mysql_select_db("$db_database")) {; 
            echo 
    "De database kan niet worden geselecteerd.";
            exit;
        }
       return 
    $link;
    }

    $artist_naam $_POST['artist_naam'];

    if(empty(
    $artist_naam)){
        echo(
    "vul eerst de gegevens van het <a href=\"muziek.php\">nummer</a> in");
        exit();
    }else{
        
        
    // Start de database connectie:
        
    database_connect();
        
        
    //kijken of de artiest al in de database aanwezig is
        
    $query mysql_query("SELECT * FROM tabel_artist WHERE artist_naam = '".$artist_naam."';") or die ("FOUT1:".mysql_error());
        
        
    // controleer eerst of er records werden gevonden
        
    $rij mysql_fetch_array($query) or die ("FOUT2:" mysql_error());
        
    $teller count($rij);
        
        
    // Als de teller wat heeft gevonden, laat gegevens zien:
        
    if($teller>=1){
        
            
    //
            
    for($tel=1$tel<=$teller$tel++){
                
    $artist_id_tmp $rij['artist_id'];
            }    
        } else {
        
            
    database_connect();
            
            
    $query ="insert tabel_artist (artist_id, artist_naam, artist_nat)";
            
    $query .="values('";
            
    $query .= $_POST["artist_id"]."','";
            
    $query .= $_POST["artist_naam"]."','";
            
    $query .= $_POST["artist_nat"]."');";
            
    $result mysql_query($query)or die("FOUT:" mysql_error());
                
            
    $artist_naam_tmp $_POST["artist_naam"];
            
            
    $query "SELECT * FROM tabel_artist WHERE artist_naam = '".$artist_naam_tmp."';";
            
    $query mysql_query($query$db)or die("FOUT:" mysql_error());
            
    $query mysql_fetch_object($query)or die("FOUT:" mysql_error());
        }
        
        
    database_connect();
        
        
    $query ="insert muziek (media_id, titel, beoordeling, gerne, medium, artiest)" 
        
    $query .="values('";
        
    $query .= $_POST["media_id"]."','";
        
    $query .= $_POST["titel"]."','";
        
    $query .= $_POST["beoordeling"]."','";
        
    $query .= $_POST["gerne"]."','";
        
    $query .= $_POST["medium"]."','";
        
    $query .= $artist_id_tmp."');";
        
    $result=mysql_query($query)or die("FOUT:" mysql_error());

        
    }
    ?>
    <html>
    <head>
    <title>nummer invoegen</title>
    </head>
    <body bgcolor="#d3d3d3">
    <?php
    echo("U heeft de volgende gegevens succesvol ingevoegd:<BR>\n");


    echo(
    "Artistnaam:<b>".$_POST["artist_naam"]."</b><br>");
    echo(
    "land:<b>".$_POST["artist_nat"]."</b><br>");
    echo(
    "Titel:<b>".$_POST["titel"]."</b><br>");
    echo(
    "Beoordeling:<b>".$_POST["beoordeling"]."</b><br>");
    echo(
    "Gerne:<b>".$_POST["gerne"]."</b><br>");
    echo(
    "medium:<b>".$_POST["medium"]."</b><br>");
    echo(
    "<hr>|<a href=\"muziek.php\">Nog een nummer toevoegen</a>|<br>|<a href=\"overzicht.php\">overzicht alle nummers in database</a>|");
    ?>
    </body>
    We get this error:
    Code:
    FOUT2:
    No errors or anything that could be usefull for solving the problem.

    (I know this php has some dangerous holes, and i repeat that its not writed by me, nor will it ever come online.)

    Can some1 help finding the errors?
    Last edited by elwinh; 09-05-2007 at 02:39 PM.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The error lies on this line:

    Code:
    $query ="insert muziek (media_id, titel, beoordeling, gerne, medium, artiest)" ;
    It should be:

    Code:
    $query ="insert INTO muziek (media_id, titel, beoordeling, gerne, medium, artiest)" ;
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Sep 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ah..that's one error. But not the error wich crashes the script at this point. The error is almost at the top of the page. (remember me saying: "Fout2:")

    But ty for the reply...

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    the problem is that it cannot complete the query, which is caused from not connecting properly.

    return $link;
    no where in your connect function do you declare = assign a value to this variable

  5. #5
    Join Date
    Sep 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    eddited....

    still got the mssg.

    It will connect, even if i have that error in it. had it ad a other page and that 1 still connects.

    If the connection whas teh problem, i would have had a msg in mysql_error(). By the fact that i did'nt, it could'nt be the mysql connection.

    But also ty for your mssg.

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Here you go:

    Code:
    $query = mysql_query("SELECT * FROM tabel_artist WHERE artist_naam = '".$artist_naam."';") or die ("FOUT1:".mysql_error());
    That semicolon should not be there.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Sep 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ty, removed the semicolon, still got the error mssg.

    I thank you for your mssg, but it still won't work

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •