Grow your CSS skills. Land your dream job.

Guestbook – PHP/MySql [Solved]

  • # April 24, 2010 at 5:37 am

    Hey guys,

    I followed a tutorial about making a guestbook. But it doesn’t really work… Heres the codes, I hope you have a soloution.

    Make answer/view answers:

    Code:


    Navn:


    Besked:



    < ?php
    $foresp = mysql_query("SELECT * navn, dato, besked FROM bog ORDER BY nr DESC"); //Data hentes i tabellen bog
    while($data = mysql_fetch_array($foresp)){
    echo "

    “;
    }
    ?>

    “;
    echo “” . $data[“navn”];
    echo “

    “;
    echo $data[“dato”];
    echo “
    “;
    echo nl2br($data[“besked”]); //nl2br = newline oversættes til html breaktag.
    echo “

    Page where form directs to:

    Code:
    < ?php

    /* Tilpas variablerne til dine oplysninger */
    $host = "************"; //skal ikke ændres i 90% af tilfældende
    $bruger = "******"; //"navn på din bruger"; //se de udleverede papirer/spørg dit wehotel
    $kodeord = "******"; //"MosterFie"; //dit personlige password
    $database = "*******************"; //"navn på din database"; //se de udleverede papirer/spørg dit wehotel

    /* Herfra ændres på eget ansvar - Der forbindes til databasen */
    $db = mysql_connect($host,$bruger,$kodeord)or die ('Der kunne ikke forbindes til databasen. Fejl: ' . mysql_error());; //der connectes til databasen
    mysql_select_db($database,$db);

    /* navn og besked hentes i html formularen. */
    if($_POST["skriv"]){
    $navn = htmlspecialchars($_POST["navn"]);
    $besked = htmlspecialchars($_POST["besked"]);

    /*Tjekker om begge felter er udfyldt*/
    if($navn != "" || $besked != ""){

    /* Sikkerheds script mod SQL injektions*/
    if(!get_magic_quotes_gpc()){
    $navn = addslashes($navn);
    $besked = addslashes($besked);
    }

    /* Der tester på om navn og besked er postet før. For at undgå ens indlæg, når man opdaterer siden */
    $sql = "SELECT * FROM bog ";
    $sql .= "WHERE navn = '" . $navn . "' ";
    $sql .= "AND besked = '" . $besked ."' ";
    $result= mysql_query($sql);

    if($row = mysql_fetch_row($result)){
    echo "

    Indlægget findes allerede, og blev ikke gemt igen.“;
    }else{
    $dato_array=getdate(); //php datofunktion
    $dato = $dato_array[“mday”] . “/” . $dato_array[“mon”] . ” – ” . $dato_array[“year”];
    mysql_query(“INSERT INTO bog(navn, dato, besked) VALUES(‘$navn’,’$dato’,’$besked’)”); //data skrives til tabellen bog
    }
    }
    }
    ?>

    Rob
    # April 24, 2010 at 8:26 am

    Well – as far as I can see you are making a query to display the results of the mySQL request without making a connection first.

    Code:
    < ?php
    $foresp = mysql_query("SELECT * navn, dato, besked FROM bog ORDER BY nr DESC"); //Data hentes i tabellen bog
    while($data = mysql_fetch_array($foresp)){
    echo "
    “;
    echo “” . $data[“navn”];
    echo “

    “;
    echo $data[“dato”];
    echo “ “;
    echo nl2br($data[“besked”]); //nl2br = newline oversættes til html breaktag.
    echo “

    “;
    }
    ?>

    You have no connection details there just a query.

    # April 24, 2010 at 1:55 pm

    That might be right, and I guess that’s the problem. Can you help me to make it? As I said, it’s a tutorial, and I dont know anything about MySQL.

    I would be very glad, if you would – and thank’s for the response :)

    # May 10, 2010 at 12:15 pm

    You can follow pretty well. You should be able to just google how to make the connection. I know you said you don’t know anything about it, but it is always fun to learn something new!

    Dog Training

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".