Ok so I have a script that I am writing and I have encounted a problem. I can not get the information from a dropbox to submit into mysql data base here is my script.

<form action="work.php" method="post">

<td><input type="text" name="Email" tabindex="1" />

<td><textarea name="Message" 
rows = "7"
cols = "35"
tabindex = "2" /></textarea>


<select name="hour" tabindex="3">
<option value="1">1AM</option>
<option value="2">2AM</option>
<option value="3">3AM</option> 
<option value="4">4AM</option>
<option value="5">5AM</option>
<option value="6">6AM</option>
<option value="7">7AM</option>
<option value="8">8AM</option>
<option value="9">9AM</option>
<option value="10">10AM</option>
<option value="11">11AM</option>
<option value="12">12PM</option>
<option value="13">1PM</option>
<option value="14">2PM</option>
<option value="15">3PM</option>
<option value="16">4PM</option>
<option value="17">5PM</option>
<option value="18">6PM</option>
<option value="19">7PM</option>
<option value="20">8PM</option>
<option value="21">9PM</option>
<option value="22">10PM</option>
<option value="23">11PM</option>
<option value="24">12AM</option>
<input type="submit" name="formSubmit" value="Submit" >

And then here is work.php

$time = $_POST['hour'];
$email1 = $_POST['Email'];
$message1 = $_POST['Message'];

mysql_connect ('localhost', my'user', 'mypassword') or die ('Error: ' .mysql_error());
mysql_select_db ("mydatabase");

$query="INSERT INTO Reminder (Email, Message, Time)
mysql_query($query) or die ('Error submitting');

echo "You Chose: " .$time ;


Recommended Answers

All 10 Replies

Can you post your database table schema, as it could be that MySQL doesn't understand the input you're passing it for the time field.

Based on your code, your time field most likely needs to be a TINYINT, thus accepting values between -128 and 127.

If storing time values however, you may want to consider DATE/TIME, TIME or TIMESTAMP datatypes, depending on whether you require the date too.

The $time might be undefined if the user does not chose any value. Make a default value (or set the selected attribute) or warn the user that the time has not been selected.

if(isset($_POST['hour']) and $_POST['hour'] > 0 and $_POST['hour'] <= 24) {

    $time = $_POST['hour'];

} else {

    // set default value
    $time = 0;

    // or warn the user
    echo 'Please select time...';

Or inspect the query and test it in phpadmin (and maybe post it here). Put this on line 13:


The $time is ment to be so a user can set what time of day they would like a reminder email. I just can not get the $time to show up on my database.

Table is
FROM Reminder
LIMIT 0 , 30

Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
memccool_mail.Reminder.Email .email. ttttt 1 15 5 0 4.0000 NULL ENUM('','.email.','.gg.','ema','email','frger','gf...
memccool_mail.Reminder.Message .fdfg. work 2 12 4 0 4.3043 NULL ENUM('','.fdfg.','.work.','box','ere','ffff','grg'...
memccool_mail.Reminder.Time .. 9:56 PM 2 7 19 0 0.7826 NULL ENUM('','..','9:55 AM','9:56 PM') NOT NULL
memccool_mail.Reminder.test NULL NULL 0 0 0 23 0.0 0.0 CHAR(0)


I did the die($query); and this is what it returns.

INSERT INTO Reminder (Email, Message, Time) VALUES ('email','work','')

INSERT INTO Reminder (Email, Message, Time) VALUES ('email@email.com','this is customer message','')

You probably haven't selected any value for hour and that is why the $_POST['hour'] and $time are empty strings. You must decide what to do in such situations: either supply a default value or warn the user that he forgot to select the time.

Please disregard my previous post since it was wrong. I tested your code now and the code seems to be OK. I get this if I fill in the form and do not select any time value:

INSERT INTO Reminder (Email, Message, Time) VALUES ('myemail@doodle.com','Test message','1')

In my browser the first option is automatically selected and also put into query correctly.

What browser and OS do you use? I have tested your code in Firefox and Chrome on Linux and IE8 on Windows and works OK.

Maybe (but just maybe) you have a problem since your HTML code has errors. The <table> tag has no matching </table> tag, the last <td> tag has no matching </td> tag, the last <tr> tag has no matching </tr> tag and all this shoukd be properly nested withing <form> tags. The browser might have problems rendering the select element. Just a guess.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.