PHP Editing error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
soni.nishant7
Forum Newbie
Posts: 1
Joined: Sun Mar 11, 2012 3:13 am

PHP Editing error

Post by soni.nishant7 »

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>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>

<tr><td>&nbsp;</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>&nbsp;</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>&nbsp;</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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Editing error

Post by requinix »

Compare the fields you put in the form with what you're trying to get from $_REQUEST.
whiterainbow
Forum Newbie
Posts: 11
Joined: Fri Mar 18, 2011 9:13 am

Re: PHP Editing error

Post by whiterainbow »

Depending on how your php is configured, $_REQUEST might not work as you expect. Try $_POST, and also put a basic check in the code to see if $_POST['ename'] (just for example) is set
Post Reply