Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-28-2006, 05:51 PM Another mySQL Error
Skilled Talker

Posts: 69
Trades: 0
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?
Reality15 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-28-2006, 08:41 PM Re: Another mySQL Error
Experienced Talker

Posts: 40
Location: Denmark
Trades: 0
Do you by any chance use TINYINT as column type for the primary key? If so, change it to another column type that can store larger values
dennismp is offline
Reply With Quote
View Public Profile Visit dennismp's homepage!
 
Old 04-28-2006, 08:43 PM Re: Another mySQL Error
Skilled Talker

Posts: 69
Trades: 0
Like what?
Reality15 is offline
Reply With Quote
View Public Profile
 
Old 04-29-2006, 05:02 AM Re: Another mySQL Error
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
SMALLINT (65535), MEDIUMINT (16777215) INT (4294967295), BIGINT (18446744073709551615)

all as unsigned of course
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Another mySQL Error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20091 seconds with 12 queries