注意:未定义的索引:第4行的C:\ xampp \ htdocs \ Project \ modify.php中的id

时间:2014-03-14 22:50:25

标签: php

我一直试图让这段代码工作很长时间但我不断收到此错误: 注意:未定义的索引:第4行的C:\ xampp \ htdocs \ Project \ modify.php中的id 这是代码:

<?php
    include 'includes/phpConnection.php';
    if(!isset($_POST["submit"])) {
        $q = "SELECT * FROM members WHERE ID =".$_GET['id'];
        $result = mysql_query($q);
        $person = mysql_fetch_array($result);   
    }
?>
<h1>Edit A Member</h1>
<form method='post' action= '<?php echo $_SERVER['PHP_SELF']; ?>'>
    First Name<input type = 'text' name= 'inputFName' value = '<?php echo $person['FIRST_NAME']?>'/>
    First Last Name<input type = 'text' name= 'inputLname' value = '<?php echo $person['LAST_NAME']?>'/>
    Second Last Name<input type = 'text' name= 'inputLname2' value = '<?php echo $person['LAST_NAME2']?>'/>
    Date of Birth<input type = 'date' name= 'inputDoB' value = '<?php echo $person['DATE_OF_BIRTH']?>'/>
    relation<input type = 'text' name= 'inputRelation' value = '<?php echo $person['relation_to_me']?>'/>
    age<input type = 'text' name = 'age' />
    <input type="hidden" name = "id" value="<?php echo $_GET['id'];?>"/>
    <br />
    <input type="submit" name="submit"/>
</form>
<?php
    if(isset($_POST['submit'])){
        $u = "UPDATE members SET `FIRST_NAME`='$_POST[inputFName]',`LAST_NAME`='$_POST[inputLname]',`LAST_NAME2`='$_POST[inputLname2]',`DATE_OF_BIRTH`='$_POST[inputDoB]',`AGE`= '$_POST[age]',`relation_to_me`='$_POST[inputRelation]' WHERE ID =".$_POST['id'];
        mysql_query($u) or die(mysql_error());
    }
?> 

请帮助

3 个答案:

答案 0 :(得分:0)

您好像发布了id,而不是将其作为查询参数发送。

if($_POST["id"] === "") echo "id is an empty string\n";
if($_POST["id"] === null) echo "id is null\n";
if(isset($_POST["id"])) echo "id is set\n";
if(!empty($_POST["id"])) echo "id is not empty";

答案 1 :(得分:0)

在您的代码中更正此问题:

<?php
    include 'includes/phpConnection.php';
    if(!isset($_POST["submit"]) && isset($_GET["id"])) { // <--- declare id here
    $id = intval($_GET["id"]); // <--- declare id here and admit only integer values
        $q = "SELECT * FROM members WHERE ID =".$id;
        $result = mysql_query($q);
        $person = mysql_fetch_array($result);   
    }
?>

请记住清理数据输入以防止SQL注入。

答案 2 :(得分:-1)

<?php for ($i=0; $i <$num_results; $i++){?>
<tr  height="25px">
<td align="center "><?php $row = $result->fetch_assoc(); 
echo "<strong>". ($i+1)?><td >
<td    align="center "><?php echo stripslashes($row['I'd]); ?><td>