Jump to content

Search form


Parkie02

Recommended Posts

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
Share on other sites

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
Share on other sites

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.