我正在为宠物创建一个网站。我希望创建一个页面,宠物主人可以在其中注册和添加他的宠物。我制作了一个表单并放置了 javascript 来添加更多宠物,当点击“添加更多宠物”链接时,它会创建新字段。但我无法将这些信息收集到 php 变量中。链接在这里:http ://animalswecare.in/mypet.php
我有 php 和 mysqli 的工作知识。
我的 php 代码 if ( isset( $_POST['mypet'] ) ) {
$name = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['name'] ) ) );
$email = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['email'] ) ) );
$password = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['password'] ) ) );
$gender = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['sex'] ) ) );
$contact = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['contact'] ) ) );
$country = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['country'] ) ) );
$state = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['state'] ) ) );
$city = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['city'] ) ) );
//$photo = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['picture'] ) ) );
$fname = mysqli_real_escape_string ( $dbc, $_FILES['picture']['name'] );
$ext=$_FILES['picture']['name'];
$targetpath = "images/user/big/";
if($ext !="")
{
$ext = explode(".",$ext);
if($ext[1]=="jpg" || $ext[1]=="gif" || $ext[1]=="jpeg" || $ext[1]=="png" || $ext[1]=="bmp" || $ext[1]=="wbmp" || $ext[1]=="JPEG" || $ext[1]=="JPG" || $ext[1]=="GIF" || $ext[1]=="PNG" || $ext[1]=="BMP")
{
if($_FILES['picture']['size'] <= 2000000)
{
$filename=$targetpath.$id."-" .$fname;
$photo = $id."-" .$fname;
if (file_exists($filename))
{
chmod($filename, 0777);
unlink($filename);
}
if(move_uploaded_file($_FILES['picture']['tmp_name'],$filename))
{
$thpath = "images/user/thumb/";
$file = createThumb1($filename, $thpath, $fl_db,350,280);
}
}
}
}
$query = "INSERT INTO `user` SET `name`= '$name',`email` = '$email' ,`password` = '$password',`gender` = '$gender', `contact` = '$contact', `country` = '$country', `state` = '$state', `city` = '$city', `photo` = '$photo',`date` = now(),`status` = '1' ";
$insComm = mysqli_query($dbc, $query);
$uid = mysqli_insert_id( $dbc );
if($_POST['petname'])
{
$array = $_POST['petname'];
foreach($array as $petname)
{
if(strlen($petname)>0)
{
//$petname = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['petname'] ) ) );
$type = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['type'] ) ) );
$breed = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['breed'] ) ) );
$gender = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['gender'] ) ) );
//$photo = mysqli_real_escape_string ( $dbc, strip_tags ( trim ( $_POST['photo'] ) ) );
$fname = mysqli_real_escape_string ( $dbc, $_FILES['petimage']['name'] );
$ext=$_FILES['petimage']['name'];
$targetpath = "images/pet/big/";
if($ext !="")
{
$ext = explode(".",$ext);
if($ext[1]=="jpg" || $ext[1]=="gif" || $ext[1]=="jpeg" || $ext[1]=="png" || $ext[1]=="bmp" || $ext[1]=="wbmp" || $ext[1]=="JPEG" || $ext[1]=="JPG" || $ext[1]=="GIF" || $ext[1]=="PNG" || $ext[1]=="BMP")
{
if($_FILES['petimage']['size'] <= 2000000)
{
$filename=$targetpath.$id."-" .$fname;
$petphoto = $id."-" .$fname;
if (file_exists($filename))
{
chmod($filename, 0777);
unlink($filename);
}
if(move_uploaded_file($_FILES['petimage']['tmp_name'],$filename))
{
$thpath = "images/pet/thumb/";
$file = createThumb1($filename, $thpath, $fl_db,350,280);
}
}
}
}
$query = "INSERT INTO `mypet` SET `uid`= '$uid',`petname`= '$petname',`type` = '$type',`breed` = '$breed',`gender` = '$gender', `photo` = '$petphoto',`date` = now(),`status` = '1' ";
$insComm = mysqli_query($dbc, $query);
$msg = "Your information is successfully Added!!";