-
یه مشکل در php
سلام دوستان به نظر شما مشکل این کد چی هست هر کاری کردم بازم این ارور رو می ده وقتی اطلاعات رو توی فرم وارد می کنم و ثبت رو می زنم این ارور رو می ده ارور هم این لاین هست
کد:
$re = mysql_query("insert into users values('$id', '$firstname', '$lastname', '$companyname', '$email', '$address', '$city', '$state', '$postcode', '$country', '$phonenumber', '$securityqid', '$securityqans', '$recive_sms', '$mobile', '$username', '$password', '$ip', '$time')");
کد:
Notice: Undefined variable: id in C:\wamp\www\design\home.php on line 99
اینم کد : [PHP]<? session_start(); ob_start(); include "config.php"; include "lang/fa.php";
$note="";
if(isset($_POST["register"])){
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$companyname = $_POST["companyname"];
$email = $_POST["email"];
$address = $_POST["address"];
$city = $_POST["city"];
$state = $_POST["state"];
$postcode = $_POST["postcode"];
$country = $_POST["country"];
$phonenumber = $_POST["phonenumber"];
$securityqid = $_POST["securityqid"];
$securityqans = $_POST["securityqans"];
$recive_sms = $_POST["recive_sms"];
$mobile = $_POST["mobile"];
$username = $_POST["username"];
$password = $_POST["password"];
$repassword = $_POST["repassword"];
$captcha = $_POST["captcha"];
$ip = $_POST["ip"];
$time = strtotime("now");
$ree = mysql_query("select id from users where username='$username'");
$num = mysql_num_rows($ree);
if (!empty($_REQUEST['captcha']))
{
if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha'])
{
$note="لطفا کد را به درستی وارد نمایید";
}
else
{
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// Insert SQL Statement
$cap="one";
}
}
unset($_SESSION['captcha']);
}
if(empty($firstname) or empty($lastname) or empty($email) or empty($address) or empty($city) or empty($state) or empty($postcode) or empty($country) or empty($securityqid) or empty($securityqans) or empty($recive_sms) or empty($username) or empty($password) or empty($repassword) or empty($captcha)){
$note='<span style="color:#F00;font:9pt tahoma, arial, verdana;position:relative;right:10px;top:8px">لط فا همه فیلد ها را تکمیل نمایید</span>';
}
elseif($password != $repassword){
$note='<span style="color:#F00;font:9pt tahoma, arial, verdana;position:relative;right:10px;top:8px">تک رار رمز عبور با رمز عبور مطابق نیست</span>';
}
elseif($num!=0){
$note='<span style="color:#F00;font:9pt tahoma, arial, verdana;position:relative;right:10px;top:8px">نا م کاربری انتخابی شما تکراری است</span>';
}
else{
$password = ------_encode($password);
$securityqans = ------_encode($securityqans);
$re = mysql_query("insert into users values('$id', '$firstname', '$lastname', '$companyname', '$email', '$address', '$city', '$state', '$postcode', '$country', '$phonenumber', '$securityqid', '$securityqans', '$recive_sms', '$mobile', '$username', '$password', '$ip', '$time')");
if($re){
$note='<span style="color:#F00;font:9pt tahoma, arial, verdana;position:relative;right:10px;top:8px"><img src="images/successful.png" width="28" height="28" /> عضویت با موفقیت انجام شد</span>';
}
}
}
?>[/PHP]اینم کد اتصال به دیتابیس: [PHP]<?PHP
$dbhost = "localhost";
$dbpass = "";
$dbusername = "root";
$dbname = "mpc";
$connection = mysql_connect($dbhost, $dbusername, $dbpass)or die(mysql_error());
mysql_select_db($dbname);
mysql_query("SET NAMES 'utf8'", $connection);
mysql_query("SET CHARACTER SET 'utf8'", $connection);
mysql_query("SET character_set_connection = 'utf8'", $connection);
?>[/PHP]
در ضمن من این کد رو روی سیستم خودم اجرا می کنم روی WampServer ممکنه اشکال از WampServer باشه ؟
-
[HTML]$re = mysql_query('insert into users values('.$id.', "'.$firstname.'", "'.$lastname.'", '.$companyname.', '.$email.', '.$address.', '.$city.', '.$state.', '.$postcode.', '.$country.', '.$phonenumber.', '.$securityqid.', '.$securityqans.', '.$recive_sms.', '.$mobile.', '.$username.', '.$password.', '.$ip.', '.$time.')');
[/HTML]
هرفیلدی در جدول که string هست باید داخل "" بذاری firstname , lastname را من گذاشتم بقیه ش هم خودتون بذارید
-
دوست عزیز این ارور داره به صراحت تمام بهتون میگه متغیر id تعریف نشده است
توی تیبل user آیدی باید autoincrement باشه یعنی شما مقدارو براش تعیین نمیکنی
اینطوری بنویس درست میشه
[PHP]$re = mysql_query("insert into users values('', '$firstname', '$lastname', '$companyname', '$email', '$address', '$city', '$state', '$postcode', '$country', '$phonenumber', '$securityqid', '$securityqans', '$recive_sms', '$mobile', '$username', '$password', '$ip', '$time')");[/PHP]