Ali_Sedaghat
چهارشنبه 21 مرداد 1388, 11:20 صبح
با سلام خدمت تمام كاربران محترم
فرمي را جهت ثبت نام كاربران جديد طراحي كرده ام ولي مشكلي كه با آن مواجهم اين است كه اطلاعات فرم پس از نوشته شدن و ارسال در بانك اطلاعاتي ذخيره نشده و پيغام خطا مي دهد.
چنان چه كسي هست كه مي تواند مرا در حل اين مشكل ياري كند ممنون مي شوم.
سورس كامل برنامه به همراه توابع و فايل ها در زير نوشته شده است.
با تشكر
صداقت
توابع مورد استفاده در اين برنامه :
do_html_header و display_registration_form و do_html_footer و do_html_heading و do_html_url در فايل output_fns.php
filled_out و valid_email در فايل data_valid_fns.php
register در فايل user_auth_fns.php
db_connect در فايل db_fns.php
مشخصات ديتابيس مورد استفاده :
سرور : localhost
نام يوزر و پسورد : root
نام ديتابيس : advertising
Sql بانك اطلاعاتي كه درست كرده ام به صورت زير است :
-- phpMyAdmin SQL Dump
-- version 2.9.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Aug 11, 2009 at 10:34 AM
-- Server version: 5.0.24
-- PHP Version: 5.1.6
--
-- Database: `advertising`
--
--------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`Username` char(15) character set utf8 collate utf8_unicode_ci NOT NULL,
`Password` char(40) character set utf8 collate utf8_unicode_ci NOT NULL,
`Email` char(30) character set utf8 collate utf8_unicode_ci NOT NULL,
`UserType` int(1) unsigned zerofill default '2',
`FirstName` char(15) character set utf8 collate utf8_unicode_ci default NULL,
`LastName` char(25) character set utf8 collate utf8_unicode_ci default NULL,
`BornDate` char(10) character set utf8 collate utf8_unicode_ci default NULL,
`City` char(30) character set utf8 collate utf8_unicode_ci default NULL,
`State` int(2) unsigned zerofill default NULL,
`Country` int(3) unsigned zerofill default NULL,
`ZipCode` char(10) character set utf8 collate utf8_unicode_ci default NULL,
`Address` varchar(100) character set utf8 collate utf8_unicode_ci default NULL,
`Tel` char(12) character set utf8 collate utf8_unicode_ci default NULL,
`Mobile` char(12) character set utf8 collate utf8_unicode_ci default NULL,
PRIMARY KEY (`Username`),
KEY `Username` (`Username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
--
-- Dumping data for table `users`
--
INSERT INTO `users` VALUES ('Ali123', '123456', '1@2.com', 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
--------------------------------------------------
محتويات فايل هاي مورد استفاده :
فايل user_register_form.php :
<?php
require_once('all_fns.php');
do_html_header('?«?¨?? U†?§U…');
display_registration_form();
do_html_footer();
?>
--------------------------------------------------
فايل all_fns.php :
<?php
// We can include this file in all our files
// this way, every file will contain all our functions and exceptions
require_once('data_valid_fns.php');
require_once('db_fns.php');
require_once('user_auth_fns.php');
require_once('output_fns.php');
require_once('url_fns.php');
?>
--------------------------------------------------
فايل data_valid_fns.php :
<?php
function filled_out($form_vars)
{
// test that each variable has a value
foreach ($form_vars as $key => $value)
{
if (!isset($key) || ($value == ''))
return false;
}
return true;
}
function valid_email($address)
{
// check an email address is possibly valid
if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $address))
return true;
else
return false;
}
?>
--------------------------------------------------
فايل db_fns.php :
<?php
function db_connect()
{
$result = new mysqli('localhost', 'root', 'root', 'advertising');
if (!$result)
throw new Exception('Could not connect to database server');
else
return $result;
}
?>
--------------------------------------------------
فايل user_auth_fns.php :
<?php
require_once('db_fns.php');
function register($username, $email, $password)
// register new person with db
// return true or error message
{
// connect to db
$conn = db_connect();
// check if username is unique
$result = $conn->query("select * from users where username='$username'");
if (!$result)
throw new Exception('Could not execute query');
if ($result->num_rows>0)
throw new Exception('That username is taken - go back and choose another one.');
// if ok, put in db
$result = $conn->query("insert into users values
('$username', sha1('$password'), '$email')");
if (!$result)
throw new Exception('Could not register you in database - please try again later.');
return true;
}
?>
--------------------------------------------------
فايل output_fns.php :
<?php
function do_html_header($title)
{
// print an HTML header
?>
<html dir="rtl">
<head>
<title><?php echo $title;?></title>
</head>
<body>
<img src="advertising.gif" alt="AdvertisingCenter logo" border=0
align=left valign=bottom height = 55 width = 57 />
<h1> Advertising Center</h1>
<hr />
<?php
if($title)
do_html_heading($title);
}
function do_html_footer()
{
// print an HTML footer
?>
</body>
</html>
<?php
}
function do_html_heading($heading)
{
// print heading
?>
<h3><font face="Tahoma"><?php echo $heading;?></font></h3>
<?php
}
function do_html_URL($url, $name)
{
// output URL as link and br
?>
<br /><a href="<?php echo $url;?>"><?php echo $name;?></a><br />
<?php
}
function display_registration_form()
{
?>
<form method="POST" action="user_register.php">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; font-family: Tahoma; font-size: 10pt" bordercolor="#111111" width="65%" dir="rtl" id="AutoNumber2">
<tr>
<td width="17%">U†?§U… Uƒ?§?±?¨?±U? :</td>
<td width="13%"><font face="Tahoma">
<input type="text" name="username" size="15" maxlength="15" dir="ltr" style="font-family: Tahoma; font-size: 10pt"></font></td>
<td width="45%" dir="rtl" align="justify"><font style="font-size: 9pt">
U†?§U… Uƒ?§?±?¨?±U? ?¨?§U??¯ ?¨U?U† 6 ???§ 15 Uƒ?§?±?§Uƒ???± ?¨?§?´?¯. Uƒ?§?±?§Uƒ???±U‡?§U? (<span lang="en-us">
" = ' \ / </span>) ??U??± U…?¬?§?² U…U? ?¨?§?´U†?¯.</font></td>
</tr>
<tr>
<td width="17%">?±U…?² ?¹?¨Uˆ?± :</td>
<td width="21%"><font face="Tahoma">
<input type="password" name="passwd" size="15" maxlength="15" dir="ltr" style="font-family: Tahoma; font-size: 10pt"></font></td>
<td width="45%" dir="rtl" align="justify"><font style="font-size: 9pt">
?±U…?² ?¹?¨Uˆ?± ?¨?§U??¯ ?¨U?U† 6 ???§ 15 Uƒ?§?±?§Uƒ???± ?¨?§?´?¯. Uƒ?§?±?§Uƒ???±U‡?§U? (<span lang="en-us">
" = ' \ / </span>) ??U??± U…?¬?§?² U…U? ?¨?§?´U†?¯.</font></td>
</tr>
<tr>
<td width="17%">??Uƒ?±?§?± U…?¬?¯?¯ ?±U…?² ?¹?¨Uˆ?± :</td>
<td width="24%"><font face="Tahoma">
<input type="password" name="passwd2" size="15" maxlength="15" dir="ltr" style="font-family: Tahoma; font-size: 10pt"></font></td>
<td width="45%" align="justify"><font style="font-size: 9pt">
?±U…?² ?¹?¨Uˆ?± ?¨?§U??¯ ?¨U?U† 6 ???§ 15 Uƒ?§?±?§Uƒ???± ?¨?§?´?¯. Uƒ?§?±?§Uƒ???±U‡?§U? (<span lang="en-us">
" = ' \ / </span>) ??U??± U…?¬?§?² U…U? ?¨?§?´U†?¯.</font></td>
</tr>
<tr>
<td width="17%">?§U?U…U?U„ :</td>
<td width="24%"><font face="Tahoma">
<input type="text" name="email" size="30" maxlength="100" dir="ltr" style="font-family: Tahoma; font-size: 10pt"></font></td>
<td width="45%" align="justify"><span style="font-size: 9pt">U„?·U??§U‹ ?§U?U…U?U„
U…?¹???¨?± Uˆ?§?±?¯ U†U…?§U?U??¯ ?†UˆU† ?§?±?³?§U„ ?±U…?² U??±?§U…Uˆ?´ ?´?¯U‡ Uˆ U†U??² U…Uƒ?§???¨?§?? ?³?§U??? ?§?² ?·?±U?U‚
?§U?U† ?§U?U…U?U„ U…U? ?¨?§?´?¯. U‡U… ?†U†U?U† </span><font style="font-size: 9pt">
Uƒ?§?±?§Uƒ???±U‡?§U? (<span lang="en-us"> " = ' \ / </span>) ??U??± U…?¬?§?² U…U? ?¨?§?´U†?¯.</font></td>
</tr>
<tr>
<td width="17%"> </td>
<td width="49%" colspan="2"> </td>
</tr>
<tr>
<td width="60%" colspan="3">
<p align="right"><font face="Tahoma">
<input type="submit" value="?«?¨?? U†?§U…" name="submit" dir="rtl" style="font-family: Tahoma; font-size: 10pt">
<input type="reset" value="U¾?§Uƒ Uƒ?±?¯U† U??±U…" name="reset" dir="rtl" style="font-family: Tahoma; font-size: 10pt"></font></td>
</tr>
</table>
</div>
</form>
<?php
}
?>
فرمي را جهت ثبت نام كاربران جديد طراحي كرده ام ولي مشكلي كه با آن مواجهم اين است كه اطلاعات فرم پس از نوشته شدن و ارسال در بانك اطلاعاتي ذخيره نشده و پيغام خطا مي دهد.
چنان چه كسي هست كه مي تواند مرا در حل اين مشكل ياري كند ممنون مي شوم.
سورس كامل برنامه به همراه توابع و فايل ها در زير نوشته شده است.
با تشكر
صداقت
توابع مورد استفاده در اين برنامه :
do_html_header و display_registration_form و do_html_footer و do_html_heading و do_html_url در فايل output_fns.php
filled_out و valid_email در فايل data_valid_fns.php
register در فايل user_auth_fns.php
db_connect در فايل db_fns.php
مشخصات ديتابيس مورد استفاده :
سرور : localhost
نام يوزر و پسورد : root
نام ديتابيس : advertising
Sql بانك اطلاعاتي كه درست كرده ام به صورت زير است :
-- phpMyAdmin SQL Dump
-- version 2.9.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Aug 11, 2009 at 10:34 AM
-- Server version: 5.0.24
-- PHP Version: 5.1.6
--
-- Database: `advertising`
--
--------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`Username` char(15) character set utf8 collate utf8_unicode_ci NOT NULL,
`Password` char(40) character set utf8 collate utf8_unicode_ci NOT NULL,
`Email` char(30) character set utf8 collate utf8_unicode_ci NOT NULL,
`UserType` int(1) unsigned zerofill default '2',
`FirstName` char(15) character set utf8 collate utf8_unicode_ci default NULL,
`LastName` char(25) character set utf8 collate utf8_unicode_ci default NULL,
`BornDate` char(10) character set utf8 collate utf8_unicode_ci default NULL,
`City` char(30) character set utf8 collate utf8_unicode_ci default NULL,
`State` int(2) unsigned zerofill default NULL,
`Country` int(3) unsigned zerofill default NULL,
`ZipCode` char(10) character set utf8 collate utf8_unicode_ci default NULL,
`Address` varchar(100) character set utf8 collate utf8_unicode_ci default NULL,
`Tel` char(12) character set utf8 collate utf8_unicode_ci default NULL,
`Mobile` char(12) character set utf8 collate utf8_unicode_ci default NULL,
PRIMARY KEY (`Username`),
KEY `Username` (`Username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
--
-- Dumping data for table `users`
--
INSERT INTO `users` VALUES ('Ali123', '123456', '1@2.com', 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
--------------------------------------------------
محتويات فايل هاي مورد استفاده :
فايل user_register_form.php :
<?php
require_once('all_fns.php');
do_html_header('?«?¨?? U†?§U…');
display_registration_form();
do_html_footer();
?>
--------------------------------------------------
فايل all_fns.php :
<?php
// We can include this file in all our files
// this way, every file will contain all our functions and exceptions
require_once('data_valid_fns.php');
require_once('db_fns.php');
require_once('user_auth_fns.php');
require_once('output_fns.php');
require_once('url_fns.php');
?>
--------------------------------------------------
فايل data_valid_fns.php :
<?php
function filled_out($form_vars)
{
// test that each variable has a value
foreach ($form_vars as $key => $value)
{
if (!isset($key) || ($value == ''))
return false;
}
return true;
}
function valid_email($address)
{
// check an email address is possibly valid
if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $address))
return true;
else
return false;
}
?>
--------------------------------------------------
فايل db_fns.php :
<?php
function db_connect()
{
$result = new mysqli('localhost', 'root', 'root', 'advertising');
if (!$result)
throw new Exception('Could not connect to database server');
else
return $result;
}
?>
--------------------------------------------------
فايل user_auth_fns.php :
<?php
require_once('db_fns.php');
function register($username, $email, $password)
// register new person with db
// return true or error message
{
// connect to db
$conn = db_connect();
// check if username is unique
$result = $conn->query("select * from users where username='$username'");
if (!$result)
throw new Exception('Could not execute query');
if ($result->num_rows>0)
throw new Exception('That username is taken - go back and choose another one.');
// if ok, put in db
$result = $conn->query("insert into users values
('$username', sha1('$password'), '$email')");
if (!$result)
throw new Exception('Could not register you in database - please try again later.');
return true;
}
?>
--------------------------------------------------
فايل output_fns.php :
<?php
function do_html_header($title)
{
// print an HTML header
?>
<html dir="rtl">
<head>
<title><?php echo $title;?></title>
</head>
<body>
<img src="advertising.gif" alt="AdvertisingCenter logo" border=0
align=left valign=bottom height = 55 width = 57 />
<h1> Advertising Center</h1>
<hr />
<?php
if($title)
do_html_heading($title);
}
function do_html_footer()
{
// print an HTML footer
?>
</body>
</html>
<?php
}
function do_html_heading($heading)
{
// print heading
?>
<h3><font face="Tahoma"><?php echo $heading;?></font></h3>
<?php
}
function do_html_URL($url, $name)
{
// output URL as link and br
?>
<br /><a href="<?php echo $url;?>"><?php echo $name;?></a><br />
<?php
}
function display_registration_form()
{
?>
<form method="POST" action="user_register.php">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; font-family: Tahoma; font-size: 10pt" bordercolor="#111111" width="65%" dir="rtl" id="AutoNumber2">
<tr>
<td width="17%">U†?§U… Uƒ?§?±?¨?±U? :</td>
<td width="13%"><font face="Tahoma">
<input type="text" name="username" size="15" maxlength="15" dir="ltr" style="font-family: Tahoma; font-size: 10pt"></font></td>
<td width="45%" dir="rtl" align="justify"><font style="font-size: 9pt">
U†?§U… Uƒ?§?±?¨?±U? ?¨?§U??¯ ?¨U?U† 6 ???§ 15 Uƒ?§?±?§Uƒ???± ?¨?§?´?¯. Uƒ?§?±?§Uƒ???±U‡?§U? (<span lang="en-us">
" = ' \ / </span>) ??U??± U…?¬?§?² U…U? ?¨?§?´U†?¯.</font></td>
</tr>
<tr>
<td width="17%">?±U…?² ?¹?¨Uˆ?± :</td>
<td width="21%"><font face="Tahoma">
<input type="password" name="passwd" size="15" maxlength="15" dir="ltr" style="font-family: Tahoma; font-size: 10pt"></font></td>
<td width="45%" dir="rtl" align="justify"><font style="font-size: 9pt">
?±U…?² ?¹?¨Uˆ?± ?¨?§U??¯ ?¨U?U† 6 ???§ 15 Uƒ?§?±?§Uƒ???± ?¨?§?´?¯. Uƒ?§?±?§Uƒ???±U‡?§U? (<span lang="en-us">
" = ' \ / </span>) ??U??± U…?¬?§?² U…U? ?¨?§?´U†?¯.</font></td>
</tr>
<tr>
<td width="17%">??Uƒ?±?§?± U…?¬?¯?¯ ?±U…?² ?¹?¨Uˆ?± :</td>
<td width="24%"><font face="Tahoma">
<input type="password" name="passwd2" size="15" maxlength="15" dir="ltr" style="font-family: Tahoma; font-size: 10pt"></font></td>
<td width="45%" align="justify"><font style="font-size: 9pt">
?±U…?² ?¹?¨Uˆ?± ?¨?§U??¯ ?¨U?U† 6 ???§ 15 Uƒ?§?±?§Uƒ???± ?¨?§?´?¯. Uƒ?§?±?§Uƒ???±U‡?§U? (<span lang="en-us">
" = ' \ / </span>) ??U??± U…?¬?§?² U…U? ?¨?§?´U†?¯.</font></td>
</tr>
<tr>
<td width="17%">?§U?U…U?U„ :</td>
<td width="24%"><font face="Tahoma">
<input type="text" name="email" size="30" maxlength="100" dir="ltr" style="font-family: Tahoma; font-size: 10pt"></font></td>
<td width="45%" align="justify"><span style="font-size: 9pt">U„?·U??§U‹ ?§U?U…U?U„
U…?¹???¨?± Uˆ?§?±?¯ U†U…?§U?U??¯ ?†UˆU† ?§?±?³?§U„ ?±U…?² U??±?§U…Uˆ?´ ?´?¯U‡ Uˆ U†U??² U…Uƒ?§???¨?§?? ?³?§U??? ?§?² ?·?±U?U‚
?§U?U† ?§U?U…U?U„ U…U? ?¨?§?´?¯. U‡U… ?†U†U?U† </span><font style="font-size: 9pt">
Uƒ?§?±?§Uƒ???±U‡?§U? (<span lang="en-us"> " = ' \ / </span>) ??U??± U…?¬?§?² U…U? ?¨?§?´U†?¯.</font></td>
</tr>
<tr>
<td width="17%"> </td>
<td width="49%" colspan="2"> </td>
</tr>
<tr>
<td width="60%" colspan="3">
<p align="right"><font face="Tahoma">
<input type="submit" value="?«?¨?? U†?§U…" name="submit" dir="rtl" style="font-family: Tahoma; font-size: 10pt">
<input type="reset" value="U¾?§Uƒ Uƒ?±?¯U† U??±U…" name="reset" dir="rtl" style="font-family: Tahoma; font-size: 10pt"></font></td>
</tr>
</table>
</div>
</form>
<?php
}
?>