简体   繁体   中英

date and phone number format in php

i am trying to get data from user and store into database using php. when i add date & phone number , it store any 1st number of date what you entered & any random number in phone number.

$fname = $_GET['fname'];
$lname = $_GET['lname'];
$mname = $_GET['mname'];
$dob = $_GET['dob'];
$pnumber = $_GET['pnumber'];
$occupation = $_GET['occupation'];
$joindate = $_GET['join date'];
$ffname = $_GET['ffname'];
$flname = $_GET['flname'];
$peraddress = $_GET['peraddress'];
$fpnumber = $_GET['fpnumber'];
$mpnumber = $_GET['mpnumber'];
$roomnumber = $_GET['roomnumber'];
$deposite = $_GET['deposite'];
//$password = $_GET['password'];
//$sha1password = sha1($password);

//create connection
$connection = mysqli_connect('localhost', 'root', 'root', 'Hostel');

//check connection
if ($connection->connect_error) {
die('Connection error (' . $connection->connect_errno . ') ' .$connection->connect_error);
}

echo 'Cool!' .$connection->host_info . "\n";

 $sqlin = "INSERT INTO Student (First_Name, Last_Name, Middle_Name,   Date_of_Birth, Phone_Number, Occupation, Join_Date, Father_First_Name, Father_Last_Name, Permenent_Address, Father_Phone_Number, Mother_Phone_Number, Room_Number, Deposite)
 VALUES ('$fname', '$lname', '$mname', '$dob', '$pnumber', '$occupation', '$joindate', '$ffname', '$flname', '$peraddress', '$fpnumber', '$mpnumber', '$roomnumber', '$deposite')";

 if ($connection->query($sqlin) === TRUE) {
 echo"Thank you! Your info has been entered into database";
 }else{
    echo"Error: " . $sqlin . "<br>" . $connection->error;
 }

 $connection->close();

 ?>

i already set date type is date in html and for phone number is text. how i can correct date with any format with calender option and phone number ?

Since you are posting your data from the form using _GET, that might have caused the problem with date when saving in database. Change the form post method to 'POST' and read posted values using $_POST

I think if you mentioned the type of colomn you created as date. It has to be sent only in the format 'YYYY-MM-DD HH:MM:SS' and I don't think it support other format you entered to store and you ca store the telephone number even in text format. you can use strotime() to convert the entered date into that format $dob1 = date('Ym-d', strtotime($dob)); so that you could store in database without any errors and you should specify the entire date if you declare the variable to be stored as date in database

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM