Jump to content

mrfdes

Members
  • Posts

    50
  • Joined

  • Last visited

Posts posted by mrfdes

  1. Thank you for that Jacques.

    But, "So why use MySQLi?", well, because I don't know any better.

     

    The course I am following at the moment doesn't even mention mysqli, let alone PDO.

    Like I said, I am a beginner, and a lot of things still look/sound extremely complicated tome.

     

    Thank you for your input anyway.

  2. What I mean is:

    when I changed 

    mysql_select_db("jingleko_reloader", $con) or die("Couldnt Select a DB - ".mysql_error());
    

    to

    mysqli_select_db("jingleko_reloader", $con) or die("Couldnt Select a DB - ".mysql_error());
    

    I got the error 'Could not connect to db', so I had to put the database name in the mysqli_connect as 4th parameter.

     

    Strange, but it is probably me.

    Thank you.

  3. Thanks.

    I have changed to mysqli now.

    PDO is still a bit beyond me, I'm afraid, but I am working on that.

    By the way, it looks like some mysqli statements are no longer supported when you change from mysql to mysqli.

     

    But, thank you all for your very useful advice.

  4. But where???

     

    I have set up a script for people to remove themselves from a mailing list.

    It worked fine so far, but when I added a possibility to show a message the entered email addres did not exist, things went wrong.

    The script still runs, there are no errors, but when the user enters a non-existing email address, it still says "You have been removed".

     

    Everything seemed to go well until I added a button to a URL (echo'd) rather than a plain link.

     

    I have checked and rechecked, re-examined the flow, but I cannot find where I went wrong.

     

    One further thing: the people get sent to this page by a one field form on a HTML page, with method "post".

     

    Anyway, here is the script:

    <HTML>
    <HEAD>
     <TITLE>Vlaanderen-Flanders</TITLE>
    </HEAD>
    <BODY>
    
    <?php
     
    // Always try to connect and select the DB before anything else
    $con = mysql_connect("localhost","jingleko_reload","*******") or die("Couldnt Connect to DB - ".mysql_error());
    mysql_select_db("jingleko_reloader", $con) or die("Couldnt Select a DB - ".mysql_error());
    
    // Set post var
    $Epost = trim(addslashes(strip_tags($_POST['Epost'])));
    
    // Look for it in DB
    $query = "SELECT Epost FROM newsletter WHERE Epost='".$Epost."'";
    $result = mysql_query($query);
    //If found, do next thing
    if(isset($_POST['Epost']))
    {
        mysql_query("DELETE FROM newsletter WHERE Epost='$Epost'") or die (mysql_error());
        echo "<div align=\"center\"><img src=\"Pics/Vlaamse Leeuw.jpg\" width=\"114\" height=\"127\" border=\"0\"></div>";
        echo "<p align=\"center\"><b>Thank you, you are now removed from the list.</b></p><br>";
        echo "<p align=\"center\"><a href=\"index.htm\"><img src=\"Pics/begin.gif\" width=\"95\" height=\"30\" border=\"0\"></a></p>";
    }
    else
    {
    echo "<div align=\"center\"><b><font color=\"red\">This address does not exist</font></b></div><br>";
    echo "<div align=\"center\"><a href=\"eruit.htm\"><img src=\"Pics/herbegin.gif\" width=\"95\" height=\"30\" border=\"0\"></a>"; 
    echo "<a href=\"index.htm\"><img src=\"Pics/begin.gif\" width=\"95\" height=\"30\" border=\"0\"></a></div>";
    }
    
    mysql_close($con);
    
    ?>
    
    </BODY>
    </HTML>
    
    

    Any ideas, please?

    Sometimes when I altered the code, I just got a blank page.

    Thanks in advance.

     

  5. Thank you ever so much, Psycho,

     

    I REALLY tried (almost) everything.

     

    While it is good for the learning process to "learn from your mistakes" and watch closely what the error messages say, it can be quite stressful.

     

    Nevertheless, I have learned more stuff again, and this is a motivation to carry on with my course even more intensely.

     

    Thank you again.

  6. I did that with the following lines:

    $query="SELECT Song FROM stemming WHERE Nr=$songSafeHtml";
    		$result=mysqli_query($link,$query);
            $output = "You voted for <b>$songSafeHtml." ".$result</b><br> U het gestem vir <b>$songSafeHtml." ".$result</b></br>";
    

    and it gives me:

    Catchable fatal error: Object of class mysqli_result could not be converted to string in /home/jingleko/public_html/vlaamseradio.tk/top10/top10stem.php on line 71
    

    Really no idea now.

  7. I have done this, the URL was changed to http://www.vlaamseradio.tk/top10/top10stem.php?Nr=

    where Nr is the song number (the ID).

     

    The script became:

    <?php
     
    //Check if the user had voted in the last 24 hours
    if(isset($_COOKIE['voted']))
    {
        $expireString = date('m-d-Y h:i:s', $_COOKIE['voted']);
        $output = "Sorry, you can only vote once every 24 hours. You can vote again after $expireString";
    }
    else
    {
        //Start session and enable error reporting
        session_start();
        error_reporting(E_ALL | E_STRICT | E_NOTICE);
        ini_set('display_errors', '1');
     
        //Connect to DB
        $host="localhost";
        $user="jingleko_reload";
        $pwd="*******";
        $dbname="jingleko_reloader";
        $link = mysqli_connect($host,$user,$pwd,$dbname) or die(mysqli_error());
     
        //Update count for selected song: THIS IS WHERE I MADE THE CHANGES
        $number = mysqli_real_escape_string($link,$_GET['Nr']);
        $query = "UPDATE voting SET Votes = Votes+1 WHERE Nr = '$number'";
        $result = mysqli_query($link, $query);
     
        if (!$result)
        {
            //Query failed
            #die(mysqli_error()); //Uncomment for debugging only
            $output = "There was a problem processing your request.";
        }
        elseif(!mysqli_affected_rows($link))
        {
            //No records were updated
            $output = "The song you selected doesn't exist."
        }
        else
        {
            //Vote was registered
            $songSafeHtml = htmlspecialchars($_GET['Song']);
            $output = "You voted for <b>$songSafeHtml</b><br> U het gestem vir <b>$songSafeHtml</b></br>";
            //Set cookie to prevent multiple votes
            $expire = time() + (60 * 60 * 24); //Set expiration for 24 hours
            setcookie('voted', $expire, $expire);
            //Send confirmation email
            $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);
        }
    }
    ?>
    <html>
    <head></head>
    <body>
    <?php echo $output; ?>
    </body>
    </html>
    

    I indicated the changes in the comments.

     

    It works as it should, however, I have been looking for a way to get the songname too, for the purpose of displaying "You have voted for 'This or that song'. Thank you" after the vote has been registered, but I am not getting there (don't forget I am a complete beginner).

    So, how can I get the field 'Song' to display too?

    Like I said, it is only for display purposes, nothing else needs to happen, as now it says (obviously) You voted for "number", which does not say much.

    .

     

    Thanks.

  8. Hi,

    I have found a glitch in the script:

    if someone votes for a certain song which I have in the list twice, performed by different artists, both the song titles get a vote.

    I have tried a number of things so that the script recognises the field "Artist" as well as "Song" and only votes for the chosen song by the particular artist, but I do not seem to be getting anywhere.

     

    Can anyone point me in the right direction please?

    Thank you.

  9. Would this do any good?

     $result = mysqli_query($link, $query);
       $targetAddr = "67.249..*..*";  //yes is two dots
     
    //this code will match any class of 123.123.x.x,
    //you can also do "123.123.123..*" to do anything that is 123.123.123.x
     
    if (ereg($targetAddr, $_SERVER['REMOTE_ADDR'])) {
        //remote address match, do something or don't do anything
    $output = "GET LOST!!!!";
    mysqli_close();
    } else {
       //the rest of my script.
    }
    

    Thanks.

    Changed the echo to $output =

    Wonder if that makes any difference.

  10. Would this do any good?

     $result = mysqli_query($link, $query);
       $targetAddr = "67.249..*..*";  //yes is two dots
     
    //this code will match any class of 123.123.x.x,
    //you can also do "123.123.123..*" to do anything that is 123.123.123.x
     
    if (ereg($targetAddr, $_SERVER['REMOTE_ADDR'])) {
        //remote address match, do something or don't do anything
    echo "GET LOST!!!!";
    mysqli_close();
    } else {
       //the rest of my script.
    }
    

    Thanks.

  11. One other thing, I don't know what it is, but I keep getting votes from American IP addresses (probably automated), for obvious reasons I will not post them here, but the last digits are always different, while the first 4 numbers are the same, eg. xx.xxx.xx.19, then another one (first three exactly the same) xx.xxx.xx.234 etc.

     

    It is unlikely that Americans would vote for or even know my radio station, let alone voting to this extent.

    (Which is why I think a robot or hacker is doing this).

     

    Any advice please?

  12. This was my attempt:

      //Send confirmation email
    	$ipaddress = $_SERVER['REMOTE_ADDR'];
            $to = "beheer@vlaamseradio.tk";
            $subject = "There was a vote";
            $message = "Someone with IP address .$ipaddress voted for $songSafeHtml.";
    		$header = "From: systeem@jinglekot.cu.cc \r\n";
    		$retval = mail($to, $subject, $message, $header);
        }
    

    No syntax errors this time, so I'll see what happens.

×
×
  • 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.