Page 1 of 2
form that sends data to mysql?
Posted: Tue Oct 19, 2004 12:50 pm
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>';
Posted: Tue Oct 19, 2004 1:58 pm
by feyd
[devnet]+form +valid*[/devnet] and [mysql_man]INSERT Syntax[/mysql_man]
Posted: Tue Oct 19, 2004 2:01 pm
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..
Posted: Tue Oct 19, 2004 2:03 pm
by feyd
it finds 630 threads involving those two, right now.
Posted: Tue Oct 19, 2004 2:10 pm
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
Posted: Tue Oct 19, 2004 2:51 pm
by Diod
Bump (ill delete this post)
Posted: Tue Oct 19, 2004 2:54 pm
by feyd
please do not bump your thread only 40 minutes after your last post.
Posted: Tue Oct 19, 2004 2:54 pm
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)
Posted: Tue Oct 19, 2004 2:55 pm
by Diod
ok ill go to the channel
Posted: Wed Oct 20, 2004 9:28 am
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:
Posted: Wed Oct 20, 2004 9:34 am
by Diod
you corrected what in my code? :/

thx anyway =-)
Posted: Wed Oct 20, 2004 9:34 am
by feyd
use the mysql function: [mysql_man]NOW()[/mysql_man]
Posted: Wed Oct 20, 2004 9:40 am
by Diod
now i get
Code: Select all
Warning: date() ї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()
Posted: Wed Oct 20, 2004 9:41 am
by feyd
you aren't using [mysql_man]NOW()[/mysql_man] you're using [php_man]time()[/php_man].. big difference.
Posted: Wed Oct 20, 2004 9:49 am
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);