Marlon06 Posted October 22, 2013 Share Posted October 22, 2013 <?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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/283178-notice-undefined-variable-txtstudentid-in-cxampphtdocssearchphp-on-line-9/ Share on other sites More sharing options...
PravinS Posted October 22, 2013 Share Posted October 22, 2013 you have used underscore (_) in variable ($_txtstudentid) of SQL query and at top you have not used underscore Quote Link to comment https://forums.phpfreaks.com/topic/283178-notice-undefined-variable-txtstudentid-in-cxampphtdocssearchphp-on-line-9/#findComment-1454888 Share on other sites More sharing options...
Ch0cu3r Posted October 22, 2013 Share Posted October 22, 2013 You have also not defined a value for $txtstudentid <?php // Create connection $txtstudentid; Quote Link to comment https://forums.phpfreaks.com/topic/283178-notice-undefined-variable-txtstudentid-in-cxampphtdocssearchphp-on-line-9/#findComment-1454890 Share on other sites More sharing options...
Marlon06 Posted October 22, 2013 Author Share Posted October 22, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/283178-notice-undefined-variable-txtstudentid-in-cxampphtdocssearchphp-on-line-9/#findComment-1454893 Share on other sites More sharing options...
Ch0cu3r Posted October 22, 2013 Share Posted October 22, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/283178-notice-undefined-variable-txtstudentid-in-cxampphtdocssearchphp-on-line-9/#findComment-1454895 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.