Jump to content

HELP ME: I am trying to make a code to Update existing user on my database


xxlebadosxx

Recommended Posts

Hello world!

 

 

I really don't know where i Got it wrong and i will appreciate if someone can help me out.

 

I am trying to make a code to Update existing user on my database. the code displays the the user info but it is not updating, Please help out.

 

       

 

Here is the code:

 

 

<?

session_start();

 

if( !isset($_SESSION['user_logged']) )

  { header('Location: ./login.php');

    exit;}

 

include './config.php';

$message ="Edit My Info ";

$link=mysql_connect("localhost",$user_db,$pass_db);

if(!link)

  die("Could not connect to MySql Server".mysql_error() );  //check for database connection

 

  mysql_select_db($db) or die("could not select Database :$db".mysql_error() );

 

  $query='SELECT * FROM user_data where acc_no = "'.$_SESSION['user_logged'].'" ';

  $result=mysql_query($query) or die ("Invalid query :".mysql_error() ); //check for query execution

 

  $info=mysql_fetch_array($result,MYSQL_ASSOC);

 

  $booking_no=$_POST['booking_no'];

  $container_no=$_POST['container_no'];

  $port_loading=$_POST['port_loading'];

  $date_loading=$_POST['date_loading'];

  $senders_name=$_POST['senders_name'];

  $senders_address=$_POST['senders_address'];

  $receivers_name=$_POST['receivers_name'];

  $receivers_address=$_POST['receivers_address'];

  $city_state=$_POST['city_state'];

  $country=$_POST['country'];

  $email=$_POST['email'];

  $receivers_phone=$_POST['receivers_phone'];

  $office=$_POST['office'];

  $dispatch_date=$_POST['dispatch_date'];

  $present_status=$_POST['present_status'];

  $last_status=$_POST['last_status'];

  $final_port=$_POST['final_port'];

  $delivery_date=$_POST['delivery_date']; 

 

 

  if(($booking_no!="")&&($container_no!="")&&($port_loading!="")&&($date_loading!="")&&($senders_name!="")&&($senders_address!=""))

  {

  $booking_no=addslashes(htmlspecialchars($booking_no));

  $email=addslashes(htmlspecialchars($email));

  $container_no=addslashes(htmlspecialchars($container_no));

  $port_loading=addslashes(htmlspecialchars($port_loading));

  $date_loading=addslashes(htmlspecialchars($date_loading));

  $senders_name=addslashes(htmlspecialchars($senders_name));

  $senders_address=addslashes(htmlspecialchars($senders_address));

  $receivers_name=addslashes(htmlspecialchars($receivers_name));

  $receivers_address=addslashes(htmlspecialchars($receivers_address));

  $city_state=addslashes(htmlspecialchars($city_state));

  $country=addslashes(htmlspecialchars($country));

  $email=addslashes(htmlspecialchars($email));

  $receivers_phone=addslashes(htmlspecialchars($receivers_phone));

  $office=addslashes(htmlspecialchars($office));

  $dispatch_date=addslashes(htmlspecialchars($dispatch_date));

  $present_status=addslashes(htmlspecialchars($present_status));

  $last_status=addslashes(htmlspecialchars($last_status));

  $final_port=addslashes(htmlspecialchars($final_port));

  $delivery_date=addslashes(htmlspecialchars($delivery_date));

 

 

 

  $query= 'UPDATE `'.$db.'`.`user_data` SET `booking_no` = "'.$booking_no.'",`container_no` = "'.$container_no.'",`port_loading` = "'.$port_loading.'",`date_loading` = "'.$date_loading.'",`senders_name` = "'.$senders_name.'",`senders_address` = "'.$senders_address.'" WHERE `user_data`.`acc_no` = "'.$_SESSION['user_logged'].'" ';

 

  mysql_query($query) or die ("Invalid query :".mysql_error() );

 

 

 

  $message = "Your account details have been updated ";

 

  }

 

  else if( isset($_POST['Button_Update']) )

    $message = "NOT UPDATED !! Please enter the neccesary details : ";

  mysql_close( $link );

?>

Link to comment
Share on other sites

try this...

<?php
session_start();

if( !isset($_SESSION['user_logged']) )
  { header('Location: ./login.php');
    exit;}

include './config.php';
$message ="Edit My Info ";
$link=mysql_connect("localhost",$user_db,$pass_db);
if(!$link)
   die("Could not connect to MySql Server".mysql_error() );  //check for database connection
   
  mysql_select_db($db) or die("could not select Database :$db".mysql_error() );

  $query='SELECT * FROM user_data where acc_no = "'.$_SESSION['user_logged'].'" ';
  $result=mysql_query($query) or die ("Invalid query :".mysql_error() ); //check for query execution

  $info=mysql_fetch_array($result,MYSQL_ASSOC);
  
  $booking_no=$_POST['booking_no'];
  $container_no=$_POST['container_no'];
  $port_loading=$_POST['port_loading'];
  $date_loading=$_POST['date_loading'];
  $senders_name=$_POST['senders_name'];
  $senders_address=$_POST['senders_address'];
  $receivers_name=$_POST['receivers_name'];
  $receivers_address=$_POST['receivers_address'];
  $city_state=$_POST['city_state'];
  $country=$_POST['country'];
  $email=$_POST['email'];
  $receivers_phone=$_POST['receivers_phone'];
  $office=$_POST['office'];
  $dispatch_date=$_POST['dispatch_date'];
  $present_status=$_POST['present_status'];
  $last_status=$_POST['last_status'];
  $final_port=$_POST['final_port'];
  $delivery_date=$_POST['delivery_date'];  


  if(($booking_no!="")&&($container_no!="")&&($port_loading!="")&&($date_loading!="")&&($senders_name!="")&&($senders_address!=""))
  {
  $booking_no=addslashes(htmlspecialchars($booking_no));
  $email=addslashes(htmlspecialchars($email));
  $container_no=addslashes(htmlspecialchars($container_no));
  $port_loading=addslashes(htmlspecialchars($port_loading));
  $date_loading=addslashes(htmlspecialchars($date_loading));
  $senders_name=addslashes(htmlspecialchars($senders_name));
  $senders_address=addslashes(htmlspecialchars($senders_address));
  $receivers_name=addslashes(htmlspecialchars($receivers_name));
  $receivers_address=addslashes(htmlspecialchars($receivers_address));
  $city_state=addslashes(htmlspecialchars($city_state));
  $country=addslashes(htmlspecialchars($country));
  $email=addslashes(htmlspecialchars($email)); 
  $receivers_phone=addslashes(htmlspecialchars($receivers_phone)); 
  $office=addslashes(htmlspecialchars($office));
  $dispatch_date=addslashes(htmlspecialchars($dispatch_date));
  $present_status=addslashes(htmlspecialchars($present_status)); 
  $last_status=addslashes(htmlspecialchars($last_status)); 
  $final_port=addslashes(htmlspecialchars($final_port)); 
  $delivery_date=addslashes(htmlspecialchars($delivery_date)); 


  
  $query = "UPDATE `".$db."`.`user_data` SET `booking_no` = '".$booking_no."',`container_no` = '".$container_no."',`port_loading` = '".$port_loading."',`date_loading` = '".$date_loading."',`senders_name` = '".$senders_name."',`senders_address` = '".$senders_address."' WHERE `user_data`.`acc_no` = '".$_SESSION['user_logged']."' "; 
  
  mysql_query($query) or die ("Invalid query :".mysql_error() ); 
  
  
  
  $message = "Your account details have been updated ";
  
  }
  
  else
    $message = "NOT UPDATED !! Please enter the neccesary details : ";
  mysql_close( $link );
?>

 

You were missing the dollar sign in here...

if(!link)

changed it to...

if(!$link)

 

Your quotes in your query were all backwards.

$query= 'UPDATE `'.$db.'`.`user_data` SET `booking_no` = "'.$booking_no.'",`container_no` = "'.$container_no.'",`port_loading` = "'.$port_loading.'",`date_loading` = "'.$date_loading.'",`senders_name` = "'.$senders_name.'",`senders_address` = "'.$senders_address.'" WHERE `user_data`.`acc_no` = "'.$_SESSION['user_logged'].'" '; 

is now this...

$query = "UPDATE `".$db."`.`user_data` SET `booking_no` = '".$booking_no."',`container_no` = '".$container_no."',`port_loading` = '".$port_loading."',`date_loading` = '".$date_loading."',`senders_name` = '".$senders_name."',`senders_address` = '".$senders_address."' WHERE `user_data`.`acc_no` = '".$_SESSION['user_logged']."' ";

 

 

 

Link to comment
Share on other sites

 

Thanks.

 

I could sense something is wrong somewhere....

 

1. this error should only be showing when necessary field on the form are filled up

 

NOT UPDATED !! Please enter the neccesary details :

 

But it showing permanently on the package and when i try to fill in and submit nothing changes

 

Hope you understand me

Link to comment
Share on other sites

try...

<?php
session_start();

if( !isset($_SESSION['user_logged']) )
  { header('Location: ./login.php');
    exit;}

include './config.php';
$message ="Edit My Info ";
$link=mysql_connect("localhost",$user_db,$pass_db);
if(!$link)
   die("Could not connect to MySql Server".mysql_error() );  //check for database connection
   
  mysql_select_db($db) or die("could not select Database :$db".mysql_error() );

  $query='SELECT * FROM user_data where acc_no = "'.$_SESSION['user_logged'].'" ';
  $result=mysql_query($query) or die ("Invalid query :".mysql_error() ); //check for query execution

  $info=mysql_fetch_array($result,MYSQL_ASSOC);
  
  $booking_no=$_POST['booking_no'];
  $container_no=$_POST['container_no'];
  $port_loading=$_POST['port_loading'];
  $date_loading=$_POST['date_loading'];
  $senders_name=$_POST['senders_name'];
  $senders_address=$_POST['senders_address'];
  $receivers_name=$_POST['receivers_name'];
  $receivers_address=$_POST['receivers_address'];
  $city_state=$_POST['city_state'];
  $country=$_POST['country'];
  $email=$_POST['email'];
  $receivers_phone=$_POST['receivers_phone'];
  $office=$_POST['office'];
  $dispatch_date=$_POST['dispatch_date'];
  $present_status=$_POST['present_status'];
  $last_status=$_POST['last_status'];
  $final_port=$_POST['final_port'];
  $delivery_date=$_POST['delivery_date'];  


  if(isset($_POST['booking_no']) && isset($_POST['container_no']))
  {
  $booking_no=addslashes(htmlspecialchars($booking_no));
  $email=addslashes(htmlspecialchars($email));
  $container_no=addslashes(htmlspecialchars($container_no));
  $port_loading=addslashes(htmlspecialchars($port_loading));
  $date_loading=addslashes(htmlspecialchars($date_loading));
  $senders_name=addslashes(htmlspecialchars($senders_name));
  $senders_address=addslashes(htmlspecialchars($senders_address));
  $receivers_name=addslashes(htmlspecialchars($receivers_name));
  $receivers_address=addslashes(htmlspecialchars($receivers_address));
  $city_state=addslashes(htmlspecialchars($city_state));
  $country=addslashes(htmlspecialchars($country));
  $email=addslashes(htmlspecialchars($email)); 
  $receivers_phone=addslashes(htmlspecialchars($receivers_phone)); 
  $office=addslashes(htmlspecialchars($office));
  $dispatch_date=addslashes(htmlspecialchars($dispatch_date));
  $present_status=addslashes(htmlspecialchars($present_status)); 
  $last_status=addslashes(htmlspecialchars($last_status)); 
  $final_port=addslashes(htmlspecialchars($final_port)); 
  $delivery_date=addslashes(htmlspecialchars($delivery_date)); 


  
  $query = "UPDATE `".$db."`.`user_data` SET `booking_no` = '".$booking_no."',`container_no` = '".$container_no."',`port_loading` = '".$port_loading."',`date_loading` = '".$date_loading."',`senders_name` = '".$senders_name."',`senders_address` = '".$senders_address."' WHERE `user_data`.`acc_no` = '".$_SESSION['user_logged']."' "; 
  
  mysql_query($query) or die ("Invalid query :".mysql_error() ); 
  
  
  
  $message = "Your account details have been updated ";
  
  } else
    $message = "NOT UPDATED !! Please enter the neccesary details : ";
  mysql_close( $link );
?>

Link to comment
Share on other sites

 

 

Waooo this is the problem of the century, The Code is not working yet.

 

First: I really don't know how to say a very big thank you, you have been so helpful

 

Can you help me write another code, all am trying to do is just to edit or update user information from admin page

 

Or what do you feel, i might have made terrible error which you were not able to detect.

 

I have used all the code you sent me and it not working

 

if you can help me write a code that will be able to UPDATE these few fields

 

  $office=$_POST['office'];

  $dispatch_date=$_POST['dispatch_date'];

  $present_status=$_POST['present_status'];

  $last_status=$_POST['last_status'];

  $final_port=$_POST['final_port'];

  $delivery_date=$_POST['delivery_date']; 

 

I will appreciate

 

Thanks once more.

 

 

 

 

Link to comment
Share on other sites

I won't write the entire script for you. I suggest starting that file again, scrap what you've already made, and redo it something along these lines...

<?php
session_start();

// file includes, config file etc

if(isset($_POST['formValues'])) {
  // validate input
  
  // check input is of correct format/length/value etc
  // IF everything is fine with the input, move onto...
     // ... INSERT query
  
     // display success message
} else {
  // display form was not submitted
}

?>

Link to comment
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.