Hello everyone...
I just finished writing an "add music" script for my site's staff to make it easier on them. Here is the main page where they put in information:
PHP Code:
<?php
include "header.php";
?>
<td width="100%">
<div align="center">
<center>
<table border="0" width="502" cellspacing="0" bgcolor="#000000">
<tr>
<td width="100%">
<table border="0" width="100%" bgcolor="#FFFFFF" cellspacing="0" cellpadding="5" background="images/background_articles.gif">
<tr>
<td width="500" height="10"></td>
</tr>
<tr>
<td width="500"><font face="Arial"><b>Add
New Music</b></font>
<p><font face="Arial" size="2"><u>Notes
on adding music:
</u><br>
~If you have any questions, PM Reality
on the forums and he'll get back to you
soon.</font></p>
<form method="POST" action="postsound.php">
<p align="center"><font size="2" face="Arial">Username
: </font><input type="text" name="username" size="20"
<?php
if ($_POST['username']){
?>
value="$username"
<?php
}
else {
}
?>
><br>
<font size="2" face="Arial">Password :
</font><input type="text" name="password" size="20"
<?php
if ($_POST['password']){
?>
value="$password"
<?php
}
else {
}
?>
></p>
<p align="center"><font size="2" face="Arial">Midway
: </font><select size="1" name="category">
<option value="Front Gate">Front
Gate</option>
<option value="Boardwalk">Boardwalk</option>
<option value="General Midways">General
Midways</option>
<option value="Wicked Twister Midway">Wicked
Twister Midway</option>
<option value="Frontiertown and Trail">Frontiertown
and Trail</option>
<option value="Top Thrill Dragster">Top
Thrill Dragster</option>
<option value="Millennium Force">Millennium
Force</option>
<option value="Magnum XL-200">Magnum
XL-200</option>
<option value="Raptor">Raptor</option>
<option value="Mantis">Mantis</option>
<option value="Halloweekends">Halloweekends</option>
</select>
<p align="center"><font size="2" face="Arial">Song
Name : </font><input type="text" name="songname" size="20"><br>
<font size="2" face="Arial">Song
Artist : </font><input type="text" name="artist" size="20"></p>
<p align="center"><font size="2" face="Arial"><b>Please
check your song for any errors before
posting it!</b>
</font></p>
<p align="center">
<input type="submit" value="Post" name="B1"></p>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</div>
</td>
<?php
include "footer.php";
?>
And here is the result page, postsound.php...
PHP Code:
<?php
$date = date('Y-m-d H:i:s');
$username = $_POST['username'];
$password = $_POST['password'];
$songname = $_POST['songname'];
$artist = $_POST['artist'];
$category = $_POST['category'];
//CONNECT TO THE DATABASE
$dbh=mysql_connect ("REMOVED", "REMOVED", "REMOVED") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("REMOVED");
//WHOSE CHILD IS THIS?!?!?
$result = mysql_query("SELECT `id` FROM `staff` WHERE `username` LIKE CONVERT(_utf8 '$username' USING latin1) COLLATE latin1_general_ci AND `password` = CONVERT(_utf8 '$password' USING latin1) COLLATE latin1_general_ci");
if (!$result) {
echo mysql_error();
exit;
}
while ($array = mysql_fetch_array($result)) {
$staffid = $array['id'];
}
//WHOSE CHILD IS THIS?!?!?
$result = mysql_query("INSERT INTO `sounds` (`id`, `date`, `staffid`, `category`, `songname`, `artist`) VALUES ('NULL', '$date', '$staffid', '$category', '$songname', '$artist');");
if (!$result) {
echo mysql_error();
exit;
}
include "header.php";
?>
<td width="100%">
<div align="center">
<center>
<table border="0" width="502" cellspacing="0" bgcolor="#000000">
<tr>
<td width="100%">
<table border="0" width="100%" bgcolor="#FFFFFF" cellspacing="0" cellpadding="5" background="images/background_articles.gif">
<tr>
<td width="500" height="10"></td>
</tr>
<tr>
<td width="500">
<p align="center"><font face="Arial"><b>Article
Added!</b></font>
<p align="center"><font face="Arial" size="2"><a href="index.php"><font color="#000000">Return
to the main page</font></a></font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</div>
</td>
<?php
include "footer.php";
?>
I've been using it for a while with no problems, but I just tried to post an entry and I got this error:
Duplicate entry '127' for key 1
Any idea why?
|