PHP Editing error
Posted: Sun Mar 11, 2012 3:19 am
i have created 2 editing files whose code are as follows:
This is code for modify.php:
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="db_event"; // Database name
$tbl_name="event1"; // Table name
// 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");
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE `eid`='$_REQUEST[eid]' ";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="modify_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td> </td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr><td> </td></tr>
<tr>
<td ><strong>Eventname</strong></td>
<td><input name="name" type="text" id="name" value="<?php echo $rows['ename']; ?>" size="25"></td>
</tr>
<tr>
<td ><strong>Venue</strong></td>
<td><input name="lastname" type="text" id="lastname" value="<?php echo $rows['venue']; ?>" size="25"></td>
</tr>
<tr>
<td ><strong>City</strong></td>
<td><input name="city" type="text" value="<?php echo $rows['city']; ?>" size="25"></td>
</tr>
<tr>
<td ><strong>Timings</strong></td>
<td><input name="timings" type="text" value="<?php echo $rows['timings']; ?>" size="25"></td>
</tr>
<tr>
<td ><strong>Event date</strong></td>
<td><input name="edate" type="text" value="<?php echo $rows['edate']; ?>" size="25"></td>
</tr>
<tr>
<td ><strong>Describe</strong></td>
<td><input name="describe" type="text" value="<?php echo $rows['describe']; ?>" size="100" ></td>
</tr>
<tr>
<td ><strong>Created date</strong></td>
<td><input name="cdate" type="text" value="<?php echo $rows['cdate']; ?>" size="25"></td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" id="id" value="<? echo $rows['eid']; ?>"></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?
// close connection
mysql_close();
?>
And on editing in form as i submit it it to modify_acc.php whose code is as:
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="db_event"; // Database name
$tbl_name="event1"; // Table name
// 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");
// update data in mysql database
$sql="UPDATE $tbl_name SET ename='$_REQUEST[ename]' , venue='$_REQUEST[venue]' , city='$_REQUEST[city]' , timings='$_REQUEST[timings]' , edate='$_REQUEST[edate]' , describe='$_REQUEST[describe]' , cdate='$_REQUEST[cdate]' WHERE eid='$_REQUEST[eid]' ";
$result=mysql_query($sql);
// if successfully updated.
if($result)
{
echo "Successful";
echo "<BR>";
echo "<a href='display.php'>View result</a>";
}
else {
echo "ERROR";
}
?>
As i submit it, it shows an error as
Undefined index:ename
Undefined index:venue
Undefined index:eid
in modify_ac.php in line 13
This is code for modify.php:
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="db_event"; // Database name
$tbl_name="event1"; // Table name
// 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");
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE `eid`='$_REQUEST[eid]' ";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="modify_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td> </td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr><td> </td></tr>
<tr>
<td ><strong>Eventname</strong></td>
<td><input name="name" type="text" id="name" value="<?php echo $rows['ename']; ?>" size="25"></td>
</tr>
<tr>
<td ><strong>Venue</strong></td>
<td><input name="lastname" type="text" id="lastname" value="<?php echo $rows['venue']; ?>" size="25"></td>
</tr>
<tr>
<td ><strong>City</strong></td>
<td><input name="city" type="text" value="<?php echo $rows['city']; ?>" size="25"></td>
</tr>
<tr>
<td ><strong>Timings</strong></td>
<td><input name="timings" type="text" value="<?php echo $rows['timings']; ?>" size="25"></td>
</tr>
<tr>
<td ><strong>Event date</strong></td>
<td><input name="edate" type="text" value="<?php echo $rows['edate']; ?>" size="25"></td>
</tr>
<tr>
<td ><strong>Describe</strong></td>
<td><input name="describe" type="text" value="<?php echo $rows['describe']; ?>" size="100" ></td>
</tr>
<tr>
<td ><strong>Created date</strong></td>
<td><input name="cdate" type="text" value="<?php echo $rows['cdate']; ?>" size="25"></td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" id="id" value="<? echo $rows['eid']; ?>"></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?
// close connection
mysql_close();
?>
And on editing in form as i submit it it to modify_acc.php whose code is as:
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="db_event"; // Database name
$tbl_name="event1"; // Table name
// 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");
// update data in mysql database
$sql="UPDATE $tbl_name SET ename='$_REQUEST[ename]' , venue='$_REQUEST[venue]' , city='$_REQUEST[city]' , timings='$_REQUEST[timings]' , edate='$_REQUEST[edate]' , describe='$_REQUEST[describe]' , cdate='$_REQUEST[cdate]' WHERE eid='$_REQUEST[eid]' ";
$result=mysql_query($sql);
// if successfully updated.
if($result)
{
echo "Successful";
echo "<BR>";
echo "<a href='display.php'>View result</a>";
}
else {
echo "ERROR";
}
?>
As i submit it, it shows an error as
Undefined index:ename
Undefined index:venue
Undefined index:eid
in modify_ac.php in line 13