Forum Moderators: coopster

Message Too Old, No Replies

Upload & Query MySQL Info Database with image files

content management database with information and photos

         

alcheme

8:11 pm on Dec 28, 2004 (gmt 0)

10+ Year Member



Hello,

I want a database I can enter information and upload a photo from a web form. Then I want to query that database for the text info with its related photo and display it (formatted) in a browser (html).

Summary:

1. upload photo's and text information to database with my add article form.
2. Query the database and page the results with the text and related photo.

It comes in three parts:

1. add_article.php [Text / Photo Upload Form]
2. insert_article.php [Inserts into database]
3. articles.php [View Output]

Here is what I have this far:

add_article.php

<form action="insert_article.php" method="post" enctype="multipart/form-data" name="insert_article" id="insert_article">

Author

<select name="authordrop" id="authordrop">
<option>-- select one ---</option>
<option>Name 1</option>
<option>Name 2</option>
<option>Name 3</option>
</select>

Or

<input name="authortext" type="text" id="authortext" size="30">

Issue #

<select name="issue" id="issue">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>

Section</td>

<select name="section" id="section">
<option selected>-- select one --</option>
<option value="Section 1">Section 1</option>
<option value="Section 2">Section 2</option>
</select>

Upload Photo

<input name="photo" type="file" id="photo">

Title

<input name="title" type="text" id="title" size="50">

Article

<textarea name="content" cols="50" rows="8" wrap="PHYSICAL" id="content"></textarea>

<input name="submit" type="submit" id="submit" value="Register Article in Database">

</form>


--> Next Page
insert_article.php

// NEED HELP WITH CORRECT UPLOADING CODE HERE -->

<?php

if ($photo_name!= "") {
$photoloc = "/home/*****/public_html/images/photo/$photo_name";
@copy("$photo" , "$photoloc")

or die("Couldn't Upload Your File.");

} else {

die("No File Specified");

}

// <--

$db=mysql_connect ("localhost", "db_user", "db_password") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ("db_name", $db);

$insert_date = date("Y-m-d H:i:s");

$content=ereg_replace(10,"<br>",$content);

$content = ereg_replace("www.([a-z])*.([a-z]*)","<a class=\"Link\" href=\"http://\\0\">\\0</A>", $content);

$content = ereg_replace("([a-z])*@([a-z]*).([a-z]*)","<a class=\"Link\" href=\"mailto:\\0\">\\0</A>", $content);

if($authortext) {
$author = $authortext;
}
else {
$author = $authordrop;
}

// NEED HELP WITH INSERTING PHOTO FILE NAME HERE -->

if($photo==1) {
$sql = $sql = "INSERT INTO articles (section, issue, title, author, insert_date, content) VALUES ('$section','$issue','$title','$author','$insert_date','$content','1')";
} else {
$sql = "INSERT INTO articles (section, issue, title, author, insert_date, content) VALUES ('$section','$issue','$title','$author','$insert_date','$content')";
}

// <--

$result = mysql_query($sql);

?>


--> Next Page
articles.php

<?php

include("*******");

$result = mysql_query("SELECT * FROM articles WHERE issue ='3' ORDER BY id DESC",$db);

if ($myrow = mysql_fetch_array($result)) {

$issue=$myrow["issue"];
$section=$myrow["section"];
$photo=$myrow["photo"];

echo "<table border=0>\n";

echo "<tr><td><h1>MY ARTICLES :: Issue # $issue</h1></td></tr>\n";
echo "<tr><td><h2>In This Issue</h2></td></tr>\n";

do {

// NEED TO QUERY/PRINT & FORMAT IMAGES HERE -->

printf("<tr><td><p><b>%s</b></p></td></tr>
<tr><td><p><b>%s</b></p></td></tr>
<tr><td><p>By: %s</p></td></tr>
<tr><td>%s<p>%s</p></td></tr>
<tr><td><hr></td></tr>\n", $myrow["section"], $myrow["title"], $myrow["author"], $myrow["photo"], $myrow["content"]);

// Need To: Left Align Photo (align with text)
// Need To: Format Size of Photo (110 px wide)
// <--

} while ($myrow = mysql_fetch_array($result));

echo "</table>\n";

} else {

echo "<table border=0>\n";
echo "<tr><td>Sorry, no Articles in this Section at this time!</td></tr>\n";
echo "<tr><td>&nbsp;</td></tr>\n";
echo "</table>\n";

}

?>

Can anyone help?

~Shane

jatar_k

4:09 pm on Dec 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> Can anyone help?

I am not understanding what you need help with. What is the problem that you are running into?