PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Iron Speed
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old September 16th, 2002, 09:19 AM
marvc marvc is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 5 marvc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs down Need help with php article and personal project...

I do not know PHP nor do I see myself becoming a full fledge programmer anytime soon, but I am trying to follow along wiith this tutorial on adding blobs to a database:
http://www.devarticles.com/content....cleId=68&page=5
and I'm SOS = stuck on stupid...
I'm trying to create a form that allows users to upload data or files to a table I've created in a database. The table contains the following fields:
id
author
city
state
email
title
copyright
submitdate
category
filename
filedata mediumblob
filetype

Can someone assist me in modifying this so that it allows the user to submit their data or upload a file, store that info into the database and then post it for public viewing in either a link or table format? These would be poems , essays, or short stories.
Any help on this is appreciated.

Reply With Quote
  #2  
Old September 16th, 2002, 06:49 PM
marvc marvc is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 5 marvc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
makin a lil progress...

Man I'm burned out.OK...This is what I've come up with from my readings thus far. Again this is my first attempt at ever creating a database using mysql & php, so be king.
As a reminder I'm trying to allow users to submit files or text to a database to be made available for public viewing.
I've created a submitform that has the fields I want stored.
I've also created a database = dbnubiint and a table for this particular page = nuwoez. I've also created a user = dbnubiint_user.
I take this code and add it to my submitform under <body>
and get parse errors. The exact error is: Parse error: parse error, unexpected T_IF in c:\program files\php home edition 2\www\nuwoez\submitform.php on line 49.
The Code:
PHP Code:
<?php 
// If the user wants to add a file 
if (isset($addfile)):
?>
<!--Form to submit filedata-->
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Enter your work here:<BR>
<TEXTAREA NAME="filedata" ROWS=10 COLS=40WRAP>
</TEXTAREA><BR>
<INPUT TYPE=SUBMIT NAME="submitform" VALUE="SUBMIT">
</FORM>
<!---End of Form-->

<?php 
else:
// Connect to the database server 
$dbcnx = @mysql_connect("localhost""dbnubiint_user""dbusernu"); 
if (!
$dbcnx) { 
echo( 
"<P>Unable to connect to the " "database server at this 
time.</P>" 
); exit(); 
}
// Select the nubiint database 
if (! @mysql_select_db("dbnubiint") ) { 
echo( 
"<P>Unable to locate the Nubiint " "database at this time.</P>" ); 
exit(); 
}
// If a File has been submitted, 
// add it to the database. 
if ("SUBMIT" == $submitform) { 
$sql "INSERT INTO nuwoez SET " 
"Filedata='$Filedata', " "Author='$Author', " .
"City='$City', " .
"State='$State', " .
"Email='$Email', " .
"Title='$Title', " .
"Copyright=DATE()"" .
"
Submitdate=CURDATE" .
"
Category='$Category'" .
"
Filename='$Filename'" .
"
Filetype='$Filetype'" . 
if (mysql_query($sql)) { 
echo("
<P>Your file has been added.</P>"); 
} else { 
echo("
<P>Error adding submitted file" . mysql_error() . 

"
</P>"); 


echo("
<PHere are all the file " . 
"
in our database: </P>"); 
// Request the text of all the files 
$result = mysql_query( 
"
SELECT Filedata FROM nuwoez"); 
if (!$result) { 
echo("
<P>Error performing query" . mysql_error() . "</P>"); 
exit(); 

// Display the text of each file in a paragraph 
while ( $row = mysql_fetch_array($result) ) { echo("
<P>" . $row["Filedata"] . 

"
</P>"); 

// When clicked, this link will load this page 
// with the file submission form displayed. 
echo("
<P><A HREF='$PHP_SELF?addfile=1'>" . 
"
Add a File!</A></P>"); 
endif; 
?>

My submitform contains both a file upload box and a textarea box. Not sure if this has anything to do with anything, just thought I'd post it.
This is modified code from the Jokes database tutorial mysql.com. Again my hands on knowledge is entry level, so please don't assume I know what I'm doing.
I appreciate any assistance I can get from the list.
TIA

* Edit: Please make use of the "php" and "/php" braces when displaying code.

Last edited by FrankieShakes : September 17th, 2002 at 08:57 PM.

Reply With Quote
  #3  
Old September 16th, 2002, 09:36 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
if dont know php, what the hell are you doing, blobing data isnt for begginners!

try reading this article for starters

URL

Reply With Quote
  #4  
Old September 16th, 2002, 09:59 PM
marvc marvc is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 5 marvc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Started out trying to follow the article here:
http://www.devarticles.com/content....cleId=68&page=3

Ended up up on an article located here:
http://www.mysql.com/articles/ddws/23.html

got spun around at about the 5 tutorial and have been dizzy ever since.
I was hoping I could create a simple form, have users upload text or files from this form into a table in a database, and have that info made available for public viewing. It honeslty didn't seem like it would be this hard.
Currently viewing this thread you just posted.
Thanks

Reply With Quote
  #5  
Old September 17th, 2002, 09:02 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Okay,

The first problem I noticed is that when you store the values of "Filename" and "Filetype", you're not actually processing anything to retrieve the actual file information.

I would suggest to check out this page of Mitch's tutorial, which explains how to store the actual file-type and filename values.

Also, I would suggest changing the "CURDATE" to "CURDATE()" when inserting the date.

Hope that helps, let us know...
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #6  
Old September 17th, 2002, 09:34 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
as a genral tip, copy the article line for line, then modify the article database, to what you want, testing for problems as you go.


If your knowledge of php isnt that great, i suggest that you read lots of articles, from devarticles and also head down to your local book store and get some books on php

Reply With Quote
  #7  
Old September 17th, 2002, 10:50 PM
marvc marvc is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 5 marvc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I think I've made some serious progress on this issue as I'm now able to connect to the db, submit the article and see it posted in the table in the db.
Can someone take a look at this page, click on submit writings, click the submit button, and then click the display button. I get an error that states the following:
The query: SELECT * FROM nuwoez WHERE type='" did not return any data.
This comes after trying to have it so that the submitted data shows up under the category that was selected. So if userA submits a poem and selects Poetry from the category list, the poem is stored under the Poetry list and userA can go to poertry, and poetry only, to view that poem. In other words, the submitted data goes to the category that was selected and can only be viewed in that category. Clicking one of the links in the menu to the left either displays that data or a link to that data. The way I have it set now, it displays the data.
Here's the code from my displaycat.php file.
<table width="100%">
<?
require("conn.inc");
?>
<?
$type = $_POST['type'];
$sql = "SELECT * FROM nuwoez WHERE type='$type'";
$result = mysql_query($sql);
$num_results = mysql_num_rows($result) or die ("The query: '$sql' did not return any data");
for ($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_row($result);
$author = mysql_result($result, $i, "author");
$city = mysql_result($result, $i, "city");
$state = mysql_result($result, $i, "state");
$email = mysql_result($result, $i, "email");
$title = mysql_result($result, $i, "title");
$copyright = mysql_result($result, $i, "copyright");
$submitdate = mysql_result($result, $i, "submitdate");
$filename = mysql_result($result, $i, "filename");
$filedata = mysql_result($result, $i, "filedata");
echo "<tr bgcolor=white><td>&nbsp;&nbsp;&nbsp;</td>";
echo "<td>" . $author ."</td>";
echo "<td>".$city . "</td>";
echo "<td>".$state . "</td>";
echo "<td>".$email . "</td>";
echo "<td>".$title . "</td>";
echo "<td>".$copyright . "</td>";
echo "<td>".$submitdate . "</td>";
echo "<td>".$filename . "</td>";
echo "<td>".$filedata . "</td></tr>";
}
?>
</table>

I've tried and can't seem to get this $type variable to act right.
Also can anyone tell me why my upload button doesn't seem to work?
<TEXTAREA NAME="filedata" rows="20" cols="55" WRAP>
</TEXTAREA><BR>
<INPUT TYPE=SUBMIT NAME="Submit" VALUE="Submit">
<input type=reset name="clear" value="Clear">
</center><br>

ANY help on this is appreciated.

Reply With Quote
  #8  
Old September 19th, 2002, 10:17 AM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
I agree with Ben, if you are new to PHP do not start off with blobbing data into MySQL dbs as that's for programmers with intermediate experience with PHP. I would try working with some simple scripts trying to understand how they work before trying to blob data.
__________________




"Only Linux users see the end of crashes."
- Pl4t0

Reply With Quote
  #9  
Old September 19th, 2002, 07:39 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Quote:
I do not know PHP


As ive said before, start with the basics and work your way up. You are obviously a begginner, and your tying to implement a script that that requires an intermediate knowledge of php.

Im not trying to discourage you from trying, but i think from a professional programmers view that you should start learning the little things.

Try what i said before, try the article without modifying it, you will get a better understanding.

Quote:
I think I've made some serious progress on this issue as I'm now able to connect to the db, submit the article and see it posted in the table in the db.


If your only just found out how to connect to a database then i suggest that you read our mysql and php begginners article, which shows you the basics of mysql, then move on to blobing the file, i would suggest to you for the moment not to blob the file, but to store it in a dir.

I hope that you take my advice otherwise your not going to get very far

Regards
Ben Rowe

Reply With Quote
  #10  
Old September 19th, 2002, 08:17 PM
marvc marvc is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 5 marvc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
My problem isn't connecting to the database as I'm familiar with that procedure. The problems comes afterwards and configuring php to do other things. Some articles say _POST and others say different. That's just something I'll have to learn as I go.

Though not a quitter in anything I choose to do, I do admit when I'm out of my league. I appreciate the advice and gracefully head to the back of the room where I sit with the online tuts, and my manual. I won't discontinue my efforts to resolve this issue I'll just ensure I have my *ish together before I post.

Thanks again. Your responses are appreciated.

Reply With Quote
  #11  
Old September 19th, 2002, 09:43 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
i would suggest coping the article, line for line, then slowly modify the code to your needs

Reply With Quote
  #12  
Old September 20th, 2002, 03:57 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Quote:
Originally posted by marvc
Some articles say _POST and others say different. That's just something I'll have to learn as I go.

Thanks again. Your responses are appreciated.


Marv,

The reason you see $_POST[] in a lot of the newer articles/tutorials is because of PHP's implementation of superglobals. Rather than referring to a variable the way you may be used to (ie: $userName) when calling another script, you now have to use PHP superglobal arrays (ie: $_POST['userName'] or $_GET['userName']).

The difference between $_POST and $_GET depends on the "method" section of your "form" tag... If you use:

<form method="post" action="callingScript.php">

Then you would use $_POST...

If you prefer to use the superglobal arrays ($_POST, etc...), you'll need to turn "register_globals" to "off" in your PHP.INI file.

For more information, check out the PHP manual.

Hope that helps a bit...

Reply With Quote
  #13  
Old September 20th, 2002, 08:02 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
also another tip is when you place a superglobal inside a string you need to encase it in curly brackets

eg

$string = "my name is " . $_GET['name'];

would become

$string = "my name is {$_GET['name']}";

this is slightly faster, and most people still dont know about this

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Need help with php article and personal project...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.