PDA

View Full Version : In need of some mysql help


Elem
01 Jul 2003, 02:41
I could really use some help on this problem i can't get around....and with my limited knowledge of mysql this is causing some problems

Ok i guess i should start off with what i'm trying to do. I have made a file uploader. Now what i want to do is when the user ventures to the upload area it shows them a link for each uploaded file. Also i should mention the script is being run from within vb...so it is using vb's db.

Here's what i currently have
$showpic = $DB_site->query("SELECT uploadname FROM user ORDER BY uploadname DESC");
$picname = $DB_site->fetch_array($showpic);

$upload_bits="";

$piccount = $DB_site->num_rows($showpic);
if ($piccount == 0) {
eval ("\$upload_bits .= \"".gettemplate("upload_none")."\";");
} else {
eval ("\$upload_bits .= \"".gettemplate("upload_isthere")."\";");
}

uploadname is a column i have added to the users table. Upload_none template says there are no pics...and the Upload_isthere template is supposed to show the links

once an image is uploaded this is the query i'm using
$DB_site->query("INSERT INTO user (uploadname) VALUES ('$imname')");
$imname is $_FILES['userfile']['name']

Upload_isthere looks like this
<a href="$shorturl/$picname[uploadname]">$shorturl/$picname[uploadname]</a>

As it is right now...it only shows the file that was last uploaded...nothing more..even though there are 2 images in the db

So my question is how do i get it to display all of the images uploaded?

Also how do i get it so it only shows the pics uploaded by that person only?

I really appreciate any help...since this is my first hack from scratch and i'm really lost :P

Cloudrunner
01 Jul 2003, 03:23
unset($upload_bits); //clears the variable
$showpic = $DB_site->query("SELECT uploadname FROM user WHERE userid = '".$bbuserinfo['userid']."' ORDER BY uploadname DESC"); //sets the query, and only shows uploads from user viewing page.
if ($DB_site->num_rows($showpic) == 0){ //check for number of rows, if none, then display error page
eval("standarderror(\"".gettemplate("upload_none")."\");"); //provides an error page with redirect
} else { //or else display downloads page
while($picname = $DB_site->fetch_array($showpic)); //loop until last row in table
$picname = $picname['uploadname']; //You will have to call this variable ($picname) in the template 'upload_isthere' for it to show up in the template
eval ("\$upload_bits .= \"".gettemplate("upload_isthere")."\";"); //setup the variable to display the template
} // close the while statement
eval("dooutput(\"".gettemplate('upload_index')."\");"); //change upload_index to the template for the actual display of the page this page would need to use the variable $upload_bits
} //close the if statement

Hope that helps, follow the comments and you should see the steps.

Elem
01 Jul 2003, 03:55
hey thanks for your help...although it's not quite fully working yet

now on the page is it just showing the url once...without the filename attached.

this is the current upload_ishere
<tr><td bgcolor="{tableheadbgcolor}" colspan="2"><normalfont color="{tableheadtextcolor}" class="thtcolor"><a href="$shorturl/$picname">$shorturl/$picname[uploadname]</a></normalfont></td></tr>

this is the template which is the index for the hack...i apologize for it being long but it is the full thing incase there is an issue with it

{htmldoctype}
<html>
<head>
<title>$bbtitle - $username's Picture Upload</title>
$headinclude
</head>
</html>
<body>
$header
<!-- breadcrumb -->
<table bgcolor="{pagebgcolor}" class="bordert" border="0" width="{tablewidth}" cellpadding="0" cellspacing="0">
<tr><td>

<table cellpadding="2" cellspacing="0" border="0" width="{contenttablewidth}" {tableinvisibleextra} align="center">
<tr>
<td><img src="{imagesfolder}/vb_bullet.gif" align="middle" alt="vBulletin">
<normalfont><b><a href="index.php?s=$session[sessionhash]">$bbtitle</a> &gt;
Photo upload for $bbuserinfo[username]</b></normalfont></td>
<td align="right">$forumjump</td>
</tr>
</table>
<!-- /breadcrumb -->
<br>
$cpnav
<br>


<form enctype="multipart/form-data" action="test.php" method="post">


<table cellpadding="{tableouterborderwidth}" cellspacing="0" border="0" bgcolor="{tablebordercolor}" {tableouterextra} width="{contenttablewidth}" align="center"><tr><td>
<table cellpadding="4" cellspacing="{tableinnerborderwidth}" border="0" {tableinnerextra} width="100%">
<tr>
<td bgcolor="{tableheadbgcolor}" colspan="2"><normalfont color="{tableheadtextcolor}" class="thtcolor"><b>Upload - $bbuserinfo[username]</b></normalfont></td>
</tr>

$upload_bits

<tr>
<td bgcolor="{firstaltcolor}"><normalfont><b>Upload:</b></normalfont></td>
<td bgcolor="{firstaltcolor}"><normalfont><input name="userfile" type="file"></normalfont>
</td>
</tr>
</table>
</td></tr></table>

<br>

<table cellpadding="2" cellspacing="0" border="0" width="{contenttablewidth}" {tableinvisibleextra} align="center">
<tr>
<td align="center"><normalfont>
<input type="hidden" name="action" value="upload">
<input type="submit" value="Upload">
</normalfont></td>
</tr>
</table>

</form>

$footer

</body>
</html>

thanks for all your help

Cloudrunner
01 Jul 2003, 05:46
upload_ishere:

<tr>
<td bgcolor="#1D6AA0" colspan="2">
<normalfont color="#EEEEFF" class="thtcolor">
<a href="$bburl/$picname">$bburl/$picname</a>
</normalfont>
</td>
</tr>
unless of course $shorturl is defined in the script elsewhere it would be best to use $bburl/path/$picname...

upload_index:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>$bbtitle - $bbuserinfo[username]'s Picture Upload</title>
$headinclude
</head>
</html>
<body>
$header
<!-- breadcrumb -->
<table bgcolor="#0E3652" class="bordert" border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<table cellpadding="2" cellspacing="0" border="0" width="95%" align="center">
<tr>
<td>
<img src="http://www.vbulletin.org/forum/images/vb_bullet.gif" align="middle" alt="vBulletin">
<normalfont>
<b><a href="index.php?s=$session[sessionhash]">$bbtitle</a> &gt;
Photo upload for $bbuserinfo[username]</b>
</normalfont>
</td>
<td align="right">
$forumjump
</td>
</tr>
</table>
<!-- /breadcrumb -->
<br>
$cpnav
<br>
<form enctype="multipart/form-data" action="test.php" method="post">
<table cellpadding="0" cellspacing="0" border="0" bgcolor="#0A293E" width="95%" align="center">
<tr>
<td>
<table cellpadding="4" cellspacing="1" border="0" width="100%">
<tr>
<td bgcolor="#1D6AA0" colspan="2">
<normalfont color="#EEEEFF" class="thtcolor">
<b>Upload - $bbuserinfo[username]</b>
</normalfont>
</td>
$upload_bits
<td bgcolor="#13486D">
<normalfont>
<b>Upload:</b>
</normalfont>
</td>
<td bgcolor="#13486D">
<normalfont>
<input name="userfile" type="file">
</normalfont>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<table cellpadding="2" cellspacing="0" border="0" width="95%" align="center">
<tr>
<td align="center">
<normalfont>
<input type="hidden" name="action" value="upload">
<input type="submit" value="Upload">
</normalfont>
</td>
</tr>
</table>
</form>
$footer
</body>
</html>

Do a side by side file compare using beyond compare2 (or equivalent) and you'll see where I made the changes...Basically the reason your link would show only once is that you had two table rows defined one after another...no good...also, make sure that the userid is the same in both items....

Now, one thing, if you are using the user table to define the upload pics, then you would be better off using the uploadname field as an id to query off another table that has the filename stored...that way each user can have multiple uploads. The way it is setup now will only allow one upload per user. The reason is that each user only uses one row in the table, thus only allowing one piece of data per field. Thus, the new query that I provided you will only show one field.

If you want, we can hook up this weekend via any of the messengers listed in my profile and we can walk through the code abit and see what we can do with it...but for now without more background on the hack, I canna help any more than what I have done here.