xxlebadosxx Posted August 19, 2011 Share Posted August 19, 2011 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 ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/245158-help-me-i-am-trying-to-make-a-code-to-update-existing-user-on-my-database/ Share on other sites More sharing options...
MasterACE14 Posted August 19, 2011 Share Posted August 19, 2011 I believe you're missing an exclamation mark in here... else if( !isset($_POST['Button_Update']) ) However you could just leave it as... else $message = "NOT UPDATED !! Please enter the neccesary details : "; Quote Link to comment https://forums.phpfreaks.com/topic/245158-help-me-i-am-trying-to-make-a-code-to-update-existing-user-on-my-database/#findComment-1259212 Share on other sites More sharing options...
xxlebadosxx Posted August 19, 2011 Author Share Posted August 19, 2011 Hi MasterACE14 Thanks for replying to my post. I did exactly as you said but its not working. Please help out. Quote Link to comment https://forums.phpfreaks.com/topic/245158-help-me-i-am-trying-to-make-a-code-to-update-existing-user-on-my-database/#findComment-1259237 Share on other sites More sharing options...
MasterACE14 Posted August 19, 2011 Share Posted August 19, 2011 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']."' "; Quote Link to comment https://forums.phpfreaks.com/topic/245158-help-me-i-am-trying-to-make-a-code-to-update-existing-user-on-my-database/#findComment-1259242 Share on other sites More sharing options...
xxlebadosxx Posted August 19, 2011 Author Share Posted August 19, 2011 Hello MasterACE14 Thanks But i tried the latest code you sent to me and it not working, or do i need to re-create a new table just confused here what do i need to do again ?? Regards Quote Link to comment https://forums.phpfreaks.com/topic/245158-help-me-i-am-trying-to-make-a-code-to-update-existing-user-on-my-database/#findComment-1259251 Share on other sites More sharing options...
MasterACE14 Posted August 19, 2011 Share Posted August 19, 2011 in what way isn't it working? Are you receiving an error? Quote Link to comment https://forums.phpfreaks.com/topic/245158-help-me-i-am-trying-to-make-a-code-to-update-existing-user-on-my-database/#findComment-1259252 Share on other sites More sharing options...
xxlebadosxx Posted August 19, 2011 Author Share Posted August 19, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/245158-help-me-i-am-trying-to-make-a-code-to-update-existing-user-on-my-database/#findComment-1259257 Share on other sites More sharing options...
MasterACE14 Posted August 19, 2011 Share Posted August 19, 2011 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 ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/245158-help-me-i-am-trying-to-make-a-code-to-update-existing-user-on-my-database/#findComment-1259260 Share on other sites More sharing options...
xxlebadosxx Posted August 19, 2011 Author Share Posted August 19, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245158-help-me-i-am-trying-to-make-a-code-to-update-existing-user-on-my-database/#findComment-1259265 Share on other sites More sharing options...
MasterACE14 Posted August 19, 2011 Share Posted August 19, 2011 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/245158-help-me-i-am-trying-to-make-a-code-to-update-existing-user-on-my-database/#findComment-1259268 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.