如何通过比较php中的电子邮件和id来更新查询

时间:2016-02-09 12:40:22

标签: php mysql

您好我需要通过比较ID和电子邮件来更新查询,但是如果我在哪里条件中给出id它不起作用。这是我的代码。

的index.php

<td style="width:21%;"><a class="button add" href="editsalaries.php?id=<?php echo $row['user_id'];?>">Edit Salary Details</a></td>

editsalaries.php

<form method="post" action="updatesalaries.php" id="myform">
<input type='hidden' value="<?php echo $username; ?>" name='email'> 
<?php  include "editsalary.php";?>
<table style="border-collapse: collapse;border: 1px solid black;width:44%;">
<label>Company Name</label>
<input type="text" name="company_name" value="<?php echo $row['company_name'];?>" />
 <label>Name</label>
<input type="text" name="user_name" value="<?php echo $row['user_name'];?>" />
<button type="submit"  class = "medium" style="background-color: #2daebf;">Save</button>

updatesalaries.php

$id=$_GET['id'];
$email=$_POST['email']; 
$companyname=$_POST['company_name'];
$name=$_POST['user_name'];
$query=mysql_query("UPDATE user_salary_details SET
       company_name='$companyname',user_name='$name'WHERE email='$email' AND user_id='$id'  
");

editsalary.php

$id=$_GET['id']; 
$res = "SELECT *
FROM user_salary_details
WHERE email ='$username'
AND user_id='$id'";
$result=mysql_query($res);
$row = mysql_fetch_array($result);

1 个答案:

答案 0 :(得分:1)

第一个代码部分中的表单没有任何名为id的控件,这意味着不会在updatesalaries.php中填充$_GET['id']。将用户标识放入会话变量或隐藏控件中。