Parkie02 Posted December 9, 2013 Share Posted December 9, 2013 Can someone maybe help me. I am new to php mysql and I am trying to create a search form where a user type in a name and the record of that name is displayed. Here is the error I get: Undefined variable: cname in C:\wamp\www\whodidntpay\search.php on line 32. Here is my code: <html> <head>Search</title> </head> <p> Company Name: <input type=text name=cname size=50 maxlength=50> <p> <input type=submit> <body> <table width="600" border="1" cellpadding="1" cellspacing="1"> <tr> <th>Company Name</th> <th>Reg</th> <th>Email</th> <th>Per</th> <th>Num</th> <th>NotPaid</th> <th>Amount</th> <tr> <?php mysql_connect('localhost', 'root', ''); mysql_select_db('whodidntpay'); // if ($cname == "") //{$cname = '%';} $sql="SELECT * FROM debtor WHERE cname LIKE '$cname%'"; $records=mysql_query($sql); ?> while ($debtor=mysql_fetch_assoc($records)) { echo "<tr>"; echo "<td>".$debtor['d_name']."</td>"; echo "<td>".$debtor['registration_nr']."</td>"; echo "<td>".$debtor['email']."</td>"; echo "<td>".$debtor['contact_person']."</td>"; echo "<td>".$debtor['contact_number']."</td>"; echo "<td>".$debtor['companies_not_paid']."</td>"; echo "<td>".$debtor['amount_not_paid']."</td>"; } </html> Thank you Link to comment https://forums.phpfreaks.com/topic/284646-search-form/ Share on other sites More sharing options...
MDCode Posted December 9, 2013 Share Posted December 9, 2013 You haven't defined $cname anywhere before using it. Link to comment https://forums.phpfreaks.com/topic/284646-search-form/#findComment-1461774 Share on other sites More sharing options...
Ch0cu3r Posted December 9, 2013 Share Posted December 9, 2013 For this to work Company Name: <input type=text name=cname size=50 maxlength=50> <p> <input type=submit> You need to wrap it within a <form> tag <form action="" method="post"> Company Name: <input type=text name=cname size=50 maxlength=50> <p> <input type=submit> </form> You then get the value from the Company Name text field using $_POST['cname'] Link to comment https://forums.phpfreaks.com/topic/284646-search-form/#findComment-1461776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.