Solved

how to insert date from my registration page into sql database

Posted on 2009-05-19
4
301 Views
Last Modified: 2012-05-07
i have registration form and i would like to insert system date into mysql database.

please help!!!
my database looks like this :---
 
 
<?php
 
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
// Create database
if (mysql_query("CREATE DATABASE reg",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }
// Create table
mysql_select_db("reg", $con);
$sql = "CREATE TABLE details
(
 
 
   ID INT NOT NULL AUTO_INCREMENT,
   email VARCHAR(35) NOT NULL,
   name VARCHAR(35) NOT NULL,
   department VARCHAR(35) NOT NULL,
   phone VARCHAR(35) NOT NULL,
   altphone VARCHAR(35) NOT NULL,
   vista VARCHAR(35) NOT NULL,
  wimba VARCHAR(35) NOT NULL,
   date1 datetime default NULL,   
   PRIMARY KEY (ID)
 
   
   
 
 
 
 
 
)";
// Execute query
mysql_query($sql,$con);
mysql_close($con);
 
?>
 
 
 
form code :--
 
 
<form name="registration" method="post" action="registration.php5">  
      <table align="center" class="style1">
          <tr>
              <td class="style2">
                  Email</td>
              <td class="style2">
                  :</td>
              <td>
                  <input id="Text1" type="text" name="email" /></td>
          </tr>
          <tr>
              <td class="style2">
                  Name</td>
              <td class="style2">
                  :</td>
              <td>
                  <input id="Text2" type="text" name="name" /></td>
          </tr>
          <tr>
              <td class="style2">
                  Department</td>
              <td class="style2">
                  :</td>
              <td>
                  <input id="Text3" type="text" name="department" /></td>
          </tr>
          <tr>
              <td class="style2">
                  Office Phone</td>
              <td class="style2">
                  :</td>
              <td>
                  <input id="Text4" type="text" name="phone"/></td>
          </tr>
          <tr>
              <td class="style2">
                  Alternate Phone</td>
              <td class="style2">
                  :</td>
              <td>
                  <input id="Text5" type="text" name="altphone"/></td>
          </tr>
          <tr>
              <td class="style2">
                  &nbsp;</td>
              <td class="style2">
                  &nbsp;</td>
              <td>
                  &nbsp;</td>
          </tr>
          <tr>
              <td class="style2">
                  &nbsp;</td>
              <td class="style2">
                  &nbsp;</td>
              <td>
                  <input id="submit" type="submit" value="Submit" /></td>
          </tr>
          
      </table>
 
 
php code :--
 
<?PHP
 
//Database Information
 
$dbhost = "localhost";
$dbname = "reg";
$dbuser = "root";
$dbpass = "";
 
//Connect to database
 
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
                     
    
$email = $_POST['email'];
$name = $_POST['name'];    
$department = $_POST['department'];
$phone = $_POST['phone'];
$altphone = $_POST['altphone'];
$vista= $_POST['vista'] ;
$wimba= $_POST['wimba'] ; 
 
   $date1= $_POST['date'];                   
 
          
              
   
 
 
$query = "INSERT INTO details (email,name,department,phone,altphone,vista,wimba,date)
VALUES('$email','$name','$department','$phone','$altphone','$vista','$wimba','$DATE: Auto CURDATE()', CURDATE())";
 
                       
 
 
mysql_query($query) or die(mysql_error());
mysql_close();
          header("location:login_success.php5"); 
//echo "You have successfully Registered";
?>
   
 
 
there is error .....
 
i need to populate database columns ,along with date .

Open in new window

0
Comment
Question by:siddharthkool
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 24424460
$query = "INSERT INTO details (email,name,department,phone,altphone,vista,wimba,date)
VALUES('$email','$name','$department','$phone','$altphone','$vista','$wimba',NOW() )";
 
0
 

Author Comment

by:siddharthkool
ID: 24424928
thanks a lot !!!!!
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24425007
Beware of using the column name, "date" since "date" is a reserved word in MySQL.  Try something different, or remember to put the reserved word in backticks on every use.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 25399256
@siddharthkool:Thanks for the points, but you might want to share the points on this Q with yodercm.  The SQL expression NOW() is an integral part of the answer.  You can use the "request attention" button and ask a moderator how to change a grade.  Best regards, ~Ray
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question