简体   繁体   中英

I'm trying to make update process page for my eprofile web

This is what im trying to do.. i got eprofile with a database. the database consist of 2 table which is personal_data and and nationality. 1st user can view thier old personal information then i gonna make update/edit page for them. Nationality is in other table because the nationality in dropdown menu. then the user can change thier personal and information, after they insert new information they clicking the submit button and go to process.php where update process for database occur. my problem is, i dont know how to define/or how to connect two table which is personal_data and nationality in the update query.

code for nationality

  <?php
            $query = "SELECT nationality_type FROM nationality";
            $result = mysql_query ($query); ?>
            <select name="personal_nationality" >
            <?php while($row = mysql_fetch_array($result)){ ?>
            <option value="<?php echo $row['nationality_type']?>"  <?php if ( $personal_nationality ==  $row['nationality_type']){ ?> selected <?php } ?>>
            <?php echo $row['nationality_type']?></option>
            <?php }?>
            </select>

process.php code

    <?php

    $host="localhost"; // test local
    $username="lasadmin"; // Mysql username 
    $password="lasadmin"; // Mysql password 
    $db_name="eprofile"; // Database name 
    $db = mysql_connect($host, $username, $password); 
    $link = mysql_select_db($db_name,$db);


$personal_designation = $_POST['personal_designation'];
$personal_department = $_POST['personal_department'];
$personal_job_grade = $_POST['personal_job_grade'];
$personal_emp_group = $_POST['personal_emp_group'];
$personal_current_company = $_POST['personal_current_company'];
$personal_work_location = $_POST['personal_work_location'];


mysql_query("UPDATE personal_data SET personal_designation = '".mysql_real_escape_string($_POST["personal_designation"])."', personal_department = '".mysql_real_escape_string($_POST["personal_department"])."', personal_job_grade = '".mysql_real_escape_string($_POST["personal_job_grade"])."', personal_emp_group = '".mysql_real_escape_string($_POST["personal_emp_group"])."', personal_current_company = '".mysql_real_escape_string($_POST["personal_current_company"])."', personal_work_location = '".mysql_real_escape_string($_POST["personal_work_location"])."' WHERE LAS_login_id = '".mysql_real_escape_string($_POST["LAS_login_id"])."'");


$personal_full_name = $_POST['personal_full_name'];
$personal_title = $_POST['personal_title'];
$personal_date_birth = $_POST['personal_date_birth'];
$personal_marital_status = $_POST['personal_marital_status'];
$personal_nationality = $_POST['nationality_type'];


mysql_query("UPDATE personal_data SET personal_full_name = '".mysql_real_escape_string($_POST["personal_full_name"])."', personal_title = '".mysql_real_escape_string($_POST["personal_title"])."', personal_date_birth = '".mysql_real_escape_string($_POST["personal_date_birth"])."', personal_marital_status = '".mysql_real_escape_string($_POST["personal_marital_status"])."', nationality_type = '".mysql_real_escape_string($_POST["personal_nationality"])."' WHERE LAS_login_id = '".mysql_real_escape_string($_POST["LAS_login_id"])."'");


?>

when i trying to change the information(testing), this error is show -Notice: Undefined index: nationality_type in C:\\wamp\\www\\eprofile\\process.php on line 26

this is code for line 26

$personal_nationality = $_POST['nationality_type'];

can u tell me what is the problem, and what is the solution for this problem? what should i do on defined index??

You have two problems...

THe first one is in your UPDATE sql query.

WHERE LAS_login_id= '$LAS_login_id'

Where did you find the $LAS_login_id ? You are not defining it anywhere that i can see...

The second problem is with your index nationality_type which you have not included in the code above...

Hope this helps

At first I would recommend to escape the content that you receive by the $_POST variables. You don't need to copy it into extra variables. (Unless us use it for something different)

Second problem is that $LAS_login_id is not initialized, has no value, so your UPDATE statement won't update anything.

//simple update
mysql_query("UPDATE mytable SET 
myvalue = '".mysql_real_escape_string($_POST["my_value"])."' 
WHERE mycriteria = '".mysql_real_escape_string($_POST["my_criteria"])."'");

And there should be an array with nationality_type as index which is undefined too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM