Page 1 of 1

Uploads and MySQL error

Posted: Wed Nov 14, 2007 7:29 pm
by Bogey
I have an upload system and what I want it to do is to upload an image (that works perfectly) and if everything is correct (works) than it would submit the url, name and the comments submitted about the image into the database (doesn't work) and then create an individual page for the image (works perfectly).

I chose an SQL route for this one... here is my PHP...

Code: Select all

<?php
  //setting the values
  $name = $_POST['file-name'];

  //The uploading code
  if (($_FILES["file"]["type"] == "image/gif")
  || ($_FILES["file"]["type"] == "image/jpeg")
  || ($_FILES["file"]["type"] == "image/pjpeg")
  || ($_FILES["file"]["type"] == "image/bmp")
  || ($_FILES["file"]["type"] == "image/png")
  && ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "<p>Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb</p>";

    if (file_exists("images/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      $error = true;
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "images/" . $_FILES["file"]["name"]);
      echo 'Stored in: ' . 'images/' . $_FILES["file"]["name"];
      $imageUrl = 'images/' . $_FILES["file"]["name"];
      $error = false;
      }
    }
  }
else
  {
  echo "<p>Invalid file</p>";
  $error = true;
  }

//Creating the file
if($error === false)
 {
  //MySQL connection
  mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
  //Database connection
  mysql_select_db($dbtable) or die(mysql_error());
  mysql_query("INSERT INTO `imageSharing` (`url`,`Name`,`Description`) VALUES ('$imageUrl','$name','$description')");

//Creating the image file
$filename2 = 'pages/'. $_FILES["file"]["name"] .'.php';
$fp2 = fopen("$filename2", "w");
fwrite($fp2, "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
<head>
<title>". $name ."</title>
<meta name=\"keywords\" content=\"". $keywords .">\" />
<meta name=\"description\" content=\"". $name ."\" />
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<link rel=\"stylesheet\" href=\"../". $cssScript ."\" title=\"". $siteName .">\" media=\"screen\" type=\"text/css\" />
</head>
<body>
<div id=\"wrap\">
<div id=\"header\">". $header ."</div>
<div id=\"container\">
<div id=\"navigation\">
<a href=\"../Index.php\">Home</a>
<a href=\"../Submit.php\">Submit</a>
<a href=\"../Images.php\">Images</a>
<a href=\"../Search.php\">Search</a>
</div>
<div id=\"content\">
<img src=\"../". $imageUrl ."\" alt=\"". $name ."\" /><br /><p class=\"alt\">". $name ."</p>
</div>
</div>
<div id=\"footer\">". $footer ."</div>
</div>
</body>
</html>");
chmod("$filename2", 0755);
fclose($fp2);

//MySQL log off
mysql_close();
 }
else
 {
  print "There was an error.";
 }
?>

Posted: Wed Nov 14, 2007 8:28 pm
by Bogey
I fixed the problem of when it was not submitting the information into the database... it now does that... now what I want is to view the results like I posted above... (in the main - individual page) the following is like a preview of it...

Code: Select all

*********************
*       IMAGE       *
*********************
*    Description    *
*********************
That I want to be viewed in 100px width... the image to be scaled down to width="100px" height="100px" and to have a link around it... in the following format...

Code: Select all

<div class="img"><a href="$url"><img src="$url" width="100px" height="100px" alt="$name" /><br />Name</a></div>
And that in three columns and four rows... so it would look like the following...

Code: Select all

********************* ********************* *********************
*       IMAGE       * *       IMAGE       * *       IMAGE       *
********************* ********************* *********************
*    Description    * *    Description    * *    Description    *
********************* ********************* *********************

********************* ********************* *********************
*       IMAGE       * *       IMAGE       * *       IMAGE       *
********************* ********************* *********************
*    Description    * *    Description    * *    Description    *
********************* ********************* *********************

********************* ********************* *********************
*       IMAGE       * *       IMAGE       * *       IMAGE       *
********************* ********************* *********************
*    Description    * *    Description    * *    Description    *
********************* ********************* *********************

********************* ********************* *********************
*       IMAGE       * *       IMAGE       * *       IMAGE       *
********************* ********************* *********************
*    Description    * *    Description    * *    Description    *
********************* ********************* *********************

Posted: Wed Nov 14, 2007 8:45 pm
by Bogey
For individual pages I want the look and organization to be like the following...

Code: Select all

*********************************
*   image  *description         *
************description         *
*   name   *description         *
*********************************
the image url, description, and name would be taken off of the database... I have no idea on how to do that... can someone giv eme the PHP code to do that? Please... that would be greatly appreciated...

Posted: Wed Nov 14, 2007 8:49 pm
by Bogey
And also, I want it paginated... I know I am probably asking for too much but I have no idea whatsoever on how to do that...

Posted: Thu Nov 15, 2007 6:36 pm
by Bogey
Anyone? I really need help on this one... please

Posted: Sun Nov 18, 2007 9:44 pm
by Bogey
I'm currently using the following script which is bringing me errors right now...

Code: Select all

<?php
    include_once('config.php');

    //MySQL  connection
    mysql_connect($dbhost,  $dbuser,  $dbpass)  or  die(mysql_error());
    //Database  connection
    mysql_select_db($dbtable)  or  die(mysql_error());

//Varible  to  store  all  retrieved  information.
$buffer  =  array();

//Pull  all  the  data  out  of  the  database.
$query  =  "mysql_query(SELECT  url,Name,Description  FROM  images  ORDER  BY  'Name')  or  die(mysql_error()"; 
$results  =  'mysql_query($query)  or  die(mysql_error()';

$myArray  =  array();
while($row  =  mysql_fetch_assoc($query))    {
                $myArray[]    =    $row;
}

foreach($myArray  as  $rowArray)  {
echo  '<img  src="'.  $rowArray['URL']  .'"  alt="'.  $rowArray['NAME']  .'"  /><br  />Description:<br  /><p>'.  $rowArray['DESCRIPTION']  .'</p><br  />';   
}

?>
I get the following error...
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Image distribution\show.php on line 18
Any help?

Posted: Sat Nov 24, 2007 7:33 pm
by Bogey
For the most part, this forum is pretty active.

This is what I'm using right now...

Code: Select all

<?php
  include_once('config.php');

  //MySQL connection
  mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
  //Database connection
  mysql_select_db($dbtable) or die(mysql_error());

//Variable to store all retrieved information.

//Pull all the data out of the database.
$query = "SELECT url, Name, Description FROM images ORDER BY 'Name'";
$results = mysql_query("$query") or die(mysql_error()); 

$myArray = array();
while($row = mysql_fetch_assoc($query))  {
        $myArray[] = $row;
}
echo $rowArray['URL'];
foreach($myArray as $rowArray)  {
echo '<img src="'. $rowArray['URL'] .'" alt="'. $rowArray['NAME'] .'" /><br />Description:<br /><p>'. $rowArray['DESCRIPTION'] .'</p>'; 
}

?>
This is so frustrating... I still get the same error... I can't figure out why :x :x :x

Posted: Sat Nov 24, 2007 7:37 pm
by s.dot
Do it like this:

Code: Select all

$query = 'sql only';
$results = mysql_query($query) or die(mysql_error());

if ($results)
{
     while($row = mysql_fetch_assoc($results))
     {
            ...
      }
}
Edit: I see you are doing it that way in your revised post. Check the mysql_num_rows() of your result set before you loop through it. I'm guessing your query isn't pulling any rows.