944,142 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3645
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Nov 9th, 2009
0
Re: Newbie question: PHP form not writing to MySQL database
Ahghh!
<sorry>
I don't meant you but the poster of thread!
It is great for beginners. I quoted a wrong person,

</Sorry>
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007
Nov 9th, 2009
0
Re: Newbie question: PHP form not writing to MySQL database
aahhh its fine... i was starting to get worried that after spending 2 months coding, some1 s suggesting me to read that absolute beginners stuff..

Click to Expand / Collapse  Quote originally posted by evstevemd ...
Ahghh!
<sorry>
I don't meant you but the poster of thread!
It is great for beginners. I quoted a wrong person,

</Sorry>
Last edited by venkat0904; Nov 9th, 2009 at 6:30 am.
Reputation Points: 13
Solved Threads: 21
Junior Poster
venkat0904 is offline Offline
186 posts
since Oct 2009
Nov 9th, 2009
0
Re: Newbie question: PHP form not writing to MySQL database
Still not working for me. I don't know the code, so I'm not sure what to look for, but I made sure that all the variable names and everything were correct.

Here's the code that I'm using:

PHP Syntax (Toggle Plain Text)
  1. <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD="post">
  2. <P>Type your word here:<BR>
  3. <TEXTAREA NAME="word" ROWS="2" COLS="40" WRAP="HARD"></TEXTAREA><BR>
  4. <INPUT TYPE="SUBMIT" NAME="submitWord" VALUE="SUBMIT">
  5. </FORM>
  6.  
  7. <?php
  8. $word = $_POST['submitWord'];
  9. if ("SUBMIT" == $submitWord) {
  10. $sql = "INSERT INTO Dictionary SET " .
  11. "Word='$word', " .
  12. "AddDate=CURDATE()";
  13. if (mysql_query($sql)) {
  14. echo("<P>Your word has been added.</P>");
  15. } else {
  16. echo("<P>Error adding submitted word: " .
  17. mysql_error() . "</P>");
  18. }
  19. }
  20. ?>

If this helps, when I use PuTTY to check the contents of the database, I see this:
PHP Syntax (Toggle Plain Text)
  1. mysql> select * from Dictionary;
  2. +----+----------+------+----------------------------------------------+------------+
  3. | ID | Word | PoS | Definition | AddDate |
  4. +----+----------+------+----------------------------------------------+------------+
  5. | 2 | abstract | adj | NULL | 0000-00-00 |
  6. | 3 | abstract | adj | NULL | 0000-00-00 |
  7. | 4 | abstract | adj | not concrete; hard to understand; intangible | 2009-11-08 |
  8. +----+----------+------+----------------------------------------------+------------+
  9. 3 rows in set (0.01 sec)

Click to Expand / Collapse  Quote originally posted by evstevemd ...
Are you sure you don need this dose?
Thanks! I'll look at that now.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Sucesso is offline Offline
9 posts
since Aug 2008
Nov 10th, 2009
0
Re: Newbie question: PHP form not writing to MySQL database
why dont u use the code suggested above... ur sql query syntax itself is wrong.. how do you expect to get a database entry with that...
general syntax for insert statement is-
INSERT INTO [tablename] (col1,col2 ...) VALUES (val1, val2...);

Also ur table structure shows other fields also besides word and date... are u sure when u are inserting a new row, these values are allowed to be null?

Click to Expand / Collapse  Quote originally posted by Sucesso ...
Still not working for me. I don't know the code, so I'm not sure what to look for, but I made sure that all the variable names and everything were correct.

Here's the code that I'm using:

PHP Syntax (Toggle Plain Text)
  1. <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD="post">
  2. <P>Type your word here:<BR>
  3. <TEXTAREA NAME="word" ROWS="2" COLS="40" WRAP="HARD"></TEXTAREA><BR>
  4. <INPUT TYPE="SUBMIT" NAME="submitWord" VALUE="SUBMIT">
  5. </FORM>
  6.  
  7. <?php
  8. $word = $_POST['submitWord'];
  9. if ("SUBMIT" == $submitWord) {
  10. $sql = "INSERT INTO Dictionary SET " .
  11. "Word='$word', " .
  12. "AddDate=CURDATE()";
  13. if (mysql_query($sql)) {
  14. echo("<P>Your word has been added.</P>");
  15. } else {
  16. echo("<P>Error adding submitted word: " .
  17. mysql_error() . "</P>");
  18. }
  19. }
  20. ?>

If this helps, when I use PuTTY to check the contents of the database, I see this:
PHP Syntax (Toggle Plain Text)
  1. mysql> select * from Dictionary;
  2. +----+----------+------+----------------------------------------------+------------+
  3. | ID | Word | PoS | Definition | AddDate |
  4. +----+----------+------+----------------------------------------------+------------+
  5. | 2 | abstract | adj | NULL | 0000-00-00 |
  6. | 3 | abstract | adj | NULL | 0000-00-00 |
  7. | 4 | abstract | adj | not concrete; hard to understand; intangible | 2009-11-08 |
  8. +----+----------+------+----------------------------------------------+------------+
  9. 3 rows in set (0.01 sec)

Thanks! I'll look at that now.
Reputation Points: 13
Solved Threads: 21
Junior Poster
venkat0904 is offline Offline
186 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Multiple Text areas not working.
Next Thread in PHP Forum Timeline: php classes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC