Jump to content


Photo

php picture up-loading, with mysql-support


  • Please log in to reply
5 replies to this topic

#1 ExosSho

ExosSho
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 June 2006 - 06:57 PM

i started writing a little program, which uploads files (till now pics prefered) to the folder, which contains the PHP-file.(i know; noobish)
on the first page, u select the file u want to upload, and may enter a Title( in order to enable a gallery-database with mysql);
second page shows u wether the data has been sent to the database(THIS IS THE MAIN PROBLEM because it wont save anything to the database), info about the file(like type etc.), where its gonna be saved, or if a file(pic) alrady exists with the same name, in this case the script should view the "new-version"(which cant be uploaded) and the "old-version"(which alrady exists)
this is the formular where u enter the stuff
<html>
<head>
<link rel="stylesheet" type="text/css" href="style_1.css">
</head>
<body>
<div style="background-color:#efefef;width:480px;border:5px solid #00c000;padding:1px;margin:0px auto;text-align:center;">
<form enctype="multipart/form-data" action="showit.php" method="post">
data: <input name="upfile" type="file" size="25">
<p>titel: <input name="titel" size="25">
<p><input type="submit" value="send" name="send">
</form>
</div>
</body>
</html>


this file shows the pics, and should send data to mysql
<html>
<head>
<link rel="stylesheet" type="text/css" href="style_1.css">
</head>
<body>
<div  style="background-color:#efefef;width:480px;margin:0px auto;border:5px solid #00c000;padding:1px;text-align:center;">
<?php
    echo "<h3><ul><k>control:</k></ul></h3><p>";
    echo "original-name: <zitat>$upfile_name</zitat><br>";
    echo "size: <zitat>$upfile_size Byte</zitat><br>";
    echo "type: <zitat>$upfile_type</zitat><br>";

    $dname = explode(".",$upfile_name);
    $dnamesize = count($dname);
    $upfile_ext = $dname[$dnamesize-1];
    echo "data-extension: <zitat>" . $upfile_ext . "</zitat><br>";
    list($headw, $headh) = getimagesize($upfile);
    echo "original-properties: <zitat>" . $headw . "x" . $headh . "</zitat><br>";
    $verz = getcwd();
     $exi = $verz ."/". $upfile_name;
    if($upfile_size>0 && !file_exists($exi))
    {
    echo "new home of " . $upfile_name . " : <zitat>" . $verz. "</zitat><br>";
        copy($upfile,$upfile_name);
        echo "data has been copied in: <zitat>$upfile_name</zitat><br>";
        if($headw>470)
        {; 
        echo '<img src="'.$upfile_name.'" width="470" alt="'.$title.'" />'; 
        } 
        else
        {
        echo '<img src="'. $upfile_name .'"><br>'; 
        }
    }
    else if(file_exists($exi))
    {
         copy ($upfile, "redrasterblue.png");
         echo "<r>a file with the name: <zitat>" . $upfile_name . "</zitat> does already exist!</r><br>";
         echo "<table>";
         echo "<tr><td><k>new-" . $upfile_name . "</k></td><td><k>old-" . $upfile_name . "</k></td></tr>";
         echo '<tr><td><img src="redrasterblue.png" width="200"></td><td><img src="'.$upfile_name.'" width="200"></td></tr>'; 
         echo "</table><br>";
        }
        else
         {
         echo "copy-error: data does not exist";
         echo " or false data-type";
    }
    if(isset($_POST['send']))
{
    mysql_connect(localhost,root)
    or die("no connection to mysql");
    mysql_select_db("daten")
    or die("not able to select database");
    $sqlab = "insert into upload (name, typ, titel) values ($upfile_name, $upfile_type, $titel)";
    mysql_query($sqlab);
 $num = mysql_affected_rows();
   }
 if ($num>0)
      {
         echo "<g>one data has been added<p></g>";
      }
      else if($num<=0)
      {
         echo "<r>an Error appeared, ";
         echo "no data has been added to mysql<p></r>";
}
?>
</div>
</body>
</html>

thanks for any help^^

#2 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 21 June 2006 - 07:20 PM

Try this:

@mysql_connect("localhost", "username", "password") or die("Could not connect to database");
@mysql_select_db("database") or die("Could not connect to database music");

$query = ("INSERT INTO upload (name,typ,titel) VALUES ('$upfile_name','$upfile_type','$titel')");
$result = mysql_query($query) or die('Query failed: ' . mysql_error());


$num = mysql_affected_rows($result);
   }
if ($num>0)
      {
         echo "<g>one data has been added<p></g>";
      }
      else if($num<=0)
      {
         echo "<r>an Error appeared, ";
         echo "no data has been added to mysql<p></r>";
}


#3 ExosSho

ExosSho
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 June 2006 - 07:37 PM

ok, first thank u for quick(and helpful) replie, now the data is beeing send to the data base,...
but now there appears a error
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in C:\apachefriends\xampp\htdocs\upload\showit2.php on line 60
[/quote]


#4 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 21 June 2006 - 07:40 PM

which line is 60

#5 ExosSho

ExosSho
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 June 2006 - 07:49 PM

[!--quoteo(post=386554:date=Jun 21 2006, 02:40 PM:name=cmgmyr)--][div class=\'quotetop\']QUOTE(cmgmyr @ Jun 21 2006, 02:40 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
which line is 60
[/quote]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
$num = mysql_affected_rows($result);
[/quote]

ok i got it
this is what it was
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$num = mysql_affected_rows($result);[/quote]
but if u delete the "$result" in the brackets it works fine
thank u again for your help ^^

#6 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 21 June 2006 - 07:51 PM

sorry, try deleting $result so it's like: $num = mysql_affected_rows();





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users