PDA

View Full Version : سوال: فوری: مشکل با insert



reza10wert
دوشنبه 26 تیر 1391, 17:39 عصر
مشکل کد چه؟
<?php
if ( isset($_POST['add_user']) ) {
$name= $_POST['name'];
$family= $_POST['family'];
$phone= $_POST['phone'];
$messenger= $_POST['messenger'];
$email= $_POST['email'];
$finance= $_POST['finance'];
$username= $_POST['username'];
$password= $_POST['password'];
$count_goal= $_POST['count_goal'];
$count_assist= $_POST['count_assist'];
$average_goal= $_POST['average_goal'];
$average_assist= $_POST['average_assist'];
$percent_win= $_POST['percent_win'];
$total_point= $_POST['total_point'];
$count_present= $_POST['count_present'];
$count_win= $_POST['count_win'];
$count_second= $_POST['count_second'];
$count_third= $_POST['count_third'];
$count_win_knock= $_POST['count_win_knock'];
$top_score= $_POST['top_score'];
$second_score= $_POST['second_score'];
$top_assist= $_POST['top_assist'];
$top_defence= $_POST['top_defence'];
$top_goalkeeper= $_POST['top_goalkeeper'];
$count_second_knock= $_POST['count_second_knock'];
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_password = '';
$mysql_db = 'db_mongeh';

$link = @mysql_connect($mysql_host , $mysql_user , $mysql_password ) ;
mysql_select_db($mysql_db) ;

if (!@$link || !@mysql_select_db($mysql_db) ) {
die ('Connection to database error !');

}
$query = "INSERT INTO `tbl_profile`
(`profile_id`,`name`,`family`,`phone`,`messenger`, `email`,`finance`,`username`,`password`,`count_goa l`,`count_assist`,`average_goal`,`average_assist`, `percent_win`,`total_point`,`count_present`,`count _win`,`count_second`,`count_third`,`count_win_knoc k`,`top_score`,`second_score`,`top_assist`,`top_de fence`,`top_goalkeeper`,`count_second_knock`) VALUES
(NULL,'$name','$family','$phone','$messenger','$em ail','$finance','$username','$password','$count_go al','$count_assist','$average_goal','$average_assi st','$percent_win','$total_point','$count_present' ,'$count_win','$count_second','$count_third','$cou nt_win_knock','$top_score','$second_score','$top_a ssist','$top_defence','$top_goalkeeper','$count_se cond_knock')";
if(mysql_query($query) ) {
echo 'کاربر جدید افزوده شد';
} else {
echo 'خطایی در هنگام ذخیره کردن رخ داد';
}
}
?>

colors
دوشنبه 26 تیر 1391, 17:42 عصر
چه خطای میده؟

reza10wert
دوشنبه 26 تیر 1391, 18:01 عصر
ذخیره نمیشه
در کل میخوام اگه فرم سامبیت شده ذخیره کنه

colors
دوشنبه 26 تیر 1391, 18:18 عصر
ظاهرا مشکل از نام فیلدها در کوئری هست.

اینجوری بنویسید و چک کنید...

<?php
if ( isset($_POST['add_user']) ) {
/********************** VALUES */
$name= $_POST['name'];
$family= $_POST['family'];
$phone= $_POST['phone'];
$messenger= $_POST['messenger'];
$email= $_POST['email'];
$finance= $_POST['finance'];
$username= $_POST['username'];
$password= $_POST['password'];
$count_goal= $_POST['count_goal'];
$count_assist= $_POST['count_assist'];
$average_goal= $_POST['average_goal'];
$average_assist= $_POST['average_assist'];
$percent_win= $_POST['percent_win'];
$total_point= $_POST['total_point'];
$count_present= $_POST['count_present'];
$count_win= $_POST['count_win'];
$count_second= $_POST['count_second'];
$count_third= $_POST['count_third'];
$count_win_knock= $_POST['count_win_knock'];
$top_score= $_POST['top_score'];
$second_score= $_POST['second_score'];
$top_assist= $_POST['top_assist'];
$top_defence= $_POST['top_defence'];
$top_goalkeeper= $_POST['top_goalkeeper'];
$count_second_knock= $_POST['count_second_knock'];
/************************* INFOS */
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_password = '';
$mysql_db = 'db_mongeh';

/*********** CONNECT TO DATABASE */
$link = @mysql_connect($mysql_host , $mysql_user , $mysql_password ) ;
mysql_select_db($mysql_db) ;

/***************** CHECK CONNECT */
if (!$link ) {
die ('Connection to database error !');
}

/************************* QUERY */
$query = "INSERT INTO `tbl_profile`(
`profile_id`,
`name`,
`family`,
`phone`,
`messenger`,
`email`,
`finance`,
`username`,
`password`,
`count_goa l`,
`count_assist`,
`average_goal`,
`average_assist`,
`percent_win`,
`total_point`,
`count_present`,
`count _win`,
`count_second`,
`count_third`,
`count_win_knoc k`,
`top_score`,
`second_score`,
`top_assist`,
`top_de fence`,
`top_goalkeeper`,
`count_second_knock`) VALUES (
NULL,
'$name',
'$family',
'$phone',
'$messenger',
'$em ail',
'$finance',
'$username',
'$password',
'$count_go al',
'$count_assist',
'$average_goal',
'$average_assi st',
'$percent_win',
'$total_point',
'$count_present',
'$count_win',
'$count_second',
'$count_third',
'$cou nt_win_knock',
'$top_score',
'$second_score',
'$top_a ssist',
'$top_defence',
'$top_goalkeeper',
'$count_se cond_knock')";

if(mysql_query($query) ) {
echo 'کاربر جدید افزوده شد';
} else {
echo 'خطایی در هنگام ذخیره کردن رخ داد';
}
}
?>

مثلا خطوط 65 و 55 رو ببین!