RE: [PHP-DB] PHP Beginners Help
| From: | Bastien Koert | Date: | Thu, 03 Jan 2008 03:10:16 +0000 |
| Subject: | RE: [PHP-DB] PHP Beginners Help | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-44470@lists.php.net to get a copy of this message | ||
Hi ben,
You are creating the same table each time you run the code which would throw an error the second
time you run the code since the table is already there.
You have two choices here:
1. remove the table creation script and the call to create it since the table only needs to be
created once.
2. handle the errors that can happen on running a query. ex.
$mysql_query_one = mysql_query("SELECT * FROM
comments") or
die(mysql_error());
bastien> Date: Thu, 3 Jan 2008 02:57:00 +0000> From: bastones@googlemail.com> To:
bastien> php-db@lists.php.net> Subject: [PHP-DB] PHP Beginners Help> > Hello, my name is Ben Stones.
bastien> I am quite a beginner to PHP, and as a new> years resolution I am going to learn PHP
bastien> (finally!)> > Cut to the chase I have created a basic looping script that would display>
bastien> anything submitted in a form, on seperate lines; here is the PHP code:> > $con =
bastien> mysql_connect("localhost","ben_test","------removed-----") or>
bastien> die("con");> $db = mysql_select_db("ben_test") or die("db");>
bastien> mysql_query("CREATE TABLE comments (messages
bastien> varchar(255))");> $comments = $_POST['comment'];> $sql1 =
bastien> mysql_query("INSERT INTO comments
bastien> (messages) VALUES> ($comments)");> $mysql_query_one =
bastien> mysql_query("SELECT * FROM comments");>
bastien> while($rows=mysql_fetch_array($mysql_query_one)) {> echo $rows['messages'] . "[br
bastien> /]";> }> > Everything went swell for the first half, and after I truncated the
bastien> test> messages (or everything in the column, if you like), I tried doing one more> test run
bastien> and upon clicking 'Submit', nothing would display except the> messages I added via
bastien> phpMyAdmin.> > Hope someone could help me.> > PS: The password has been edited out of
bastien> the preceding code as well as the> HTML code purposely for the mailing list.
_________________________________________________________________
Introducing the City @ Live! Take a tour!
http://getyourliveid.ca/?icid=LIVEIDENCA006