• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Insert to mysql

iLLuSioN

New Member
Hey got a littel problem with a upload script that is a part of a news script (Rose News)

the problem is that the upload part dosent work ! when i want to add an image with upload, it fills everything in fine but it dosent fil in the url to the image in the database ! so the image just shows a "red x"

so i hope somebody knows how to make the database insert the right value. ill just post the hole upload file cus i have no idea what to post of the code that needs changes :confused5

i cant contact the author cus he went out of php biz :cry2:

PHP:
<?
session_start();
include ('includes/functions.php');
# set up the listing function

######################################
function list_files() {
global $variable;
global $userinfo;
dbconnect();
# Do Images First
$query2 = "SELECT * FROM $variable[smiles] WHERE (smileytype = 'image' ) ORDER BY $variable[smiles].smileytext ASC";
$result = mysql($variable[dbname], $query2 );
$num = mysql_numrows($result);
if ($num != 0) { ?>
<table width="98%" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
	<td colspan="4" class="titlebar">Available Images</td>
</tr>
<tr><td>Image</td><td>File Names</td><td>File Size</td><td>Add?</td></tr>
<?
$i = 0; 
while ($i < $num) :
$theid = mysql_result($result,$i,"smileyid");
$filename = mysql_result($result,$i,"smileytext");
$filesize = mysql_result($result,$i,"smileyalt");

#images
print "<tr>
<td><img src=\"../uploads/$filename\" width=\"60\" height=\"60\" border=\"0\" alt=\"\"></td>
<td>$filename</td>
<td>$filesize</td>
<td><a href=\"javascript:fileadd('[image|$filename|NONE]')\"><img src=\"includes/none.gif\" width=\"24\" height=\"24\" alt=\"Insert Image\" border=\"0\"></a> 
<a href=\"javascript:fileadd('[image|$filename|LEFT]')\"><img src=\"includes/left.gif\" width=\"24\" height=\"24\" alt=\"Insert Image Aligned Left\" border=\"0\"></a> 
<a href=\"javascript:fileadd('[image|$filename|RIGHT]')\"><img src=\"includes/right.gif\" width=\"24\" height=\"24\" alt=\"Insert Image Aligned Right\" border=\"0\"></a> 
";
if ($userinfo[userlevel] > 69) { print " <a href=\"javascript:usure('Delete this image?', 'upload.php?funky=remove&id=$theid')\"><img src=\"includes/delete.gif\" width=\"24\" height=\"24\" alt=\"Delete this image from file\" border=\"0\"></a>";}
print "</td></tr>";
$i++;
endwhile;
}
print "</table>";


# Do Files Now
$query2 = "SELECT * FROM $variable[smiles] WHERE (smileytype = 'file' ) ORDER BY $variable[smiles].smileytext ASC";
$result = mysql($variable[dbname], $query2 );
$num = mysql_numrows($result);
if ($num != 0) { ?>
<br>
<table width="98%" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
	<td colspan="3" class="titlebar">Available Files</td>
</tr>
<tr><td>File Names</td><td>File Size</td><td>Add?</td></tr>
<?
$i = 0; 
while ($i < $num) :
$theid = mysql_result($result,$i,"smileyid");
$filename = mysql_result($result,$i,"smileytext");
$filesize = mysql_result($result,$i,"smileyalt");

#images
print "<tr>
<td>$filename</td>
<td>$filesize</td>
<td><a href=\"javascript:fileadd('[file|$filename|]')\">Add</a>";
if ($userinfo[userlevel] > 69) { print " | <a href=\"javascript:usure('Delete this file?', 'upload.php?funky=remove&id=$theid')\">Remove</a>";}
print "</td></tr>";
$i++;
endwhile;
}
print "</table>";
}
##########################################################

# check they are logged in and stuff
$loggedin = $HTTP_COOKIE_VARS["con-Logger"];
# if not logged in re-direct to index.php
if (($userinfo[userlevel] == '') OR ($loggedin != "1") OR ($userinfo[username] == '')) {
Header("Location: index.php");
}

#############################
else {

#now check FUNKY

#remove file - admins only
if ($funky == 'remove') {
if ($userinfo[userlevel] > 69) {
dbconnect();
$query2 = "SELECT smileytext FROM $variable[smiles] Where (smileyid = '$id')";
$result = mysql($variable[dbname], $query2);
$num = mysql_numrows($result);
if ($num != 0) { 
$filename = mysql_result($result,$i,"smileytext");
$PATH = "../uploads/" . $filename;
unlink($PATH);
$query2 = "DELETE FROM $variable[smiles] Where (smileyid = '$id')";
$result = mysql($variable[dbname], $query2);
}
Header("Location: upload.php");
}
}

# upload file
elseif ($funky == 'do_upload') {
$dirname = "../uploads";
$filename = $userfile_name;
copy($userfile, $dirname."/".$filename) or die("<b>Error:</b> could not copy file."); 
unlink($userfile) or die("<b>Error:</b> could not delete uploaded file.");

if (ereg("image", $userfile_type)) {$type = 'image';}
else {$type = 'file';}
dbconnect();
$query2 = "INSERT INTO $variable[smiles] VALUES('NULL', '$title', '$thenews', '$thedate', '$userinfo[userid]', '$cat', '$comments', '0')";
$query2 = "INSERT INTO $variable[smiles] VALUES('', '$type', '$userfile_name', '', '$userfile_size')";
mysql_db_query($variable[dbname],$query2) or Die (mysql_error());
Header("Location: upload.php");
}

# else just print the page and stuff
else { ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title>Files and Stuff</title>
	<link rel="STYLESHEET" type="text/css" href="stylesheet.css">
</head>
<? include ('includes/javabits.inc'); ?>
<body>
<? 
# if staff or above offer to upload new
if ($userinfo[userlevel] > 49) { ?>
<script>
function send_file() {
if (theform.userfile.value.length == 0) {
alert ('Please select a file.')
theform.userfile.focus ()
return false
}
stuff.innerHTML='Uploading... This may take a while'
theform.send.value = 'Uploading...'
theform.submit()
return true
}
</script>
<form enctype="multipart/form-data" action="<? echo $PHP_SELF ?>" method="post" name="theform">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000">
<input type="hidden" name="funky" value="do_upload">

<table width="98%" border="0" cellspacing="2" cellpadding="2" align="center" class="menutable">
<tr><td>
Upload New file: <input name="userfile" type="file"> <input type="button" name="send" value="Send File" onClick="send_file();">
</td></tr>
<tr>
<td id="stuff"><div align="center">Use this form to upload files.</div></td>
</tr>
</table>
</form>
<? } ?>

<? list_files(); ?>

</body>
</html>
<? }







}
#############################
 
I thought i as going mad for a minute, i thought "i'm sure i've already answered this :confused5"

Go check your thread on WHT :p
 
Back
Top