Jump to content

Notice: Undefined variable: txtstudentid in C:\xampp\htdocs\search.php on line 9


Marlon06

Recommended Posts

<?php

// Create connection

$txtstudentid;

 

$con=mysql_connect("localhost:3306","root","") or die( mysql_error());

 

if(!mysql_select_db("db1", $con));

 

$result=mysql_query("SELECT * FROM tblstudent where studentid='". $_txtstudentid ."'");

 

echo "<table border=1>

<tr>

<td colspan=3 align=center> Student Records </td>

</tr>

<tr>

<td> Student ID </td>

<td> Firstname </td>

<td> Lastname </td>

</td>

";

while($row=mysql_fetch_array($result))

{

$studnum=$row['studentid'];

$fname=$row['firstname'];

$lname=$row['lastname'];

 

echo "<tr>

<td> $studnum </td>

<td> $fname </td>

<td> $lname </td>

</tr>";

}

echo "</table>";

 

?>

Like this?

 

<?php
// Create connection
 
$con=mysql_connect("localhost:3306","root","") or die( mysql_error());
 
if(!mysql_select_db("db1", $con));
 
$result=mysql_query("SELECT * FROM tblstudent where studentid='" . $txtstudentid . "'");
 
echo "<table border=1>
<tr>
<td colspan=3 align=center> Student Records </td>
</tr>
<tr>
<td> Student ID </td>
<td> Firstname </td>
<td> Lastname </td>
</td>
";
while($row=mysql_fetch_array($result))
{
$studnum=$row['studentid'];
$fname=$row['firstname'];
$lname=$row['lastname'];
 
echo "<tr>
<td> $studnum </td>
<td> $fname </td>
<td> $lname </td>
</tr>";
}
echo "</table>";
 
?>
 
Still Error

Where is $txtstudentid defined / coming from? You need be defining variables before you can use them.

 

Is $txtstudentid from the url? like site.com/student.php?txtstudentid=345 . If that is the case then you use the  $_GET['txtstudentid] superglobal variable to get the student id.

 

If it is from a form that is submitted with POST method, then you use $_POST['txtstudentid'] superglobal variable.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.