Jump to content

mrfdes

Members
  • Posts

    50
  • Joined

  • Last visited

Posts posted by mrfdes

  1. I have one further question, though:

     

    How can I log the voter's IP address in the email?

     

    I tried the following, but that did not work:

     //Send confirmation email
            $to = "beheer@vlaamseradio.tk";
            $subject = "Someone voted";
            $message = "Someone voted for $songSafeHtml.";
            $ip= SERVER['REMOTE_ADDR'];
    		$header = "From: systeem@jinglekot.cu.cc \r\n";
    		$retval = mail($to, $subject, $message, $ip, $header);
        }
    

    So, probably something was put in the wrong place.

     

    Thank you.

  2. Thank you for your further explanation, Psycho.

    It all helps me to learn more.

    I have read your comments properly and tried to analyse everything you said.

     

    As for the time zone, I suspected it had to be put at the top of the script, but then I thought "PHP is NEVER that simple", well, it proved me wrong.

    Although it still gives me  a weird time out put. The time is almost 9 pm here, and I get 08:06:seconds...

    The time should be 1 hour ahead of me, though,

     

    I used exactly this code: 

    date_default_timezone_set("Europe/Brussels");
    

    which looks 100% valid to me.

     

    Anyway, I am not going to mope about details, nor bother you with them.

     

    Thank you so much once again.

  3. Very true, Psycho,

    however, the script was tested before the email bit was added, and it still works now in that I do not get an email if someone tried to vote more than once in 24 hours, also, the votes do not get incremented if that is the case, so it seems all is well.

     

    Now one more thing: how can i integrate this

    date_default_timezone_set('Europe/Brussels');
    

    into my script?

    I live in the UK, but my audience mostly reside in Belgium/Holland/South Africa, 1 hour ahead of us, and the time given in the warning was probably US time, as it seems I had voted in the middle of the night at 7pm here.

     

    Apart from that, I do take your comments to heart and I am grateful for them, I definitely want to learn proper PHP programming, but that is obviously not so simple having to do it all by yourself, is it?

     

    Thank you very much again.

  4. Thanks, Psycho.

    Well, it is my working script, 

     

    I just translated it in English so that people here would understand the variables and must have forgotten one. :psychic:

    Anyway, I'll test it to see what happens.

    By the way, the sendmail() function was used to send a message to me when someone votes so I can follow what happens.

     

    Thank you very much again for this, it is much appreciated.

     

    Like I said, I am a novice, one who was even still working with mysql rather than mysqli, so PDO is definitely still far beyond me.

    But these things make me even more determined to carry on learning.

     

    Thanks again.

  5. OK,

    Here it comes:

    <?php
    session_start();
    error_reporting(E_ALL | E_STRICT | E_NOTICE);
    ini_set('display_errors', '1');
    $host="localhost";
    $user="jingleko_reload";
    $pwd="*******";
    $dbname="jingleko_reloader";
    $link = mysqli_connect($host,$user,$pwd,$dbname) or die(mysqli_error());
    $lied = mysqli_real_escape_string($link,$_GET['Song']);
    $songSafeHtml = htmlspecialchars($_GET['Song']);
    if (mysqli_query($link, "UPDATE voting SET Votes= Votes+1 WHERE Song = '$song'"))
        echo "You voted for <b>$songSafeHtml</b><br> U het gestem vir <b>$songSafeHtml</b></br>";
    	else
        die(mysqli_error());
    	$to = "beheer@vlaamseradio.tk";
       $subject = "There was a vote";
       $message = "Someone voted for $songSafeHtml.";
       $header = "From:systeem@jinglekot.cu.cc \r\n";
       $retval = mail ($to,$subject,$message,$header);
       if( $retval == true )   
       {
          echo "Your vote has been registered...";
       }
       else
       {
          echo "There was a fault...";
       }
    ?>
    

    Thanks so much once again.

  6. Then there is just one more thing:

    How could I send a cookie to the voters so they can only vote once every 24 hours?

    (It doesn't matter about it being a cookie, as most of my audience are not computer literate enough to delete or fiddle with a cookie).

     

    I have already noticed that, while the script has only been running a few hours, people are already voting like mad, and I would like things to go a bit honest at least.

     

    I REALLY do not have a clue about how to do any of this, so be patient with me please.

     

    Thanks in advance.

    :thumb-up:

  7. Yes, it is capped. :)

     

    I now get this:

    Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/jingleko/public_html/vlaamseradio.tk/top10/top10stem.php on line 20

    Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/jingleko/public_html/vlaamseradio.tk/top10/top10stem.php on line 23

    Lines 20 and 23 are:

    20 if (mysqli_query("UPDATE voting SET Votes= Votes+1 WHERE Song = '$song'"))
    
    23  die(mysqli_error());
    
  8. I keep getting errors referring to line 18 now.

    The kines 16, 17 and 18 are this:

    mysqli_connect($host,$user,$pwd,
    $dbname) or die(mysqli_error());
    mysqli_select_db($dbname) or die(mysqli_error());
    

    The errors are:

    Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in /home/jingleko/public_html/vlaamseradio.tk/top10/top10stem.php on line 18

    Notice: Use of undefined constant mysqli_error - assumed 'mysqli_error' in /home/jingleko/public_html/vlaamseradio.tk/top10/top10stem.php on line 18
    mysqli_error

  9. OK, after setting the error checking I now get:

    Warning: mysqli_connect(): (28000/1045): Access denied for user 'jingleko_reload'@'31.22.4.227' (using password: YES) in /home/jingleko/public_html/vlaamseradio.tk/top10/top10stem.php on line 17
    
    Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/jingleko/public_html/vlaamseradio.tk/top10/top10stem.php on line 17
    

    Line 16 and 17 are the following: 16 mysqli_connect($host,$user,$pwd,

    17 $dbname) or die(mysqli_error());: 

     

    Maybe this rings some bells.

    BTW, I am impressed with all the quick replies I am getting here.

    thanks so much, everyone.

  10. Forgive my ignorance, but I am quite new to PHP/MySQL.

    What I would like to achieve is, for a Top 10 on my radio station, I would like to allow the people to vote for individual songs, and when they do, increase the value of the number of votes in the database.

    I pass the value of the song they clicked on through the URL:http://www.vlaamseradio.tk/top10/top10stem.php?Song= It does display the song correctly on the page, saying "You voted for "Songname", but the votes value will not increase in the database. Here is the code I used:

    <?php
    $host="localhost";
    $user="*****";
    $pwd="******";
    $dbname="jingleko_reloader";
    mysqli_connect($host,$user,$pwd, $dbname);
    $song = mysql_real_escape_string($_GET['Song']);
    $songSafeHtml = htmlspecialchars($_GET['Song']);
    mysqli_query("
        UPDATE voting 
        SET Votes= Votes+ 1 
        WHERE Song = '$song'
    ");
    echo ("You voted for $songSafeHtml" );
    ?>
    
    

    Any idea where my fault could be, please?

    All help will be very much appreciated.

     

  11. Hi X5HOST,

     

    I'm afraid you've lost me now.

    I haven't got a clue what 2NF and 3NF mean.

     

    Like I said, I am a novice.

    And to be quite honest, the search never yields any results anyway, all I get is "Sorry, we couldn't find any data matching your search", while I am sure I entered existing data in the search.

     

    Thank you anyway.

  12. Hi,

    I would require some help with a short script to let the listeners of my radio vote in a Top-10.

     

    Something simple would be good enough.

    I have a MySQL database table with 3 fields: Song, artist and votes.

    The intention is that in part one (code follows after this), the listener does a search and when the search results appear, there should be a voting button next to every one and when that button is clicked the votes field is increased by one.

     

    I have made the code for a form, this is it:

    <html>
    
    <head>
    <title>Zoeken naar een lied...</title>
    </head>
    
    <body bgcolor=#ffffff>
    
    <h2>Zoek</h2>
    
    <form name="search" method="post" action="studentsearch-exec.php">
    Zoek naar: <input type="text" name="find" /> in
    <Select NAME="field">
    <Option VALUE="Lied">Lied</option>
    <Option VALUE="Artiest">Artiest</option>
    </Select>
    
    <input type="submit" name="search" value="Zoek" />
    </form>
    </body>
    
    </html>
    

    "Zoek" means search, Lied means song and Artiest, obviously "Artist".

     

    Then the PHP page:

    
    <html>
    <head><title>Een lied opzoeken...</title>
    </head>
    <body bgcolor=#ffffff>
    
    <?php
    $username="SomeUsername";
    $password="notTellingyou";
    $database="frankie_reloader";
    
    echo "<h2>Resultaat:</h2><p>";
    
    //If they did not enter a search term we give them an error
    $find = $_POST['find']; 
    if ($find == "")
    {
    echo "<p>U vergat een zoekopdracht in te voeren!!!";
    exit;
    }
    
    // Otherwise we connect to our Database
    mysql_connect("localhost", $username, $password) or die(mysql_error());
    mysql_select_db($database) or die(mysql_error());
    
    // We perform a bit of filtering
    $find = strtoupper($find);
    $find = strip_tags($find);
    $find = trim ($find);
    
    //Now we search for our search term, in the field the user specified
    $data = mysql_query("SELECT * FROM stemming WHERE field LIKE $find");
    
    
    //And we display the results
    while($result = mysql_fetch_array( $data ))
    {
    echo $_POST['find'];
    echo " ";
    }
    
    //This counts the number or results - and if there wasn't any it gives them a little message explaining that
    $anymatches=mysql_num_rows($data);
    if ($anymatches == 0)
    {
    echo "Het spijt ons, maar we vinden geen resultaat voor uw opdracht...<br><br>";
    }
    
    //And we remind them what they searched for
    echo "<b>U zocht naar:</b> " .$find;
    //}
    ?> 
    
    
    </body>
    </html>
    

    The 3rd field (number of votes) is not present in the code yet, as I can't even get it to find any results.

    But the field is called "Stemmen" (meaning votes) and needs to be updated by one when someone clicks the button.

    I would prefer it if only one vote in 24 hours is allowed per person.

     

    Any help would be gratefully accepted, as I am a total PHP novice.

    Thanks in advance.

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.