Jump to content

Recommended Posts

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());

}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/86085-editing-profile/
Share on other sites

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440735
Share on other sites

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";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440738
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440749
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440753
Share on other sites

<?php

include_once ("functions.php");

include_once ("config.php");

 

//Start session

&#160;  //Connect to mysql server

&#160;  $link = mysql_connect("localhost","root","");

&#160;  if(!$link) {

&#160; &#160; &#160; die('Failed to connect to server: ' . mysql_error());

&#160;  }

&#160;  //Select database

&#160;  $db = mysql_select_db("project");

&#160;  if(!$db) {

&#160; &#160; &#160; die("Unable to select database");

&#160;  }

&#160; 

&#160;  //Array to store validation errors

 

&#160;  //Connect to mysql server

 

&#160; 

&#160;  //Sanitize the POST values

&#160;  $id = CleanVar(h_($_POST['id']));

&#160;  $fname = CleanVar(h_($_POST['fname']));

&#160;  $lname = CleanVar(h_($_POST['lname']));

&#160;  $gender = CleanVar(h_($_POST['gender']));

&#160;  $day= CleanVar(h_($_POST['day']));

&#160;  $month = CleanVar(h_($_POST['month']));

&#160;  $year = CleanVar(h_($_POST['year']));

&#160;  $country = CleanVar(h_($_POST['country']));

&#160;  $postalcode = CleanVar(h_($_POST['postalcode']));

&#160;  $error&#160; &#160; &#160; &#160; &#160; =&#160;  "N";

 

//start the update

If($error == "N")

{

&#160;  $current_cat_sql = "UPDATE members SET firstname = '".d_($fname)."',

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;  lastname = '".d_($lname)."',

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; gender= '".d_($gender)."',

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; day = '".d_($day)."',

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; month = '".d_($month)."',

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; year = '".d_($year)."',

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; country = '".d_($country)."',

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; postalcode = '".d_($postalcode)."'

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WHERE member_id = '".d_($id)."'";

&#160;  mysql_query ($current_cat_sql) or die ("Err".mysql_error());

header("location: register-success.php");

&#160; &#160; &#160; exit;

}

else

{

echo "error";

}

?>

 

 

This is the code i have used

Link to comment
https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440765
Share on other sites

you have removed "&#160; " 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";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440777
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440787
Share on other sites

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'

Link to comment
https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440911
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/86085-editing-profile/#findComment-440912
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.