Current location: Hot Scripts Forums » Programming Languages » PHP » data into database


data into database

Reply
  #1 (permalink)  
Old 10-25-11, 05:36 PM
williamh26 williamh26 is offline
Wannabe Coder
 
Join Date: Jul 2010
Posts: 132
Thanks: 2
Thanked 0 Times in 0 Posts
data into database

Hi guys i have this form to insert data into database
PHP Code:

<form name="form1" method="post" action="askhomework.inc.php">
                <ol>

                  <li><label for="firstname">First Name</label>
                  <input type="text" name="firstname" id="firstname"></li>

                  <li><label for="lastname">Last Name</label>
                  <input type="text" name="lastname" id="lastname"></li>

                  <li><label for="email">Email</label>
                  <input type="text" name="email" id="email"></li>

                  
                  <li><label for="subjects">Subject:</label>&nbsp;
                  <?php

                    
include("mylibrary/login.php");

                      
$query="SELECT sub_name,freetut_id FROM freetutorials";
                      
$result mysql_query ($query);
                       echo 
"<select name='subject' value=''>Subjects</option>";
                       
// printing the list box select command

                      
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
                      
echo "<option value=$nt[freetut_id]>$nt[sub_name]</option>";
                       
/* Option values are added by looping through the array */
                       
}
                      echo 
"</select>";// Closing of list box
            
?> </li>

                  <li><label for="select">Due-on:</label>&nbsp;
                  
                   <tr>
                         <td><strong>Day</strong><select name="day"> &nbsp;

                          <?php

                                
for($i=1$i<=31$i++) {
                                    echo 
"<option>" $i"</option>";
                                      }
                          
?> </select></td>&nbsp;
                         <td><strong>Month</strong><select name="month">
                          <?php
                                
for($i=1$i<=12$i++) {
                                    echo 
"<option>" $i"</option>";
                                      }
                          
?> </select></td>&nbsp;
                         <td><strong>Year</strong><select name="year">
                          <?php
                                
for($i=2011$i<=2020$i++) {
                                    echo 
"<option>" $i"</option>";
                                      }
                          
?> </select></td>&nbsp;
                         <td><strong>Hour</strong><select name="hour">
                          <?php
                                
for($i=0$i<=23$i++) {
                                    echo 
"<option>" sprintf("%02d",$i) . "</option>";
                                      }
                          
?> </select></td>&nbsp;
                         <td><strong>Min</strong><select name="minute">
                          <?php
                                
for($i=0$i<=60$i++) {
                                    echo 
"<option>" sprintf("%02d",$i) . "</option>";
                                      }
                          
?> </select></td>
                   </tr>

                  <br>
                  <li><label for="problems">Problem/s</label>&nbsp;&nbsp;&nbsp;
                  <textarea class="video" type="text" name="problems"></textarea></li><br>

                  <li><input name="submit" type="submit" class="submit" id="submit" value="Submit"></li>
                </ol>
            </form>
The problem is that when insert data in the subject droplist insert only the array number not the actually name. This is my code
PHP Code:

<?php

include("mylibrary/login.php");


$firstname $_POST['firstname'];
$lastname $_POST['lastname'];
$email $_POST['email'];
$year $_POST['year'];
$month $_POST['month'];
$day $_POST['day'];
$subject $_POST['subject'];
$problems $_POST['problems'];

 
$dueon date("Y-m-d"mktime(0,0,0,$month$day$year));

// Insert data into mysql
$query "INSERT INTO homeworkask ( dueon, subject, firstname, lastname, email, problems) " .
            
" VALUES ('$dueon','$subject', '$firstname', '$lastname', '$email', '$problems')";


   
$result mysql_query($query) or die('Unable to add product');
   if (
$result)
      echo 
"<h2>Your Homework has been Submitted. Check your email in about 24 hours.</h2>\n";
   else
      echo 
"<h2>Problem Submitting your Homework.</h2>\n";
      echo
"<a href='index.php'>Back to main page</a>";
?>
This is what happen in the database
homeworkask_id firstname lastname email subject dueon problems
59 sdfg fdsg sdfg 1 2011-01-01 fsfdgsd
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Data from Database to Excel via SQL Command and Customize Style of it For VB.NET without Auto tomason Windows .NET Programming 2 08-10-11 03:11 AM


All times are GMT -5. The time now is 08:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.