Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.