Forum Moderators: coopster
I'm facing a problem with mysql and don't know what is the problem as I still learn php/mysql. I use a simple script to upload some images and a file. Everything runs very well untill I choose a name for a file that is allready in the database, the new data just overwrite the old one which gives me allmost two identical results in the db, allmost because only the path to the uploaded images are changed, the comments, name, creation data stay different.
Here is my db:
`ID` bigint(20) NOT NULL auto_increment,
`name` varchar(255) default NULL,
`created` varchar(255) default NULL,
`animated` enum('Yes','No') default 'No',
`size` varchar(255) default NULL,
`logofile` varchar(255) default NULL,
`comments` text,
`imgfile` varchar(255) default NULL,
`author` int(11) default NULL,
`phonetype` enum('T610','S700','K700','K750') default NULL,
`mainimage` varchar(255) default NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=67;
And the script that uploads the files:
if (isset($_GET['1'])){
$phonename = $_POST['name'];
$phonecreated = $_POST['created'];
$phoneanimated = $_POST['animated'];
$phonecomments = $_POST['textarea'];
$phonetype1 = $_POST['type'];
$userloggedin = $_SESSION['myusername'];
$userloggedin = username2num($userloggedin, $userloggedin);
if ((!$phonename) ¦¦ (!$phonecreated) ¦¦ (!$phoneanimated) ¦¦ (!$phonecomments)){
echo "You need to fill in all fields";
}else{
$sql = mysql_query("INSERT INTO phones_phones (name, created, animated, comments, author, phonetype) VALUES ('$phonename', '$phonecreated', '$phoneanimated', '$phonecomments', '$userloggedin', '$phonetype1')");
echo "<br /><br /><hr color=\"#E3E3E3\" size=\"1\"/><br /><tr>";
echo" <td>Screenshots:</td>";
echo" <td><form method=\"POST\" enctype=\"multipart/form-data\" action=\"uploadphone.php?2&phone=$phonename&phonetype=$phonetype1\">";
echo" <input name=\"pic1\" type=\"file\" size=\"40\" /> Small screenshot";
echo" <input name=\"pic2\" type=\"file\" size=\"40\" /> Large screenshot";
echo" <input name=\"file\" type=\"file\" size=\"40\" /> Theme file<br />";
echo " <input type=\"submit\" value=\"Submit\" name=\"B1\"><input type=\"reset\" value=\"Reset\" name=\"B2\"></td>";
Other informations are added with a simple form. I'm really lost on what's going on here, if anybody can help me out I would really appreciate it :)
Many thanks
$sql = mysql_query("INSERT INTO phones_phones (name, created, animated, comments, author, phonetype) VALUES ('$phonename', '$phonecreated', '$phoneanimated', '$phonecomments', '$userloggedin', '$phonetype1')");
$lastid = mysql_insert_id($sql);
echo" <td><form method=\"POST\" enctype=\"multipart/form-data\" action=\"uploadphone.php?2&phone=$lastid\">";
something like that I assume