我是 PHP 新手,在网上看了最后一个小时后,我找不到我的代码有什么问题,所以我来找你。我试图有一个地方来更新我从一个收集的数据。我得到这个错误。未定义的索引:第 12 行 /Users/mm1/Desktop/php/backend form/edit_ac.php 中的 id。这是我目前所拥有的。有人可以帮忙吗..
<?php require("database.php"); ?>
<?php require("functions.php"); ?>
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$id= mysql_prep($_GET['id']);
$last= mysql_prep($_POST['last']);
$first= mysql_prep($_POST['first']);
// update data in mysql database
$sql="UPDATE $tbl_name SET first='{$first}', last='{$last}' WHERE id='{$id}'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='edit_info.php'>View result</a>";
}
else {
echo "ERROR";
}
?>
这是表格(我知道这一切都不完整,我只是想让它先工作。)
<?php require("database.php"); ?>
<?php // Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<form name="form1" method="post" action="edit_ac.php">
<table width="700" border="0" cellpadding="5">
<tr>
<td colspan="2" class="center"><h3>PARTICIPANT IDENTIFICATION</h3></td>
</tr>
<tr>
<td width="218">First</td>
<td width="456"><input name="first" type="text" maxlength="50" id="first" value="<? echo $rows['first']; ?>" /></td>
</tr>
<tr>
<td width="218">Last</td>
<td width="456"><input name="last" type="text" maxlength="50" id="last" value="<? echo $rows['last']; ?>" /></td>
</tr>
<tr>
<td width="218">Middles</td>
<td width="456"><input name="middle" type="text" maxlength="50" id="middle" value="<? echo $rows['middle']; ?>"/></td>
</tr>
<tr>
<td>Address</td>
<td><input name="address" type="text" maxlength="50" id="address" value="<? echo $rows['address']; ?>"/></td>
</tr>
<tr>
<td>City</td>
<td><input name="city" type="text" maxlength="50" id="city" value="<? echo $rows['city']; ?>"/></td>
</tr>
<tr>
<td>State</td>
<td><input name="state" type="text" maxlength="15" id="state" value="<? echo $rows['state']; ?>"/></td>
</tr>
<tr>
<td>Zip</td>
<td><input name="zip" type="text" maxlength="15" id="zip" value="<? echo $rows['zip']; ?>" /></td>
</tr>
<tr>
<td>Home Phone</td>
<td><input name="home_phone" type="text" id="home_phone" value="<? echo $rows['home_phone']; ?>" /></td>
</tr>
<tr>
<td>Daytime Phone</td>
<td><input name="daytime_phone" type="text" id="daytime_phone" value="<? echo $rows['daytime_phone']; ?>" /></td>
</tr>
<tr>
<td>Email Address</td>
<td><input name="email_address" type="text" id="email_address" value="<? echo $rows['email_address']; ?>" /></td>
</tr>
<tr>
<td>Birthday</td>
<td><input name="month" type="text" id="month" size="3" maxlength="2" value=""/> / <input name="day" type="text" id="day" size="3" maxlength="2" value=""/> / <input name="year" type="text" id="year" size="5" maxlength="4" value=""/></td>
</tr>
<tr>
<td>Social Security Number</td>
<td><input name="ss_1" type="text" id="ss_1" size="5" maxlength="3" value=""/> - <input name="ss_2" type="text" id="ss_2" size="5" maxlength="2" value=""/> - <input name="ss_3" type="text" id="ss_3" size="5" maxlength="4" value="" /></td>
</tr>
<tr>
<td colspan="2" class="center"><h3>PHOTO IDENTIFICATION </h3></td>
</tr>
<tr>
<td>Type of ID</td>
<td>
<input type="text" name="type_of_id" id="type_of_id" value=""/></td>
</tr>
<tr>
<td>ID Number</td>
<td>
<input type="text" name="id_number" id="id_number" value="" /></td>
</tr>
<tr>
<td>Issuing Jurisdiction</td>
<td><input type="text" name="issuing_state" id="issuing_state" value=""/></td>
</tr>
<tr>
<td>Expiration Date</td>
<td><input type="text" name="expiration_date" id="expiration_date" value=""/></td>
</tr>
<tr>
<td>Issue Date</td>
<td><input type="text" name="issue_date" id="issue_date" value="" /></td>
</tr>
<tr>
<td colspan="2" class="center"><h3>ESTABLISHING YOUR ACCOUNT</h3></td>
</tr>
<tr>
<td colspan="2" class="center">Designate Account Type</td>
</tr>
<tr>
<td>
Acount Type
</td>
<td>
<label>
<input type="radio" name="traditional" value="1" id="traditional" />
Traditional</label>
<br />
<label>
<input type="radio" name="roth" value="1" id="roth" />
Roth</label>
<br />
<label>
<input type="radio" name="sep" value="1" id="sep" />
SEP</label>
<br />
<label>
<input type="radio" name="simple" value="1" id="simple" />
SIMPLE</label>
<br /></td>
</tr>
<tr>
<td colspan="2" class="center">Fund Your Account</td>
</tr>
<tr>
<td colspan="2"><input name="rollover" type="radio" value="1" id="rollover" />I will rollover cash from an existing IRA or qualified retirement plan
</td>
</tr>
<tr>
<td>Prior Custodian Plan Name</td>
<td><input name="prior_plan_name" type="text" maxlength="50" id="prior_plan_name" value=""/></td>
</tr>
<tr>
<td>Expected Rollover Amount</td>
<td><input name="rollover_amount" type="text" maxlength="50" id="rollover_amount" value=""/></td>
</tr>
<tr>
<td colspan="2"><input name="transfer" type="radio" value="1" id="transfer" /> I will transfer assets from another IRA and have attached a TRANSFER AUTHORIZATION form </td>
</tr>
<tr>
<td colspan="2"><input name="contribution" type="radio" value="1" id="contribution"/> I have attached a contribution check as follows</td>
</tr>
<tr>
<td>IRA Cash Contribution for the Year</td>
<td><input name="cash_contributions_1" type="text" id="cash_contributions_1" value=""/></td>
</tr>
<tr>
<td>in the amount of</td>
<td><input name="amount_1" type="text" id="amount_1" value=""/></td>
</tr>
<tr>
<td>IRA Cash Contribution for the Year</td>
<td><input name="cash_contributions_2" type="text" id="cash_contributions_2" value="" /></td>
</tr>
<tr>
<td>in the amount of</td>
<td><input name="amount_2" type="text" id="amount_2" value="" /></td>
</tr>
<tr>
<td>Employer OR Employee (circle one) SEP/SIMPLE Contribution for the Year</td>
<td><input name="employer_contributions" type="text" id="employer_contributions" value="" /></td>
</tr>
<tr>
<td>in the amount of</td>
<td><input name="amount_3" type="text" id="amount_3" value="" /></td>
</tr>
<tr>
<td></td>
<td style="text-align:right"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</table>
<?php
// close connection
mysql_close();
?>