form that sends data to mysql?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
Diod
Forum Commoner
Posts: 52
Joined: Tue Oct 19, 2004 9:07 am

form that sends data to mysql?

Post by Diod »

hey, im trying to make a form that sends the users input to the mysql server..

ive got the following(i also need something that can check if everything is filled and if not, abort the submit and let the user know

Code: Select all

echo '<form method="post" enctype="text/plain" action=' . '><p>Your Username: <input name=author maxlength="30"> <p>Your Email Adress: <input name=email>
<p>Title: <input name=title maxlength="40"> <p> <p>Text: <br> <textarea name=why rows=5 cols=60></textarea> <p> <input type=SUBMIT value=Submit
name="SUBMIT"> <input type=RESET value="Clear All" name="RESET"></form>';
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[devnet]+form +valid*[/devnet] and [mysql_man]INSERT Syntax[/mysql_man]
User avatar
Diod
Forum Commoner
Posts: 52
Joined: Tue Oct 19, 2004 9:07 am

Post by Diod »

well... i know i gotta use $_POST['text'] and stuff.. but i just dont know when to activate it or something.. and for the form + valid thing i dont understand, it searches for a post with +form valid in it, but it doesnt find one..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it finds 630 threads involving those two, right now.
User avatar
Diod
Forum Commoner
Posts: 52
Joined: Tue Oct 19, 2004 9:07 am

Post by Diod »

well
i dont really need to validate them.. i only need to check if they are empty :/
but i dont really have any experience with forms

still cant get the form to work
User avatar
Diod
Forum Commoner
Posts: 52
Joined: Tue Oct 19, 2004 9:07 am

Post by Diod »

Bump (ill delete this post)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

please do not bump your thread only 40 minutes after your last post.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Diod wrote:Bump (ill delete this post)
its only been 41 minutes. Be patient for replies. If you require immediate assistance visit #php on freenode (IRC)
User avatar
Diod
Forum Commoner
Posts: 52
Joined: Tue Oct 19, 2004 9:07 am

Post by Diod »

ok ill go to the channel
User avatar
Diod
Forum Commoner
Posts: 52
Joined: Tue Oct 19, 2004 9:07 am

Post by Diod »

need some help with my form.. (got it to work)


i got the form to work, but it doesnt insert the correct date and time(both current)

i want the date to be inserted into a TIMESTAMP row
i want the time to be inserted into a TIME row

i got the following code

Code: Select all

printf('<div align="center">');
echo "Add a news post.";
echo '<form method="post">';
echo '<input type="hidden" name="submit" value="true">';
echo '<p>Your Username: <input type="text" name="author" maxlength="30"></p>';
echo '<p>Your Email Adress: <input type="text" name="email"></p>';
echo '<p>Title: <input type="text" name="title" maxlength="40"></p>';
echo '<p>Text: <br> <textarea name="text" rows="5" cols="60"></textarea></p>';
echo '<p><input type="submit" value="Submit"><input type="reset" value="Clear All">';
echo '</form>';

if (isset($_POST['submit']))
{ 
  $query = 'INSERT ' . 'INTO news (text, author, email, date, time, title) VALUES(''' . $_POST['text'] .''', ''' . $_POST['author'] .''', ''' . $_POST['email'] . ''', '''. time() . ''', '''. time() . ''', ''' . $_POST['title'] . ''')';
  $result = mysql_query($query,$db);

  if ($result)
  {
    echo '<br>News Added Succesfully<br/>';
}
}
feyd | correct code to post just fine. :roll::roll::roll::roll::roll:
User avatar
Diod
Forum Commoner
Posts: 52
Joined: Tue Oct 19, 2004 9:07 am

Post by Diod »

you corrected what in my code? :/ :) thx anyway =-)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use the mysql function: [mysql_man]NOW()[/mysql_man]
User avatar
Diod
Forum Commoner
Posts: 52
Joined: Tue Oct 19, 2004 9:07 am

Post by Diod »

now i get

Code: Select all

Warning: date() &#1111;function.date]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in c:\AppServ\www\index.php on line 22

Title: ssdgsdg | Author: gs | 838:59:59 Hours
-----------------------
ssdsggd
and i DID use NOW()
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you aren't using [mysql_man]NOW()[/mysql_man] you're using [php_man]time()[/php_man].. big difference.
User avatar
Diod
Forum Commoner
Posts: 52
Joined: Tue Oct 19, 2004 9:07 am

Post by Diod »

nope, im using

Code: Select all

{ 
  $query = 'I-N-SERT INTO news (text, author, email, date, time, title) VALUES(''' . $_POST['text'] .''', ''' . $_POST['author'] .''', ''' . $_POST['email'] . ''', '''. 'NOW()' . ''', '''. time() . ''', ''' . $_POST['title'] . ''')';
  $result = mysql_query($query,$db);
Post Reply