Home > Blockchain >  How do I define 'id'
How do I define 'id'

Time:05-30

Before anyone judges my coding, just know that I'm still learning the basics.

I'm facing an issue within my page which states as such:

Warning: Undefined array key "id" in C:\xampp\htdocs\Project\POLIMAS Treatment Center\POLIMAS Treatment Center\ma\write-report.php on line 11

a screenshot of the error

a screenshot of the error

I want to know how to solve this issue, now to make my question more understandable I will include the coding, I know it's most likely not secure, I need to finish my project by tomorrow, so I just want to solve this issue.

I have two pages, one which will direct towards this form, and another, that displays this form.

For the page that will direct the users towards the form, the coding is as follows:

    <?php
require('database.php');
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Appointments</title>
    <link rel="stylesheet" href="../css/dashboard.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
    
<style>
<!--.btn{
  background-color: red;
  border: none;
  color: white;
  padding: 2px 2px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 40px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 20px;
}-->
        
#appointment {
  font-family: Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

#appointment td, #appointment th {
  border: 1px solid #7e7f81;
  padding: 8px;
}

#appointment tr:nth-child(even){background-color: #8399bb;}

#appointment tr:hover {background-color: #7e7f81;}

#appointment th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  background-color: #69649b;
  color: white;
}
</style>

<body>

<div >
  <div >
    <img src="../images/POLIMAS Treatment Center.png" width="50%" height="100%" alt=""/></div>
  <div >
    <nav>
            <ul>
                <?php
                    $count=1;
                    $sel_query="Select * from ma";
                    $naem = mysqli_query($link,$sel_query);
                    while($row = mysqli_fetch_assoc($naem)){
                ?>
                <li><a href="home-ma.php" >
                    <img src="../images/grid-img6.png" alt="logo">
                    <span ><?php echo $row["maName"]; ?></span>
                </a></li>
                    <?php }?>
                <li><a href="ma-appoiment.php">
                    <i ></i>
                    <span >View Appoiment</span>
                </a></li>
                
                <li><a href="ma-report.php">
                    <i ></i>
                    <span >Report</span>
                </a></li>
                <li><a href="../index.html" >
                    <i ></i>
                    <span >Logout</span>
                </a></li>
            
            </ul>
            
        </nav>
    </div>
  <div >
    <center>
    <!-- TABLE TOP ROW HEADINGS-->
    <h1>Student Appointment</h1>

    <table id="appointment" style="width:100%">
    <tr>
        <th>Appointment ID</th>
        <th>Matrics Number</th>
        <th>Appointment Status</th>
        <th>Report</th>
        <th>Delete</th>
    </tr>
    
    <?php
    $count=1;
    $sel_query="Select * from appointment";
    $result = mysqli_query($link,$sel_query);
    while($row = mysqli_fetch_assoc($result)){
    ?>
  
    <tr>          
    <td align="center">
      <?php echo $row["appID"]; ?></td>
      
    <td align="center">
      <?php echo $row["matricsNo"]; ?></td>
      
    <td align="center"><?php if($row['appDecline']=="1") 
            
            echo "Approved";
                
        else if($row['appDecline']=="2")
                
            echo "Dissaproved";
            
        else
            
            echo "Pending"
        ?>
    </td>
    <td align="center"><a href="write-report.php?id=<?php echo $row['appID']?>"><i ></i>Write Report</a></td>
    <td align="center"><a href="delete.php?id=<?php echo $row['appID']?>"
            onclick="return confirm('Are you sure to delete this record?')"><i ></i> Remove</a></td>
    </tr><?php } ?>
    </table>
    </center>
</div>
  <div >Content for  class "footer" Goes Here</div>
    
    </div>
    
</body>
</html>

The error states that my 'id' was not defined, however in line 130, I am pretty sure I already stated it <a href="write-report.php?id=<?php echo $row['appID']?>"></a></td>

For the page which display the form, the coding is as follows:

    <?php
ini_set('display_errors', 1); 
ini_set('log_errors',1); 
error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

require ('../database.php');

if($link){
    $sql = mysqli_query($link, "SELECT * 
                                FROM appointment 
                                WHERE appID = '" . $_REQUEST['id'] . "'");
    $row = mysqli_fetch_array($sql);
}
else{
    die("Error: Could not CONNECT." . mysqli_error($link));
}

if(isset($_POST['update'])){
    $update = mysqli_query($link, "UPDATE appointment
                                    SET studMeds = '" . $_REQUEST['studMeds'] ."', 
                                    maNotes = '" . $_REQUEST['maNotes'] . "'
                                    WHERE appID = '" . $_REQUEST['id'] . "'");
    header("Location: write-report.php");
}

mysqli_close($link);
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Report</title>
    <link rel="stylesheet" href="../css/dashboard.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>

<style type="text/css">
.form-style-5{
    max-width: 500px;
    padding: 10px 20px;
    background: #f4f7f8;
    margin: 10px auto;
    padding: 20px;
    background: #f4f7f8;
    border-radius: 8px;
    font-family: Georgia, "Times New Roman", Times, serif;
}
.form-style-5 fieldset{
    border: none;
}
.form-style-5 legend {
    font-size: 1.4em;
    margin-bottom: 10px;
}
.form-style-5 label {
    display: block;
    margin-bottom: 8px;
}
.form-style-5 input[type="text"],
.form-style-5 input[type="date"],
.form-style-5 input[type="datetime"],
.form-style-5 input[type="email"],
.form-style-5 input[type="number"],
.form-style-5 input[type="search"],
.form-style-5 input[type="time"],
.form-style-5 input[type="url"],
.form-style-5 textarea,
.form-style-5 select {
    font-family: Georgia, "Times New Roman", Times, serif;
    background: rgba(255,255,255,.1);
    border: none;
    border-radius: 4px;
    font-size: 15px;
    margin: 0;
    outline: 0;
    padding: 10px;
    width: 100%;
    box-sizing: border-box; 
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box; 
    background-color: #e8eeef;
    color:#8a97a0;
    -webkit-box-shadow: 0 1px 0 rgba(0,0,0,0.03) inset;
    box-shadow: 0 1px 0 rgba(0,0,0,0.03) inset;
    margin-bottom: 30px;
}
.form-style-5 input[type="text"]:focus,
.form-style-5 input[type="date"]:focus,
.form-style-5 input[type="datetime"]:focus,
.form-style-5 input[type="email"]:focus,
.form-style-5 input[type="number"]:focus,
.form-style-5 input[type="search"]:focus,
.form-style-5 input[type="time"]:focus,
.form-style-5 input[type="url"]:focus,
.form-style-5 textarea:focus,
.form-style-5 select:focus{
    background: #d2d9dd;
}
.form-style-5 select{
    -webkit-appearance: menulist-button;
    height:35px;
}
.form-style-5 .number {
    background: #353185;
    color: #fff;
    height: 30px;
    width: 30px;
    display: inline-block;
    font-size: 0.8em;
    margin-right: 4px;
    line-height: 30px;
    text-align: center;
    text-shadow: 0 1px 0 rgba(255,255,255,0.2);
    border-radius: 15px 15px 15px 0px;
}

.form-style-5 input[type="submit"],
.form-style-5 input[type="button"]
{
    position: relative;
    display: block;
    padding: 19px 39px 18px 39px;
    color: #FFF;
    margin: 0 auto;
    background: #353185;
    font-size: 18px;
    text-align: center;
    font-style: normal;
    width: 100%;
    border: 1px solid #16a085;
    border-width: 1px 1px 3px;
    margin-bottom: 10px;
}
.form-style-5 input[type="submit"]:hover,
.form-style-5 input[type="button"]:hover
{
    background: #2a2769;
}
</style>

<div >
  <div >
    <img src="../images/POLIMAS Treatment Center.png" width="50%" height="100%" alt=""/></div>
  <div >
    <nav>
            <ul>
                <li><a href="home-ma.php" >
                    <img src="../images/grid-img6.png" alt="logo">
                    <span >Medical Assistant</span>
                </a></li>
                <li><a href="ma-appoiment.php">
                    <i ></i>
                    <span >View Appoiment</span>
                </a></li>
                
                <li><a href="ma-report.php">
                    <i ></i>
                    <span >Report</span>
                </a></li>
                <li><a href="../index.html" >
                    <i ></i>
                    <span >Logout</span>
                </a></li>
            
            </ul>
            
        </nav>
    </div>
<div >
<form action="" method="POST">
<fieldset>
<legend>Student Appointment Report</legend>
<input type="hidden" name="new" value="1" />
<input type="text" name="appID" size="6" value="<?php echo $row['appID'];?>" disabled>
<input type="text" name="matricsNo" size="6" value="<?php echo $row['matricsNo'];?>" disabled>
<input type="text" name="appTime" size="6" value="<?php echo $row['appTime'];?>" disabled>
<input type="text" name="appStatus" size="6" value="<?php echo $row['appStatus'];?>" disabled> 
<input type="text" name="studMeds" size="6" placeholder="Medication Used">  
</fieldset>
<input type="submit" name="update" value="Complete Report" />
</form>
</div>
  <div >Content for  class "footer" Goes Here</div>
  
    
    </div>
    
</body>
</html>

The error which lies on the 11th line is this:

$sql = mysqli_query($link, "SELECT * 
                            FROM appointment 
                            WHERE appID = '" . $_REQUEST['id'] . "'");

Why is my 'id' key undefined? I thought that I declared it on the previous page with <a href="write-report.php?id=<?php echo $row['appID']?>"></a></td>. My other pages face no error such as this one, and they're identical as well. Please, help me solve this issue, I'm pretty sure I made the question very clear.

CodePudding user response:

try this :

$var = $_REQUEST['id'];
mysqli_query($link, "SELECT * FROM appointment WHERE appID='$var'";

I get this error every time when i try to make sql request with the "raw" super variable.

I hope its work !

CodePudding user response:

  1. satırda yer alan hata şudur:

$sql = mysqli_query($link, "SELECT * FROM appointment WHERE appID = '" . $_REQUEST['id'] . "'");

eğer id değerini get ile gönderdi iseniz;

<?php 
$id=(int)$_GET['id'];
$sql = mysqli_query($link, "SELECT * 
                            FROM appointment 
                            WHERE appID = {$id}");

şeklinde denermisiniz

  • Related