Easy input into tables

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
phpnewbie1985
Forum Commoner
Posts: 33
Joined: Thu Jan 08, 2004 6:15 am

Easy input into tables

Post by phpnewbie1985 »

Hi, as you can probably tell my the name im new to PHP so be gentle! :S I want to have a text file on server which i can update from time to time and then a page called "table.php" will load each row in the text file into a new row in a table.. is this possible? if so could somebody please explain how i could do this?

Many thanks
Chris
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

Of course this is all possible. But would you not like to use a database instead. You can update it very easily. Have a look around for a few tutorials and don't hesitate: ask here for directions.

Depends how newbie you arethisis quite good.


Dr Evil
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

flat files are very useful in amny circumstances

you can find alot of informationhere
phpnewbie1985
Forum Commoner
Posts: 33
Joined: Thu Jan 08, 2004 6:15 am

HELLP!!

Post by phpnewbie1985 »

I have made a database called matrix_lists with a table called nokia6600 and a record in it. now when i try to retrieve the data from the database it says Connected Successfully, Could not select database... I got the code striaght from php.net and im just confused now!!!

HELP!

Code: Select all

<?php
/* Connecting, selecting database */
$link = mysql_connect("localhost", "username", "password")
   or die("Could not connect : " . mysql_error());
echo "Connected successfully";
mysql_select_db("matrix_lists") or die("Could not select database");

/* Performing SQL query */
$query = "SELECT * FROM nokia6600";
$result = mysql_query($query) or die("Query failed : " . mysql_error());

/* Printing results in HTML */
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "\t<tr>\n";
   foreach ($line as $name) {
       echo "\t\t<td>$name</td>\n";
   }
   echo "\t</tr>\n";
}
echo "</table>\n";

/* Free resultset */
mysql_free_result($result);

/* Closing connection */
mysql_close($link);
?>
Many thanks
Chris
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

there are 2 possible reasons that i can think of

1- the user you are connecting to mysql with does not have permissions for this 'database'

2- your database is spelt wrong (or case is wrong)

coincidentally, your syntax is correct
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

first things first. Your DB is definately called matrix_lists, you haven't spelt it wrong or anything like that have you?

Mark
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try changing:

Code: Select all

mysql_select_db("matrix_lists") or die("Could not select database");
to

Code: Select all

mysql_select_db("matrix_lists") or die("Could not select database".'<p>'.mysql_error().'</p>');
to see if you get a more useful error message.

Mac
phpnewbie1985
Forum Commoner
Posts: 33
Joined: Thu Jan 08, 2004 6:15 am

WOOHOO

Post by phpnewbie1985 »

Brilliant! i had not assigned that user to database... dumb ass i am! :S thanks for all your help! :D its much appreciated! thats why i love this forum such speedy replies!

Chris
Post Reply