mrfdes Posted April 7, 2014 Share Posted April 7, 2014 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. Link to comment https://forums.phpfreaks.com/topic/287593-need-help-with-a-short-script/ Share on other sites More sharing options...
X5HOST Posted April 7, 2014 Share Posted April 7, 2014 Hi mrfdes, I would seriously consider using some kind of 2NF or possibly 3NF within your database, having all of the details within one row is a little in-efficient. Link to comment https://forums.phpfreaks.com/topic/287593-need-help-with-a-short-script/#findComment-1475319 Share on other sites More sharing options...
mrfdes Posted April 7, 2014 Author Share Posted April 7, 2014 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. Link to comment https://forums.phpfreaks.com/topic/287593-need-help-with-a-short-script/#findComment-1475322 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.