Jump to content

Need help with a short script.


mrfdes

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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