Forum Moderators: coopster

Message Too Old, No Replies

Mysql data doubled

when uploading files with same name

         

Valhala

6:57 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



Hi all,

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

Valhala

8:11 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



Ah I'm dumb it's "uploadphone.php?2&phone=$phonename" that caused my problem ...

Now can anyone know how to use the last ID instead, I know that it"s select last_insert_id but can't make it work.

[edited by: jatar_k at 8:15 pm (utc) on June 10, 2005]
[edit reason] lang [/edit]

jatar_k

8:15 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



do you mean
[php.net...]

sry, I am not totally sure that I understand the question

Valhala

8:45 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



Yes that's it, now I need to make it work in place of "uploadphone.php?2&phone=$phonename"", like uploadphone.php?2&phone=$id"

Any idea before I pass again a whole day to figure it out :)

jatar_k

8:49 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



since it works after the insert then you could do it this way

$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

Valhala

8:54 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



Allready tryed that but I get an error:

Warning: mysql_insert_id(): supplied argument is not a valid MySQL-Link resource in ../public_html/test/uploadphone.php on $lastid = mysql_insert_id($sql);

jatar_k

8:55 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



oops, my fault, pass it the connection var from your mysql_connect, not $sql

Valhala

9:17 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



Many thanks it worked, I get the correct ID but nothing shows up in the database but I suspect that I have to make 2/3 changes before. Can I pm you if I need more help?

Many thanks again, was going crazy here :)

jatar_k

9:32 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> pm you

you can but your best bet is to just post a thread, then you aren't relying on my hectic schedule, there are tons of folk around that can help. :)