rinteractive Posted January 15, 2008 Share Posted January 15, 2008 hai guys!!!! i am new to php and Mysql , i am trying to edit the user profile bt the table is not updating the records. The coding i have used for updating below: <?php include_once ("functions.php"); include_once ("config.php"); //Start session session_start(); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { if(!get_magic_quotes_gpc()) { $str = @trim(mysql_real_escape_string($str)); } else { return @trim($str); } } //Sanitize the POST values $fname = clean($_POST['fname']); $lname = clean($_POST['lname']); $gender = clean($_POST['gender']); $day= clean($_POST['day']); $month = clean($_POST['month']); $year = clean($_POST['year']); $country = clean($_POST['country']); $postalcode = clean($_POST['postalcode']); $id = Cleanvar($_REQUEST['id']); //Input Validations if($fname == '') { $errmsg_arr[] = 'First name missing'; $errflag = true; } if($lname == '') { $errmsg_arr[] = 'Last name missing'; $errflag = true; } if($gender == '') { $errmsg_arr[] = 'Gender missing'; $errflag = true; } if($day == '') { $errmsg_arr[] = 'Day missing'; $errflag = true; } if($month == '') { $errmsg_arr[] = 'Month missing'; $errflag = true; } if($year == '') { $errmsg_arr[] = 'Year missing'; $errflag = true; } if($country == '') { $errmsg_arr[] = 'Country name missing'; $errflag = true; } if($postalcode == '') { $errmsg_arr[] = 'Postal code missing'; $errflag = true; } //Check for duplicate login ID //If there are input validations, redirect back to the registration form //Create INSERT query $qry = "UPDATE members SET firstname = '$fname' , lastname = '$lname', gender = '$gender', day = '$day', month = '$month', year = '$year', country = '$country' , postalcode = '$postalcode' WHERE member_id = '".d_($id)."'"; $result = mysql_query($qry); //Check whether the query was successful or not if($result) { header("location: register-success.php"); exit(); }else { die("Query failed".mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/ Share on other sites More sharing options...
rinteractive Posted January 16, 2008 Author Share Posted January 16, 2008 hey guys , i have changed my code now bt error message is showing please anyone help me???? my code is this <?php include_once ("functions.php"); include_once ("config.php"); //Start session //Connect to mysql server $link = mysql_connect("localhost","root",""); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db("project"); if(!$db) { die("Unable to select database"); } //Array to store validation errors //Connect to mysql server //Sanitize the POST values $id = CleanVar(h_($_POST['id'])); $fname = CleanVar(h_($_POST['fname'])); $lname = CleanVar(h_($_POST['lname'])); $gender = CleanVar(h_($_POST['gender'])); $day= CleanVar(h_($_POST['day'])); $month = CleanVar(h_($_POST['month'])); $year = CleanVar(h_($_POST['year'])); $country = CleanVar(h_($_POST['country'])); $postalcode = CleanVar(h_($_POST['postalcode'])); $error = "N"; if ($error == "Y"){ include_once ("register-edit.php"); exit; } else{ $current_cat_sql = "UPDATE members SET firstname = '".d_($fname)."', lastname = '".d_($lname)."', gender= '".d_($gender)."', day = '".d_($day)."', month = '".d_($month)."', year = '".d_($year)."', country = '".d_($country)."', postalcode = '".d_($postalcode)."' WHERE member_id = '".d_($id)."'"; mysql_query ($current_cat_sql) or die ("Err".mysql_error()); } header("location: register-success.php"); exit; ?> The error message is Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\project\admin\PHP-Login\register-edit-action1.php:1) in C:\xampp\htdocs\project\admin\PHP-Login\register-edit-action1.php on line 53 Thanks in Advance Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440735 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 try this $current_cat_sql = "UPDATE members SET firstname = '".d_($fname)."', lastname = '".d_($lname)."', gender= '".d_($gender)."', day = '".d_($day)."', month = '".d_($month)."', year = '".d_($year)."', country = '".d_($country)."', postalcode = '".d_($postalcode)."' WHERE member_id = '".d_($id)."'"; mysql_query ($current_cat_sql) or die ("Err".mysql_error()); } if($current_cat_sql ) { header("location: register-success.php"); } else { echo "no update"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440738 Share on other sites More sharing options...
rinteractive Posted January 16, 2008 Author Share Posted January 16, 2008 Thanks Adam i have tired your then also it gives the same error message Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440742 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 Change header("location: register-success.php"); to header('Location: register-success.php') also you have //start session but dont actually start a session. Add this session_start(); Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440745 Share on other sites More sharing options...
rinteractive Posted January 16, 2008 Author Share Posted January 16, 2008 when i write session_start(); code it given the error message like this Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\project\admin\PHP-Login\register-edit-action1.php:1) in C:\xampp\htdocs\project\admin\PHP-Login\register-edit-action1.php on line 6 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\project\admin\PHP-Login\register-edit-action1.php:1) in C:\xampp\htdocs\project\admin\PHP-Login\register-edit-action1.php on line 57 Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440749 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 try this, <?php include_once ("functions.php"); include_once ("config.php"); //Start session //Connect to mysql server $link = mysql_connect("localhost","root",""); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db("project"); if(!$db) { die("Unable to select database"); } //Array to store validation errors //Connect to mysql server //Sanitize the POST values $id = CleanVar(h_($_POST['id'])); $fname = CleanVar(h_($_POST['fname'])); $lname = CleanVar(h_($_POST['lname'])); $gender = CleanVar(h_($_POST['gender'])); $day= CleanVar(h_($_POST['day'])); $month = CleanVar(h_($_POST['month'])); $year = CleanVar(h_($_POST['year'])); $country = CleanVar(h_($_POST['country'])); $postalcode = CleanVar(h_($_POST['postalcode'])); $error = "N"; //start the update If($error == "N") { $current_cat_sql = "UPDATE members SET firstname = '".d_($fname)."', lastname = '".d_($lname)."', gender= '".d_($gender)."', day = '".d_($day)."', month = '".d_($month)."', year = '".d_($year)."', country = '".d_($country)."', postalcode = '".d_($postalcode)."' WHERE member_id = '".d_($id)."'"; mysql_query ($current_cat_sql) or die ("Err".mysql_error()); header("location: register-success.php"); exit; } else { echo "error"; } ?> removed the session stuff. Also are you echoing information out before the header is set. If so remove that echo below the header. Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440753 Share on other sites More sharing options...
rinteractive Posted January 16, 2008 Author Share Posted January 16, 2008 i have tired your code it showing error message like this Parse error: syntax error, unexpected '&' in C:\xampp\htdocs\project\admin\PHP-Login\register-edit-action1.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440759 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 Whats on line 6, Post your whole code. Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440761 Share on other sites More sharing options...
rinteractive Posted January 16, 2008 Author Share Posted January 16, 2008 <?php include_once ("functions.php"); include_once ("config.php"); //Start session   //Connect to mysql server   $link = mysql_connect("localhost","root","");   if(!$link) {       die('Failed to connect to server: ' . mysql_error());   }   //Select database   $db = mysql_select_db("project");   if(!$db) {       die("Unable to select database");   }     //Array to store validation errors   //Connect to mysql server     //Sanitize the POST values   $id = CleanVar(h_($_POST['id']));   $fname = CleanVar(h_($_POST['fname']));   $lname = CleanVar(h_($_POST['lname']));   $gender = CleanVar(h_($_POST['gender']));   $day= CleanVar(h_($_POST['day']));   $month = CleanVar(h_($_POST['month']));   $year = CleanVar(h_($_POST['year']));   $country = CleanVar(h_($_POST['country']));   $postalcode = CleanVar(h_($_POST['postalcode']));   $error          =  "N"; //start the update If($error == "N") {   $current_cat_sql = "UPDATE members SET firstname = '".d_($fname)."',                               lastname = '".d_($lname)."',                               gender= '".d_($gender)."',                               day = '".d_($day)."',                               month = '".d_($month)."',                               year = '".d_($year)."',                               country = '".d_($country)."',                               postalcode = '".d_($postalcode)."'                   WHERE member_id = '".d_($id)."'";   mysql_query ($current_cat_sql) or die ("Err".mysql_error()); header("location: register-success.php");       exit; } else { echo "error"; } ?> This is the code i have used Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440765 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 whats on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440771 Share on other sites More sharing options...
rinteractive Posted January 16, 2008 Author Share Posted January 16, 2008 It give error on this line   //Connect to mysql server as un excepted '&' Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440773 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 you have removed "  " from the scripts right. That was put in by the forum. No idea why is does that. This it have something to do with spacing or tabbing <?php include_once ("functions.php"); include_once ("config.php"); //Start session //Connect to mysql server $link = mysql_connect("localhost","root",""); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db("project"); if(!$db) { die("Unable to select database"); } //Array to store validation errors //Connect to mysql server //Sanitize the POST values $id = CleanVar(h_($_POST['id'])); $fname = CleanVar(h_($_POST['fname'])); $lname = CleanVar(h_($_POST['lname'])); $gender = CleanVar(h_($_POST['gender'])); $day= CleanVar(h_($_POST['day'])); $month = CleanVar(h_($_POST['month'])); $year = CleanVar(h_($_POST['year'])); $country = CleanVar(h_($_POST['country'])); $postalcode = CleanVar(h_($_POST['postalcode'])); $error ="N"; //start the update If($error == "N") { $current_cat_sql = "UPDATE members SET firstname = '".d_($fname)."', lastname = '".d_($lname)."', gender= '".d_($gender)."', day = '".d_($day)."', month = '".d_($month)."', year = '".d_($year)."', country = '".d_($country)."', postalcode = '".d_($postalcode)."' WHERE member_id = '".d_($id)."'"; mysql_query ($current_cat_sql) or die ("Err".mysql_error()); header("location: register-success.php"); exit; } else { echo "error"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440777 Share on other sites More sharing options...
rinteractive Posted January 16, 2008 Author Share Posted January 16, 2008 The above query is running but the table is not updating the record :'( Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440785 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 So the header is chaning? also change $current_cat_sql = "UPDATE members SET firstname = '".d_($fname)."', lastname = '".d_($lname)."', gender= '".d_($gender)."', day = '".d_($day)."', month = '".d_($month)."', year = '".d_($year)."', country = '".d_($country)."', postalcode = '".d_($postalcode)."' WHERE member_id = '".d_($id)."'"; mysql_query ($current_cat_sql) or die ("Err".mysql_error()); header("location: register-success.php"); exit; to $current_cat_sql = "UPDATE members SET firstname = $fname, lastname = $lname, gender= $gender, day = $day, month =$month, year = $year, country = $country, postalcode = $postalcode WHERE member_id = $id; mysql_query ($current_cat_sql) or die ("Err".mysql_error()); header("location: register-success.php"); exit; Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440787 Share on other sites More sharing options...
rinteractive Posted January 16, 2008 Author Share Posted January 16, 2008 Its giving error like this Err You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 9 Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440819 Share on other sites More sharing options...
rinteractive Posted January 16, 2008 Author Share Posted January 16, 2008 please anybody help me???? i am running out of my time my boss is scribbllinnng me Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440836 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 When you post an error show us what line it is on. We know it is on line 9 but what is written on line 9 Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440842 Share on other sites More sharing options...
foreverhex Posted January 16, 2008 Share Posted January 16, 2008 When you post an error show us what line it is on. We know it is on line 9 but what is written on line 9 Yes, this would help. Chances are its simply a quote problem. I get errors like this when I forget to add a quote to something like WHERE username = $blah instead of WHERE username = '$blah' Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440911 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 Change mysql_query ($current_cat_sql) or die ("Err".mysql_error()); to mysql_query ($current_cat_sql) or die ("Err in $current_cat_sql".mysql_error()); So we can actually see the query. Also, we're not here to bail you out from your boss. please anybody help me???? i am running out of my time my boss is scribbllinnng me Quote Link to comment https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440912 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.