Hi there. I switched to a new laptop, and installed latest Xampp. -Gone from Xampp 1.7.1 & MySQL 5.1.33 to Xampp 2.5 & MySQL 5.5.16 -PHP 5.3.8-
And now get a variety of:
"Notice: Undefined index: update in C:\xampp\htdocs\..\edit.php on line 4"
"Notice: Undefined variable: DBError in C:\xampp\htdocs\..\edit.php on line 107"
"Notice: Undefined variable: SuccMsg in C:\xampp\htdocs|..\edit.php on line 108"
alerts on many similar web site pages. There is info on how to prevent/correct that, but I can't find a why. Presumably the latest PHP is less forgiving ?
I prefer to improve my coding rather than to suppress notices.
Code is below, and helpful comments appreciated. Thanks.
/*
$id=isset($_POST['$id']) ? trim($_POST["$id"]) : ""; **to make no notice alert, need to change code to the isset or declare the vars isset-as per below !!
<?php error_reporting (E_ALL ^ E_NOTICE); ?> **or suppress notices
*/
<?php
//session_start();
include('../_dbconn/passwords.php');
if($_POST['update'])
//** if (isset($_POST['update']) )
{
//extract($_POST);// array used to extract variables and their values from an array
$id=trim($_POST['id']);
$apply=trim($_POST['apply']);
$pass=trim($_POST['pass']);
$user=trim($_POST['user']);
$comment=trim($_POST['comment']);
$con = dbconn_passwords(); //calling db connection.
$uQuery="UPDATE passwords SET id='$id', apply='$apply', pass='$pass', user='$user', comment='$comment' WHERE id = $id";
// execute the query
$rs=$con->query($uQuery);
if(!$rs)// failed executing query.. something is wrong so.. show it
{
$DBError="ERROR: failed executing query ".mysqli_error($con);
}
{
$SuccMsg="<script>alert(\"Entry has been edited Successfully\");</script>";
}
}
// display initial form with values pre-filled
if($_GET['id']) // if entry id is available from the data base
{
$id=$_GET['id'];
@$con = dbconn_passwords(); //calling db connection.
if(mysqli_errno($con))
{
$DBError="Error: Unable to connect to the database, Please contact the admin manager";
}
else // now we are connected to the database
{
$gQuery="SELECT * FROM passwords WHERE id = $id"; //
// execute the query
$rs=$con->query($gQuery);
if(!$rs)// failed executing query.. something is wrong so.. show it
{
$DBError="ERROR: failed executing query ".mysqli_error($con);
}
else
{
// read the data from the bd
$count=$rs->num_rows; // fetch object function that converts each row into a PHP object, & represents each col in that row as a property of that object
if($count>0)
{
$data=$rs->fetch_assoc();
$id=$data['id'];
$apply=$data['apply'];
$pass=$data['pass'];
$user=$data['user'];
$comment=$data['comment'];
}
else
{
echo "Record not found";
}
}
}
} //*** end of GET['id']
// form submitted
?>
<div align=center>
<form method="post" action="<? echo $PHP_SELF ?>">
<input type='hidden' name='id' value="<? echo $id ?>" />
<table width="550" style=\"font-face:Arial,sans-serif;font-weight:normal;color:#0000cc;font-size:9pt;padding-right:50px;\">
<tr>
<td colspan="2" style=\"font-face:Verdana,Arial,sans-serif;font-weight:normal;color:#006600;font-size:11pt;padding-left:70px;\"><br />Edit an Entry<br /></td>
</tr>
<tr>
<td class="label" align="right">Applicable to</td>
<td class="instruct">
<input type="text" name="apply" size="20" value="<? echo $apply ?>">
</td>
</tr>
<tr>
<td class="label" align="right">Password</td>
<td class="instruct">
<input type="text" name="pass" size="20" value="<? echo $pass ?>">
</td>
</tr>
<tr>
<td class="label" align="right">User</td>
<td class="instruct">
<input type="text" name="user" size="20" value="<? echo $user ?>">
</tr>
<tr>
<td class="label" align="right">Comment</td>
<td class="instruct">
<input type="text" name="comment" size="20" value="<? echo $comment ?>">
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="update" value="Update"> <a style='font-face:arial,verdana,sans-serif;font-weight:normal;color:#0000cc;font-size:11pt;padding-left:80px;text-decoration:none;' href="index.php">View Entries</a>
</td>
</tr>
</table>
</form></div>
<?php
// Display Error or Success Messages
echo ($DBError)?"<span class=\"error\">".$DBError."</span><br />":"";
echo ($SuccMsg);
?>