Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Please help with this "simple" task!
Old 06-20-2008, 12:54 PM Please help with this "simple" task!
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 960
Name: Darren
Location: England
Trades: 0
OK, here goes...

I am trying to create a form where someone can enter into a text box - choose from a list of pages in a drop down, hit submit - and then the text is displayed on the relevant page.

The uploads are going to be quotes and need to be displayed on pages i.e
"sport" "general" "movies" etc.

I'm assuming i need a table created in my database called "quotes" and then a column after that with "sport" in there as well...?

I know the code for displaying on the page would be something like
PHP Code:
$result mysql_query("SELECT * FROM quotes WHERE page_number = sport");?> 
but how do i get the information to the database with an upload form?

Hope this makes sense!
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."
rolda hayes is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-20-2008, 02:43 PM Re: Please help with this "simple" task!
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
I'm not sure what you're asking? If you want to put data into a database, it's generally bulk loads or insert commands.

You would probably want a lookup or enumeration table so that instead of having to query for (and store!) string data like in your query, sport might map to 1, movies 2, etc. Then your table is smaller, ie it stores less data, and querying it is faster because there isn't so much disc IO. Plus, it's faster and more efficient to match integer values than strings.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-20-2008, 02:50 PM Re: Please help with this "simple" task!
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 960
Name: Darren
Location: England
Trades: 0
Woa!!! I think I understand that..!

When I originally asked about how best to do this i was told to do it your way sport=1 movies=2 etc but I thought that actually using the names would make it easier - guess not!

I'll try and explain myself a bit better...

I'm going to be building a site that diplays a list of quotes to do with particular subjects i.e. "sport" as one page "movies" as another.

Originally, I was going to use a text file for each list, and then get the client to FTP each text file so they would display in the right place on each page.

But now I thought it would be better if they could have an admin page, type the new quote into a text box, choose from a dropdown which page list the quote should appear on and then hit submit.

I need this to be foolproof for me though as I really am a Noob at mysql!!
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."
rolda hayes is offline
Reply With Quote
View Public Profile
 
Old 06-20-2008, 03:19 PM Re: Please help with this "simple" task!
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
You could do text files and have an admin page. I have no idea how to make that happen in PHP - can PHP even access the file system? To, say, enumerate text files in a directory, server side, and build a response from them? A database will be drastically faster, tho, because of caching. A DB will also let you do things like query by author, instead of by movies vs music.

Whether you store the category or page directly as text or as integers with lookup values is a bit of a side issues. You can make a working system either way, and it will take a lot of concurrent users and or a lot of data before you'll feel pain from this.

So, basically, you would want to make some tables to hold your data, then write a bunch of procs in your MySQL database to interface with the data. One probably takes the page name, quote, and author as input parameters, then, internally, fires off an insert. Another might fetch all the quotes for sport. Finally, your PHP code will call the appropriate procedures and render the data they return to HTML.

http://dev.mysql.com/doc/refman/5.0/...rocedures.html
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-20-2008, 03:25 PM Re: Please help with this "simple" task!
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 960
Name: Darren
Location: England
Trades: 0
Is there any way to write to a .txt file through an HTML form?
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."
rolda hayes is offline
Reply With Quote
View Public Profile
 
Old 06-20-2008, 03:33 PM Re: Please help with this "simple" task!
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
In .NET, sure! It's easy as pie.

Code:
void Page_Load(object sender, EventArgs e) {
   string text = Form["quote"];
   StreamWriter w = new StreamWriter("filename.txt");
   w.Write(text);
   w.Dispose();
}
I don't know what the PHP equivalent might be, if there is one?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by Learning Newbie; 06-20-2008 at 03:35 PM..
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-21-2008, 08:38 AM Re: Please help with this "simple" task!
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 960
Name: Darren
Location: England
Trades: 0
Ok, I've changed this a bit..

Im now going to have an upload page for each section....

i've created a table like this

CREATE TABLE `sport` (
`quote` VARCHAR( 50 ) NOT NULL
);

and my form is here

PHP Code:
<?php 

$hostname 
"localhost"
$db_user "***"
$db_password "***"
$database "***"
$db_table "sport"


$db mysql_connect($hostname$db_user$db_password); 
mysql_select_db($database,$db); 
?> 
<html> 
<head> 
<title>Sport</title> 
</head> 
<body> 

<?php 
if (isset($_REQUEST['Submit'])) { 


$sql "INSERT INTO $db_table(sport) values ('".mysql_real_escape_string(stripslashes($_REQUEST['quote']))."')";
if(
$result mysql_query($sql ,$db)) { 
echo 
'<h1>Thank you</h1>Your information has been entered into our database<br><br><img src="http://www.webmaster-talk.com/images/headers/default_logo.jpg"'
} else { 
echo 
"ERROR: ".mysql_error(); 

} else { 
?> 
<h1>Sport</h1>
<hr> 
<form method="post" action="">
 quote
<br> 
<textarea name="sport_quote" cols="60" rows="5" id="sport_quote"></textarea> 
<br>
<br>
<br>
<br> 
<input type="submit" name="Submit" value="Submit"> 
</form> 
<?php 

?> 
</body> 
</html>
but it returns:

ERROR: Unknown column 'sport' in 'field list'

??
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."

Last edited by rolda hayes; 06-21-2008 at 08:42 AM..
rolda hayes is offline
Reply With Quote
View Public Profile
 
Old 06-23-2008, 03:03 PM Re: Please help with this "simple" task!
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
It's very hard to tell because of the antique coding style (hint, dynamic SQL must die!), but it appears you're trying to add data to a column named sport in a table named sport. Using a stored procedure would have prevented this from the start.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-23-2008, 05:42 PM Re: Please help with this "simple" task!
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 960
Name: Darren
Location: England
Trades: 0
Thanks for the reply John,

I've been playing around with it today and came up with a solution that works well.

Just one last question to finish this for me...

I'm using this code to display the results.

PHP Code:
<?php  
$database
="*****";  
mysql_connect ("localhost""*****""*****");  
@
mysql_select_db($database) or die( "Unable to select database");  
$result mysql_query"SELECT user_name,user_email FROM sport" )  
or die(
"SELECT Error: ".mysql_error());  
$num_rows mysql_num_rows($result);    
print 
"<table width=700  border=0 cellpadding=5>\n";
$color1 '#FFFFFFF';
$color2 '#FFFF00';
while (
$get_info mysql_fetch_row($result)){  
print 
"<tr>\n";  
print 
"\t<td><font face=arial size=3 color=$color1/>{$get_info[0]}</font><br />";
print  
"<font face=arial size=2 color=$color2/>{$get_info[1]}</font></td>\n";  
print 
"</tr>\n";  
}  
print 
"</table>\n";  
?>
It prints the quote on 1 line, then the source of the quote on the next in a different color.

My question is - how can i get an image for a bullet point for each quote?

Where ever i put the <img> tag it messes everything up!
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."
rolda hayes is offline
Reply With Quote
View Public Profile
 
Old 06-24-2008, 04:09 PM Re: Please help with this "simple" task!
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Use an unordered list, and then CSS to replace the bullet points with an image?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-25-2008, 05:38 AM Re: Please help with this "simple" task!
rolda hayes's Avatar
Wannabe Adventurer...

Posts: 960
Name: Darren
Location: England
Trades: 0
I used this in the end

PHP Code:
print "\t<td><img src=\"images/more.gif\"><font face=arial img src=images/more.gif size=3 color=$color1/>{$get_info[0]}</font><br />"
Solved it all now! yay!

Cheers for the advise John
__________________
I Just a test to see what happens...
Please login or register to view this content. Registration is FREE

"Let us be thankful for the fools. But for them the rest of us could not succeed..."
rolda hayes is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Please help with this "simple" task!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.46944 seconds with 12 queries