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 Quote Link to comment 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. Quote Link to comment 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'] Quote Link to comment 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.