Newbie question: PHP form not writing to MySQL database

Reply

Join Date: Jun 2007
Posts: 1,357
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 127
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso
 
0
  #11
18 Days Ago
Ahghh!
<sorry>
I don't meant you but the poster of thread!
It is great for beginners. I quoted a wrong person,

</Sorry>
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 147
Reputation: venkat0904 is an unknown quantity at this point 
Solved Threads: 14
venkat0904's Avatar
venkat0904 venkat0904 is offline Offline
Junior Poster
 
0
  #12
18 Days Ago
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..

Originally Posted by evstevemd View Post
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; 18 Days Ago at 6:30 am.
Gimme reputation points if u find my post helpful.
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 4
Reputation: Sucesso is an unknown quantity at this point 
Solved Threads: 0
Sucesso Sucesso is offline Offline
Newbie Poster
 
0
  #13
18 Days Ago
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:

  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:
  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)

Originally Posted by evstevemd View Post
Are you sure you don need this dose?
Thanks! I'll look at that now.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 147
Reputation: venkat0904 is an unknown quantity at this point 
Solved Threads: 14
venkat0904's Avatar
venkat0904 venkat0904 is offline Offline
Junior Poster
 
0
  #14
17 Days Ago
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?

Originally Posted by Sucesso View Post
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:

  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:
  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.
Gimme reputation points if u find my post helpful.
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
Reply With Quote Quick reply to this message  
Reply

Tags
beginner, forms, mysql, php

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC