<!DOCTYPE html>
<html lan="fa">
<?php
try{
$dns="mysql:host=localhost;dbname=site;charset=utf 8;";
$coect=new PDO($dns,'root','');
}
catch(PDOException $error){
echo 'coection error';
}
include 'function.php';
/* read db*/
$result=$coect->query("SELECT * FROM `signup`");
?>
<head>
<meta charset="utf-8">
<title>php</title>
<!--STYLE-->
<link rel="stylesheet/less" type="text/css" href="template/style/style.less">
<script type="text/javascript" src="template/javascript/less.min.js"></script>
<!--METATAG-->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="Content-Language" content="Fa">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="DC.Subject" lang="fa-ir" content="">
<meta name="robots" content="index,follow">
<meta name="copyright" content="">
<!--END-->
</head>
<body>
<main>
<form class="right" action="<?php htmlspecialchars($_SERVER["PHP_SELF"]) ?>" method="post">
<table class="table1">
<tr>
<td>نام</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>نام خانوادگي</td>
<td><input type="text" name="family"></td>
</tr>
<tr>
<td>ايميل</td>
<td><input type="text" name="email" class="email"></td>
</tr>
<tr>
<td>جنسيت</td>
<td><select name="sex"><option>مرد</option><option>زن</option></select></td>
</tr>
<tr>
<td>نام کاربري</td>
<td><input type="text" name="useame" class="useame"></td>
</tr>
<tr>
<td>کلمه عبور</td>
<td><input type="text" name="password" class="password"></td>
</tr>
<tr>
<td>تکرار کلمه عبور</td>
<td><input type="text" name="repeatpassword" class="repeatpassword"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="ثبت" class="submit" name="submit"></td>
</tr>
</table>
</form>
<div class="error pname"><img alt="error" src="template/icon/error.png"><span></span></div>
<div class="error pfamily"><img alt="error" src="template/icon/error.png"><span></span></div>
<div class="error pemail"><img alt="error" src="template/icon/error.png"><span></span></div>
<div class="error psex"><img alt="error" src="template/icon/error.png"><span></span></div>
<div class="error puseame"><img alt="error" src="template/icon/error.png"><span></span></div>
<div class="error ppassword"><img alt="error" src="template/icon/error.png"><span></span></div>
<div class="error prepeatpassword"><img alt="error" src="template/icon/error.png"><span></span></div>
</main>
<!-- -->
<section>
<table class="table2">
<thead>
<td>نام</td>
<td>نام خانوادگي</td>
<td>ايميل</td>
<td>جنسيت</td>
<td>نام کاربري</td>
<td>پسورد</td>
<td>مديريت</td>
</thead>
<tbody>
<?php while($rows=$result->fetch(PDO::FETCH_ASSOC)){ ?>
<tr>
<td><?php echo $rows['name']; ?></td>
<td><?php echo $rows['family']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td><?php echo $rows['sex']; ?></td>
<td><?php echo $rows['useame']; ?></td>
<td><?php echo $rows['password']; ?></td>
<td>
<a href="?id=<?php echo $rows['id']; ?>" onclick="retu confirm('آيا از حذف اطلاعات اطمينان داريد ؟')"><img alt="delete" src="template/icon/delete.png"></a>
<a href="edit.php?id=<?php echo $rows['id']; ?>"><img alt="delete" src="template/icon/edit.png"></a>
</td>
</tr>
<?php }?>
<!-- -->
</tbody>
</table>
<a href="?deleteall" onclick="retu confirm('آيا تمام اطلاعات جدول حذف شود ؟')"><button type="button">حذف تمام اطلاعات جدول</button></a>
</section>
</body>
<?php
/* insert */
if($_SERVER["REQUEST_METHOD"]=="POST"){
if(isset($_POST['name']) && isset($_POST['family']) && isset($_POST['email']) && isset($_POST['sex']) && isset($_POST['useame']) && isset($_POST['password']) && isset($_POST['repeatpassword']) && isset($_POST['submit'])){
$index=array(
'name'=>input($_POST['name']),
'family'=>input($_POST['family']),
'email'=>input($_POST['email']),
'sex'=>input($_POST['sex']),
'useame'=>input($_POST['useame']),
'password'=>input($_POST['password']),
'repeatpassword'=>input($_POST['repeatpassword']),
);
$a=$b=$c=$d=$e=$f=$g=0;
/* validation name */
if(empty($index['name'])){
echo "<script>$('.pname').css({'display':'block'});$('. pname span').text('لطفا نام خود را پر کنيد !');</script>";
}
else if(!preg_match('/^[a-zA-Zx{0600}-x{06EF}]{3,50}$/u',$index['name'])){
echo "<script>$('.pname').css({'display':'block'});$('. pname span').text('کارکتر هاي مجاز : a-z + حروف فارسي + حداقل 3 کارکتر !');</script>";
}
else{
$a=1;
}
/* validation family */
if(empty($index['family'])){
echo "<script>$('.pfamily').css({'display':'block'});$( '.pfamily span').text('لطفا نام خانوادگي خود را پر کنيد !');</script>";
}
else if(!preg_match('/^[a-zA-Zx{0600}-x{06EF}]{3,50}$/u',$index['name'])){
echo "<script>$('.pfamily').css({'display':'block'});$( '.pfamily span').text('کارکتر هاي مجاز : a-z + حروف فارسي + حداقل 3 کارکتر !');</script>";
}
else{
$b=1;
}
/* validation email */
$result_email=$coect->query("SELECT `email` FROM `signup` WHERE `email`='".$index['email']."'");
$rowcount_email=$result_email->rowCount();
if(empty($index['email'])){
echo "<script>$('.pemail').css({'display':'block'});$(' .pemail span').text('لطفا ايميل خود را پر کنيد !');</script>";
}
else if(!filter_var($index['email'],FILTER_VALIDATE_EMAIL)){
echo "<script>$('.pemail').css({'display':'block'});$(' .pemail span').text('ايميل نا معتبر !');</script>";
}
else if($rowcount_email>0){
echo "<script>$('.pemail').css({'display':'block'});$(' .pemail span').text('ايميل شما قبلا ثبت شده است !');</script>";
}
else{
$c=1;
}
/* validation sex */
if(empty($index['sex'])){
echo "<script>$('.psex').css({'display':'block'});$('.p sex span').text('لطفا جنسيت خود را پر کنيد !');</script>";
}
else if(!preg_match('/^[x{0600}-x{06EF}]{2,4}$/u',$index['sex'])){
$d=0;
}
else{
$d=1;
}
/* validation useame */
$result_useame=$coect->query("SELECT `useame` FROM `signup` WHERE `useame`='".$index['useame']."'");
$rowcount=$result_useame->rowCount();
if(empty($index['useame'])){
echo "<script>$('.puseame').css({'display':'block'}); $('.puseame span').text('لطفا نام کاربري خود را پر کنيد !');</script>";
}
else if(!preg_match('/^[a-zA-Z0-9_@.]{3,50}$/i',$index['useame'])){
echo "<script>$('.puseame').css({'display':'block'}); $('.puseame span').text('نام کاربري نا معتبر !');</script>";
}
else if($rowcount>0){
echo "<script>$('.puseame').css({'display':'block'}); $('.puseame span').text('نام کاربري شما قبلا ثبت شده است !');</script>";
}
else{
$e=1;
}
/* validation password */
if(empty($index['password'])){
echo "<script>$('.ppassword').css({'display':'block'}); $('.ppassword span').text('لطفا رمز عبور خود را پر کنيد !');</script>";
}
else if(!preg_match('/^[a-zA-Z0-9_@.]{8,50}$/i',$index['password'])){
echo "<script>$('.ppassword').css({'display':'block'}); $('.ppassword span').text('رمز عبور نا معتبر !');</script>";
}
else{
$f=1;
}
/* validation repeatpassword */
if(empty($index['repeatpassword'])){
echo "<script>$('.prepeatpassword').css({'display':'blo ck'});$('.prepeatpassword span').text('لطفا تکرار رمز عبور خود را پر کنيد !');</script>";
}
else if(!preg_match('/^[a-zA-Z0-9_@.]{8,50}$/i',$index['password'])){
echo "<script>$('.prepeatpassword').css({'display':'blo ck'});$('.prepeatpassword span').text('نکرار رمز عبور نا معتبر !');</script>";
}
else if($index['password']!==$index['repeatpassword']){
echo "<script>$('.prepeatpassword').css({'display':'blo ck'});$('.prepeatpassword span').text('رمز عبور با تکرار آن همخواني ندارد !');</script>";
}
else{
$g=1;
}
if($a==1 && $b==1 && $c==1 && $d==1 && $e==1 && $f==1 && $g==1){
$coect->query("INSERT INTO `signup`(`name`,`family`,`email`,`sex`,`useame`, `password`,`repeatpassword`) VALUES('".$index['name']."','".$index['family']."','".$index['email']."', '".$index['sex']."','".$index['useame']."' ,'".$index['password']."' ,'".$index['repeatpassword']."')");
header('location: index.php');
}
}
}
/* update */
/* delete */
if(isset($_GET['id'])){
$check_id=$coect->query("SELECT `id` FROM `signup` WHERE `id`='".$_GET['id']."'");
$check_id_count=$check_id->rowCount();
if($check_id_count==1){
$coect->query("DELETE FROM `signup` WHERE `id`='".$_GET['id']."' ");
header('location: index.php');
}
else{
echo "<script>alert('ip not found')</script>";
exit();
}
}
if(isset($_GET['deleteall'])){
$deleteall=$coect->query("DELETE FROM `signup`");
if($deleteall){
header("location: index.php");
}
}
?>
</html>
همه چیز درست کار میکنه . اما مشکل اینجاست که بعد از اینکه 2 تا رکورد از طریق فرمی که ساختم ثبت میکنم , برای سومین رکوردی که میخوام ثبت کنم این ارور رو میده :
Waing: Caot modify header information - headers already sent by (output started at D:xampphtdocswwwptindex.php:105) in D:xampphtdocswwwptindex.php on line 214
اطلاعات ثبت میشه تو دیتابیس ولی مشکلش با تابع header هست .
من از نرم افزار شبیه ساز xampp استفاده میکنم .
تشکر
برچسب:
نویسنده: خنجی