简体   繁体   English

日期和电话号码格式(PHP)

[英]date and phone number format in php

i am trying to get data from user and store into database using php. 我试图从用户获取数据并使用php存储到数据库中。 when i add date & phone number , it store any 1st number of date what you entered & any random number in phone number. 当我添加日期和电话号码时,它会存储您输入的日期的第1个数字以及电话号码中的任何随机数。

$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. 我已经设置日期类型为HTML日期,电话号码为文本。 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. 由于您正在使用_GET从表单发布数据,因此在数据库中保存时可能导致日期问题。 Change the form post method to 'POST' and read posted values using $_POST 将表单发布方法更改为“ POST”,并使用$ _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. 它只能以“ YYYY-MM-DD HH:MM:SS”格式发送,并且我认为它不支持您输入要存储的其他格式,甚至可以以文本格式存储电话号码。 you can use strotime() to convert the entered date into that format $dob1 = date('Ym-d', strtotime($dob)); 您可以使用strotime()将输入的日期转换为该格式$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 这样就可以将其存储在数据库中而没有任何错误,并且如果您声明将变量存储为数据库中的日期,则应指定整个日期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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