PDA

View Full Version : سوال: کمک در مورد کد های php



edifire
یک شنبه 21 خرداد 1391, 20:47 عصر
با سلام خدمت دوستان
من تازه شروع کردم به یادگیری php و در مبحث فرم ها گیر افتادم میخواستم ببینم کسی هست یک نگاهی به کد های که من نوشتم بکنه و بگه مشکل از کجاست اینهم اضافه کنم که من برای اجرا کردن کدها از سرور لوکال مثل(ٍeasy php , wampserver ) استفاده می کنم

برنامه ای برای جمع آوری اطلاعات کاربر بنویسید





<html>

<head>
<title> Html Form </title>
</head>

<body>

<form action="Handleform.php" method="get">

First Name <input type="text"
name="First Name" size="20"><br>

Last Name <input type="text"
name="Last Name" size="40"><br>

E-mail Address <input type="text" name="Email" size="60"><br>

Comments <textarea name="Comments" rows="5" cols="40">

</textarea><br>

<input type="submit" name="submit" value="Submit">

</form>
</body>

</html>

]








<html>

<head>
<title>Form Results</title>
</head>

<body>

<?php


/* This Page receives and handles the data
generated by "frpm.html".*/

print "Your first name is $FirstName.<br>\n";

print "Your Last name is $LastName.<br>\n";

print "Your E-mail address is $Email.<br>\n";

print "This is what you had to say:<br>\n
$Comments<br>\n";


?>

</body>

</html>





اینو که اجرا می کنم نتیجه میشه این






\n"; print "Your Last name is $LastName.
\n"; print "Your E-mail address is $Email.
\n"; print "This is what you had to say:
\n $Comments
\n"; ?>

MMSHFE
یک شنبه 21 خرداد 1391, 22:11 عصر
کد فرم:


<html>
<head>
<title>HTML Form</title>
</head>
<body>
<form action="Handleform.php" method="post">
First Name <input type="text" name="FirstName" size="20"/><br/>
Last Name <input type="text" name="LastName" size="40"/><br/>
E-mail Address <input type="text" name="Email" size="60"/><br/>
Comments<br/><textarea name="Comments" rows="5" cols="40"></textarea><br/>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
و صفحه مقصد فرم:


<html>
<head>
<title>Form Results</title>
</head>
<body>
<?php
/* This Page receives and handles the data
generated by "frpm.html".*/
$FirstName = isset($_POST['FirstName']) ? $_POST['FirstName'] : '';
$LastName = isset($_POST['LastName']) ? $_POST['LastName'] : '';
$Email = isset($_POST['Email']) ? $_POST['Email'] : '';
print "<p>Your first name is $FirstName.</p>\n";
print "<p>Your Last name is $LastName.</p>\n";
print "<p>Your E-mail address is $Email.</p>\n";
print "<p>This is what you had to say:</p>\n";
nl2br($Comments)."\n";
?>
</body>
</html>

دقت کنید که صفحه مقصد فرم حتماً باید با پسوند php. ذخیره شده باشه تا کار کنه. درواقع کدهای PHP توی فایلهای با پسوند غیر php. کار نمیکنه.
موفق باشید.

mahdi_1986
دوشنبه 22 خرداد 1391, 06:07 صبح
فکر کنم کد
<form action="Handleform.php" method="get">
باید به این صورت باشد
<form action="Handleform.php" method="POST">

MMSHFE
دوشنبه 22 خرداد 1391, 13:38 عصر
درسته حق با شماست. من چون کد ایشون رو داشتم اصلاح میکردم حواسم به این نبود. باید روش POST انتخاب بشه.