problems uploading files to a mysql database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cs1h
Forum Newbie
Posts: 13
Joined: Fri Aug 31, 2007 11:39 am

problems uploading files to a mysql database

Post by cs1h »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi, 

I am trying to upload photos to a mysql databse but with no luck. I'm not getting any error messages, the problem is that nothing appears in the database. 

the form proccessor is as follows,

Code: Select all

<?php 
mysql_connect("lxxx","axxx","cxxx"); 
mysql_select_db("real"); 
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); 
$result=MYSQL_QUERY("INSERT INTO items (continent,country,type,Email,Title,Abstract,Article,data,filename,filesize,filetype) ". "VALUES ('menuSubjectsDMA','menuFilesDMA','Catagory','$Email','$title','$message','$messagetwo','$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"); 
$id= mysql_insert_id(); 
print "<p>File ID: <b>$id</b><br>"; 
print "<p>File Name: <b>$form_data_name</b><br>"; 
print "<p>File Size: <b>$form_data_size</b><br>"; 
print "<p>File Type: <b>$form_data_type</b><p>"; 
print "To upload another file <a href=http://www.myroho.com/add.html> Click Here</a>"; 
?> 

the form is as follows, 

<FORM name=myform action=send-mail.php method=post enctype="multipart/form-data">
<table border="0" width="588" cellspacing="0" cellpadding="0" id="table9">
<tr>
<td width="574">
<table border="0" width="574" cellspacing="0" cellpadding="0" id="table10">
<tr>
<td width="14" height="28" background="line_left_corner_top.png">&nbsp;</td>
<td height="28" background="line_top.png" width="546" colspan="3">&nbsp;</td>
<td width="14" height="28" background="line_right_corner_top.png">&nbsp;</td>
</tr>
<tr>
<td width="14" background="line_left.png" rowspan="35" bgcolor="#FFFFFF">&nbsp;</td>
<td colspan="3" width="546" bgcolor="#FFFFFF"><font color="#00518D"><span class="style10">
Submit Articles to Roaming Hordes Magazine</span></font></td>
<td width="14" background="line_right.png" rowspan="35" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr>
<td colspan="3" width="546" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr>
<td colspan="3" width="546" bgcolor="#FFFFFF"><span class="style51">
Adding to the members' magazine is easy. Simply fill 
out the form below to submit an article <small>(all fields are required to submit). </small></span></td>
</tr>
<tr>
<td colspan="3" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style68"><font color="#EE7F01">1</font></span><span class="style62"><font color="#EE7F01">.</font></span><span class="style62"> E<span class="style78">mail:</span></span></td>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td bgcolor="#FFFFFF"><label>
<input name="Email" type="text" id="Email" size="28" maxlength="250">
</label></td>
</tr>
<tr>
<td colspan="3" width="546" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr>
<td width="546" align="left" valign="top" bgcolor="#FFFFFF"><span class="style68"><font color="#EE7F01">2</font></span><span class="style62"><font color="#EE7F01">.</font></span> <span class="style62">T<span class="style78">itle:</span></span></td>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td style="width: 421px" align="left" valign="top" bgcolor="#FFFFFF">
<input name="title" type="text" class="userpass" id="title" style="width: 421" value="" size="28" maxlength="250"></td>
</tr>
<tr>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td style="width: 421px" align="left" valign="top" bgcolor="#FFFFFF">&nbsp;			
</td>
</tr>
<tr>
<td width="546" height="20" bgcolor="#FFFFFF">
<span class="style58"><font color="#000000">(20 character limit)</font></span></td>
<td width="546" height="20" bgcolor="#FFFFFF">&nbsp;</td>
<td style="width: 421px" align="left" valign="top" height="20" bgcolor="#FFFFFF">
<span class="style58"><font color="#00518D"><em>i.e.</em>							catchy description of article's content</font></span></td>
</tr>
<tr>
<td colspan="3" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr>
<td colspan="3" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF">
<span class="style68"><font color="#EE7F01">3</font></span><span class="style62"><font color="#EE7F01">.</font>A<span class="style78">bstract:</span></span>
<p class="style58">
<font color="#00518D"><em>i.e.</em> short overview and introduction to full article</font></p>
<p class="style58"><font color="#000000">(300 character limit)</font></p>
<p>&nbsp;</td>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" style="width: 421" bgcolor="#FFFFFF"><font size="1" face="arial, helvetica, sans-serif"><br>
<textarea name=message wrap=physical cols=50 rows=7 onKeyDown="textCounter(this.form.message,this.form.remLen,300);" onKeyUp="textCounter(this.form.message,this.form.remLen,300);"></textarea>
<br>
<input readonly type=text name=remLen size=3 maxlength=3 value="300"> 
<font face="Verdana, Arial, Helvetica, sans-serif">characters left</font></font><font face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font>&nbsp;</td>
</tr>
<tr>
<td colspan="3" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr>
<td colspan="3" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF"><span class="style68"><font color="#EE7F01">4</font></span><span class="style62"><font color="#EE7F01">.</font></span> <span class="style62">A<span class="style78">rticle:</span></span>
<p><span class="style58">
<font color="#00518D"><em>i.e.</em> full article</font></span></p>
<p><span class="style58"><font color="#000000">(4000 character limit)</font></span></p>
<p>&nbsp;</td>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" bgcolor="#FFFFFF"><font size="1" face="arial, helvetica, sans-serif"><br>
<textarea name=messagetwo wrap=physical cols=50 rows=7 onkeydown="textCounter(this.form.messagetwo,this.form.remLen2,4000);" onkeyup="textCounter(this.form.messagetwo,this.form.remLen2,4000);"></textarea>
<br>
<input readonly type=text name=remLen2 size=4 maxlength=4 value="4000"> characters left</font>&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" bgcolor="#FFFFFF">&nbsp;					
</td>
</tr>
<tr>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" bgcolor="#FFFFFF">
<span class="style86"><font color="#EE7F01">>></font>
<font color="#00518D"><a href="add%20item.html">
<font color="#00518D">Save article to personal email account</font></a> </font><font color="#EE7F01">>></font><font color="#EE7F01"></font><font color="#EE7F01"></font></span></td>
</tr>
<tr>
<td width="546" colspan="3" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr>
<td width="546" bgcolor="#FFFFFF"><span class="style68"><font color="#EE7F01">5</font></span><span class="style62"><font color="#EE7F01">.</font></span> <span class="style62">L<span class="style78">ocation:</span></span></td>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF"><select name="menuSubjectsDMA" onChange="changeFilesDMA()">
  <option value="none">Select a Continent
  <option value="">Africa
  <option value="">Asia
  <option value="">Europe
  <option value="">North America
  <option value="">Oceania
  <option value="">South America
  </select>

<!-- this menu holds the files to go-->

<select name="menuFilesDMA" style="width:300">

<option value="none"> Choose Country
</select>&nbsp;</td>
</tr>
<tr>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF">&nbsp;			
</td>
</tr>
<tr>
<td width="546" bgcolor="#FFFFFF"><span class="style58">
<font color="#000000">(20 character limit)</font></span></td>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF">
<span class="style58"><font color="#00518D"><em>i.e.</em>where and when did the events you have written about occur? </font></span></td>
</tr>
<tr>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF">&nbsp;			
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><span class="style68"><font color="#EE7F01">6</font></span><span class="style62"><font color="#EE7F01">. </font> P<span class="style78">hotos:</span></span></td>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" bgcolor="#FFFFFF"><label>
<input name="userfile" type="file" id="userfile"> 
</label></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
						
<tr>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF">&nbsp;			
</td>
</tr>
<tr>
<td width="546" height="42" bgcolor="#FFFFFF"><span class="style68">
<font color="#EE7F01">7</font></span><span class="style62"><font color="#EE7F01">. </font>C<span class="style78">atagory:</span></span></td>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="middle" width="546" bgcolor="#FFFFFF"><select name="Catagory" id="Catagory">
                            <option>Magazine</option>
                            <option>News</option>
                            <option>Review</option>
                            <option>List</option>
                          </select></td>
</tr>
<tr>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" bgcolor="#FFFFFF">&nbsp;			
</td>
</tr>
<tr>
<td width="546" height="20" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" height="20" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" height="20" bgcolor="#FFFFFF">
<span class="style18">
<a href="catagories.html"><font color="#00518D">Choose the c</font></a></span><span class="style10"><a href="catagories.html"><font color="#00518D">atagory that best suits your article (if unsure click here)</font></a></span> </td>
</tr>
<tr>
<td width="546" height="19" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" height="19" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" height="19" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr>
<td width="546" height="19" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" height="19" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" height="19" bgcolor="#FFFFFF">&nbsp;		
</td>
</tr>
<tr>
<td width="546" height="20" bgcolor="#FFFFFF"><font color="#EE7F01">
<span class="style68">8.</span> </font>
<span class="style62">S<span class="style78">ubmit:</span></span></td>
<td width="546" height="20" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" height="20" bgcolor="#FFFFFF"><span class="style51">By submitting you agree to the <span class="style17">					<a href="register.html"><font color="#00518D">terms of use</font></a></span> and <span class="style17"><a href="register.html"><font color="#00518D">privacy policy</font></a></span>.</span></td>
</tr>
<tr>
<td width="546" height="20" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" height="20" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" height="20" bgcolor="#FFFFFF">&nbsp;			</td>
</tr>
<tr>
<td width="546" height="20" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" height="20" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" height="20" bgcolor="#FFFFFF"><label>
<INPUT type=submit value=Submit name=submit>
</label></td>
</tr>
<tr>
<td width="546" height="20" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" height="20" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" height="20" bgcolor="#FFFFFF">&nbsp;			</td>
</tr>
<tr>
<td width="546" height="20" bgcolor="#FFFFFF">&nbsp;</td>
<td width="546" height="20" bgcolor="#FFFFFF">&nbsp;</td>
<td align="left" valign="top" width="546" height="20" bgcolor="#FFFFFF">
<span class="style51">Having problems with a submission? Email
<a href="mailto:info@mysite.com">
info@mysite.com</a>.</span></td>
</tr>
<tr>
<td width="14" height="28" background="line_left_corner.png" bgcolor="#FFFFFF">&nbsp;</td>
<td height="28" width="546" background="line_base.png" colspan="3" bgcolor="#FFFFFF">&nbsp;</td>
<td width="14" height="28" background="line_right_corner.png" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
</table>
</td>
<td width="14">&nbsp;</td>
</tr>
<tr>

<td width="574">&nbsp;</td>
<td width="14">&nbsp;</td>
</tr>
</table></form>

Any help is much appriciated,

Colin


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by cs1h on Tue Sep 04, 2007 8:37 am, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Does mysql_insert_id() show anything? What are the field types in your database table? (table structure would help here)

Have you tried var_dump()ing your variables before the insert statement?

Make use of the mysql_error() function.

PS: Use php and code tags to post your code. Makes it much easier for us to read.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
cs1h
Forum Newbie
Posts: 13
Joined: Fri Aug 31, 2007 11:39 am

reply

Post by cs1h »

hi,

thanks for the quick responce, the mysql table is as follows.

Field Type Null Default
id int(11) Yes NULL
continent varchar(100) Yes
country varchar(100) Yes
type varchar(100) Yes
Email varchar(255) Yes
Title varchar(255) Yes
Abstract text Yes
Article text Yes
data longblob Yes
filename char(150) Yes
filesize char(150) Yes
filetype char(150) Yes

I will try your surgestions,

thanks
Post Reply