PDA

View Full Version : عدم ذخیره مقادیر یک فرم در دیتابیس



farnoosh66
یک شنبه 11 تیر 1396, 19:24 عصر
سلام
دوستان یه فایل test.htmlدارم شامل:


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>index</title>
</head>
<body>
<form action="calc.php" method="post"><br/>
fname:<input type="text" name="fname"/><br/>
lname:<input type="text" name="lname"/>
<br/>
<input type="submit" value="register"/>
</form>
</body>
</html>



یه فایل calc.php دارم به کدهای


<html>
<head><title>An Example</title></head>
<body><div>

<?php
if ( !empty ($_POST['fname']) && !empty ($_POST['lname']) )
{
$name= $_POST['fname'];
$family= $_POST['lname'];
$coo=@mysqli_connect("localhost","root","","database1");
if (!mysqli_connect_error())
{
mysqli_query($coo,"insert into tbl1 (fname,lname) value ('".$name."','".$family."')");
mysqli_close($coo);
header("location:test.html");
}
else
{
echo 'error connect';
}
}
else
{
header("location:test.html");
}
?>

</div></body></html>

ولی وقتی submit میزنم یه صفحه خالی میاد و هیچ چیزی توی دیتابیسم ذخیره نمیشه، میشه راهنمایی کنید

parsaasefi
یک شنبه 11 تیر 1396, 20:44 عصر
سلام
دوستان یه فایل test.htmlدارم شامل:


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>index</title>
</head>
<body>
<form action="calc.php" method="post"><br/>
fname:<input type="text" name="fname"/><br/>
lname:<input type="text" name="lname"/>
<br/>
<input type="submit" value="register"/>
</form>
</body>
</html>



یه فایل calc.php دارم به کدهای


<html>
<head><title>An Example</title></head>
<body><div>

<?php
if ( !empty ($_POST['fname']) && !empty ($_POST['lname']) )
{
$name= $_POST['fname'];
$family= $_POST['lname'];
$coo=@mysqli_connect("localhost","root","","database1");
if (!mysqli_connect_error())
{
mysqli_query($coo,"insert into tbl1 (fname,lname) value ('".$name."','".$family."')");
mysqli_close($coo);
header("location:test.html");
}
else
{
echo 'error connect';
}
}
else
{
header("location:test.html");
}
?>

</div></body></html>

ولی وقتی submit میزنم یه صفحه خالی میاد و هیچ چیزی توی دیتابیسم ذخیره نمیشه، میشه راهنمایی کنید

درود دوست عزیز
در قسمت کوئری value رو به values تغییر بدید ، نود و نه درصد مشکلتون رفع می شه
و توصیه می کنم در نوشتن کوئری هاتون از حروف بزرگ استفاده کنید
موفق و پیروز باشید

farnoosh66
سه شنبه 13 تیر 1396, 21:32 عصر
دوست اعزیز انجام دادم درست نشد، ایا راه دیگ ای نیست؟
یه سوال! توی php چطوری میشه عین دات نت خط به خط trace کرد کدهارو، که بشه فهمید کدوم خط برنامه ایراد داره؟؟