Forum Moderators: coopster
<?
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("databasename", $db);
$query = "SELECT clients.firstname, clients.lastname, clients.phone
FROM clients WHERE name LIKE '%".$name."%'";
$result = mysql_query($query);
while ($record = mysql_fetch_assoc($result)){
while (list($fieldname, $fieldvalue) = each ($record)){
echo $fieldname.": <b>".$fieldvalue."</b><br>";
}
echo "<br>";
}
?> This is the error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/cashflow/public_html/search/results.php on line 15
How can this be?
New code:
<?
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("databasename", $db);
$query = "SELECT clients.FirstName, clients.LastName, clients.Phone
FROM clients WHERE FirstName LIKE '%".$name."%'";
$result = mysql_query($query) or die (mysql_error());
while ($record = mysql_fetch_assoc($result)){
while (list($fieldname, $fieldvalue) = each ($record)){
echo $fieldname.": <b>".$fieldvalue."</b><br>";
}
echo "<br>";
}
?> NEVERMIND...it's working, it's just when it doesn't find anything matching that criteria it doesn't say it didn't find anything, probably becuase I haven't told it how to yet I would assume. One thing however, you see I have multiple things being listed about this customer, how can I tell it to search using multiple fields ( instead of just FirstName ) will it be like this?
$query = "SELECT clients.FirstName, clients.LastName, clients.Phone FROM clients WHERE FirstName, or LastName, or Phone LIKE '%".$name."%'"; [edited by: RogueDogg at 8:25 pm (utc) on May 30, 2006]
like so
$query = "SELECT clients.FirstName, clients.LastName, clients.Phone FROM clients WHERE FirstName LIKE '%".$name."%'";
echo $query;
then copy and paste that into phpmyadmin or at the commandline and see what the query returns straight from your db
<?
$link = "<br><br><a href='search.html'>Do another Search CLICK HERE</a>";
$name = trim($name);
if(!$name){
echo "No search criteria given.";
echo $link;
exit;
}
$db = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $db);
$query = "SELECT clients.FirstName, clients.LastName, clients.Phone
FROM clients WHERE FirstName LIKE '%".$name."%' OR LastName LIKE '%".$name."%' OR Phone LIKE '%".$name."%'";
$result = mysql_query($query) or die (mysql_error());
if (mysql_num_rows($result) == 0){
echo "Sorry no results found using that criteria";
echo $link;
exit;
}
while ($record = mysql_fetch_assoc($result)){
while (list($fieldname, $fieldvalue) = each ($record)){
echo $fieldname.": <b>".$fieldvalue."</b><br>";
}
echo "<br>";
}
echo $link
?> Now what this does is allows the user to search by FirstName, LastName or Phone # and it works great.
Anyone up for my next question?
How can I add this search information to an existing db *( not the db it was pulled from )*, so basically I want to add the found information to an exsisting db by the click of an "activate" button or link. Know what I mean?
you may need to use a form with all hidden values that is posted when the user submits it with the activate link/button
As for hidden inputs go, the syntax is generally: <input type='hidden' name='name' value='some value' />
To use them as arrays, which you are probably going to have to do, you specify the name with [] at the end(name='name[]')
Now to use these variables after the submit button is pressed, they are stored in the $_POST['name'] array (that is if you specify post). You can then use this as a regular array.
>>>So for the name of the hidden value it would be the $variable?
Yes, the value would be the value taken from the database.
IE FirstName = $FirstName or LastName = $LastName or PhoneNumber = $Phone because they're just $fieldvalue
while ($record = mysql_fetch_assoc($result)){
while (list($fieldname, $fieldvalue) = each ($record)){ Here is my updated script ( I have made some changes ):
<?
$link = "<br><br><a href='search.html'>Do another Search CLICK HERE</a>";
$name = trim($name);
if(!$name){
echo "No search criteria given.";
echo $link;
exit;
}
$db = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $db);
$query = "SELECT leads.First, leads.Last, leads.Address, leads.City, leads.State, leads.Zip,
leads.phone, leads.phone2, leads.email, leads.enterdate
FROM leads WHERE First LIKE '%".$name."%' OR Last LIKE '%".$name."%' OR phone LIKE '%".$name."%' ORDER BY First asc";
$result = mysql_query($query) or die (mysql_error());
if (mysql_num_rows($result) == 0){
echo "Sorry no results found using that criteria";
echo $link;
exit;
}
while ($record = mysql_fetch_assoc($result)){
while (list($fieldname, $fieldvalue) = each ($record)){
?>
<tr>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $fieldname.": <b>".$fieldvalue;?></b></font></td><br>
</tr>
<?}
echo "<br>";
}
echo $link
?>
To this:
while($row = mysql_fetch_array($result)){
$row["FirstName"] = $fname;
$row["LastName"] = $lname;
$row["Phone"] = $phone;
}
You can then use those variables anywhere in the while loop.
<?
$link = "<br><br><a href='search.html'>Do another Search CLICK HERE</a>";
$name = trim($name);
if(!$name){
echo "No search criteria given.";
echo $link;
exit;
}
$db = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $db);
$query = "SELECT leads.First, leads.Last, leads.Address, leads.City, leads.State, leads.Zip,
leads.phone, leads.phone2, leads.email, leads.enterdate
FROM leads WHERE First LIKE '%".$name."%' OR Last LIKE '%".$name."%' OR phone LIKE '%".$name."%' ORDER BY First asc";
$result = mysql_query($query) or die (mysql_error());
if (mysql_num_rows($result) == 0){
echo "Sorry no results found using that criteria";
echo $link;
exit;
}
?>
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Phone</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Phone2</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Address</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">City</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">State</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Zip</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Email</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">EnterDate</font></th>
</tr>
<?
$num=mysql_numrows($result);mysql_close();
echo "<b><center>Search Output</center></b><br><br>";
$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,"First");
$last=mysql_result($result,$i,"Last");
$phone=mysql_result($result,$i,"phone");
$phone2=mysql_result($result,$i,"phone2");
$address=mysql_result($result,$i,"Address");
$city=mysql_result($result,$i,"City");
$state=mysql_result($result,$i,"State");
$zip=mysql_result($result,$i,"Zip");
$email=mysql_result($result,$i,"Email");
$enterdate=mysql_result($result,$i,"enterdate");
?>
<tr>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $first." ".$last;?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $phone;?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $phone2;?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $address;?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $city;?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $state;?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $zip;?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><a href="mailto:<? echo $email;?>">E-mail</a></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $enterdate;?></font></td>
</tr>
<?
$i++;
}
echo "</table>";
?>
<?
echo "<br>$link<br>";
?>
I have no idea why when I put this in the "code" tags it's messing up half way through so if I doesn't display right I can send you the file insead if you like, but anyways, this is where I'm at, now I guess I need to create the form with the hidden fields? seperate form or?
$i=0;
while ($i < $num) {$first=mysql_result($result,$i,"First");
$last=mysql_result($result,$i,"Last");
$phone=mysql_result($result,$i,"phone");...........cut script to save space ;)
<?
$i++;
}
To:
while ($row=mysql_fetch_array($result)) {
?><tr>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["First"]." ".$row["Last"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["phone"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["phone2"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["Address"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["City"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["State"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["Zip"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><a href="mailto:<? echo $row["Email"];?>">E-mail</a></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["enterdate"];?></font></td>
</tr><?
}
Much nicer
Then I have a question. Why are you adding the results of this to another database? Wouldn't it be just fine to have another query that outputs the same results when it is needed? I'm just trying to figure out how to best help you is all :)
On the part where it's adding the info I designate to another database, basically what I have is a db with potential customers in it, once they become a customer istead of me filling in there customer info again, I already have it in this db and I just want to add it to my "real customers" db, because this potential customer database will be dumped weekly with people who do not become customers, what would be even better is when I "activate" them as a customer it also removes them from this current db, that would be awesome. So these are my plans, making any sense yet, hehe?
<?phpif($_POST["add_member"])
{activate();}
else
{show_users();}function activate()
{
//ADD the data of the member from the $POST variables into the NEW database}
function delete_member($email)
{
//Here you delete the new FULL member from the POTENTIAL member list based on their email address (this should be unique)}
function show_users() {
$link = "<br><br><a href='search.html'>Do another Search CLICK HERE</a>";
$name = trim($name);
if(!$name){
echo "No search criteria given.";
echo $link;
exit;
}
$db = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $db);
$name = mysql_real_escape_string($name);
$query = "SELECT First,Last,Address,City,State,Zip,phone,phone2,email,enterdate FROM leads WHERE First LIKE '%".$name."%' OR Last LIKE '%".$name."%' OR phone LIKE '%".$name."%' ORDER BY First asc";
$result = mysql_query($query) or die (mysql_error());
if (mysql_num_rows($result) == 0){
echo "Sorry no results found using that criteria";
echo $link;
exit;
}
?>
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Phone</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Phone2</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Address</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">City</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">State</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Zip</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Email</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">EnterDate</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Become a Customer!</th>
</tr>
<?
mysql_close();while ($row=mysql_fetch_array($result)) {
?><tr>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["First"]." ".$row["Last"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["phone"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["phone2"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["Address"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["City"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["State"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["Zip"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><a href="mailto:<? echo $row["Email"];?>">E-mail</a></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["enterdate"];?></font></td>
<td><form action="submit.php" method="post">
<input type="hidden" name="fname" value="<? echo $row["First"];?>" />
<input type="hidden" name="lname" value="<? echo $row["Last"];?>" />
<input type="hidden" name="email" value="<? echo $row["Email"];?>" />
<input type="hidden" name="phone" value="<? echo $row["phone"];?>" />
<input type="hidden" name="phone2" value="<? echo $row["phone2"];?>" />
<input type="hidden" name="address" value="<? echo $row["Address"];?>" />
<input type="hidden" name="city" value="<? echo $row["City"];?>" />
<input type="hidden" name="state" value="<? echo $row["State"];?>" />
<input type="hidden" name="zip" value="<? echo $row["Zip"];?>" />
<input type="hidden" name="enter_date" value="<? echo $row["enterdate"];?>" />
<input type="submit" name="add_member" value="Become a Member!" />
</form></td>
</tr><?
}
echo "</table>";
echo "<br>$link<br>";
}
Ummm...yeah...something like that....by the way this is from the top of my head, and if I can recall correctly, it was Grandpa [webmasterworld.com] that said "The top of my mind can be a dangerous place" (something like that) ;)
*EDIT* OK I see where it's getting the user data from ( the form ), how about the new db connection info?
*EDIT #2* OK I think I see what I have to do, I have to take the $_POST info from the form and create the submit.php script adding that data to the database....correct? HEHE I think I'm getting it now...I HOPE
<form method="post" action="<? echo $_SERVER['PHP_SELF'];?>">
function activate()
{
$link = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $link);
$_POST = array_map("mysql_real_escape_string",$_POST);$query = "INSERT INTO full_members VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[email]', '$_POST[phone]', '$_POST[phone2]', '$_POST[address]', '$_POST[city]', '$_POST[state]', '$_POST[zip]', '$_POST[enter_date]')";
$result = mysql_query($query,$link);
mysql_close($link);
if($result){ echo "Added successfully!"; }
else { echo "Added unsuccessfully :("; }
delete_member($_POST["email"]);
echo "Thank you for becoming a FULL Member!";
}function delete_member($email)
{
$link = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $link);
$query = "DELETE FROM leads WHERE email like \"".mysql_real_escape_string($email)."\"";
if(mysql_query($query,$link))
{ echo "Delete Successful!"; }
else { echo "Delete error!"; }
mysql_close($link);}
[edited by: jatar_k at 4:08 am (utc) on May 31, 2006]
[edit reason] fixed sidescroll [/edit]
<?php
error_reporting(E_ALL);
if($_POST["add_member"])
{activate();}
else
{show_users();}function activate()
{
$link = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $link);
$_POST = array_map("mysql_real_escape_string",$_POST);$query = "INSERT INTO full_members VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[email]', '$_POST[phone]', '$_POST[phone2]', '$_POST[address]', '$_POST[city]', '$_POST[state]', '$_POST[zip]', '$_POST[enter_date]')";
$result = mysql_query($query,$link) or die("ADD query not working<br>".mysql_error());
mysql_close($link);
if($result){ echo "Added successfully!"; }
else { echo "Added unsuccessfully"; }
delete_member($_POST["email"]);
echo "Thank you for becoming a FULL Member!";
}function delete_member($email)
{
$link = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $link);
$query = "DELETE FROM leads WHERE email like \"".mysql_real_escape_string($email)."\"";
$result=mysql_query($query,$link) or die("DELETE query not working<br>".mysql_error());
mysql_close($link);
if($result)
{ echo "Delete Successful!"; }
else { echo "Delete error!"; }}
function show_users() {
$link = "<br><br><a href='search.html'>Do another Search CLICK HERE</a>";
$name = trim($name);
if(!$name){
echo "No search criteria given.";
echo $link;
exit;
}
$db = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $db);
$name = mysql_real_escape_string($name);
$query = "SELECT First,Last,Address,City,State,Zip,phone,phone2,email,enterdate FROM leads WHERE First LIKE '%".$name."%' OR Last LIKE '%".$name."%' OR phone LIKE '%".$name."%' ORDER BY First asc";
$result = mysql_query($query) or die (mysql_error());
if (mysql_num_rows($result) == 0){
echo "Sorry no results found using that criteria";
echo $link;
exit;
}
?>
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Phone</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Phone2</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Address</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">City</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">State</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Zip</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Email</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">EnterDate</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Become a Customer!</th>
</tr>
<?
mysql_close();while ($row=mysql_fetch_array($result)) {
?><tr>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["First"]." ".$row["Last"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["phone"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["phone2"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["Address"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["City"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["State"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["Zip"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><a href="mailto:<? echo $row["Email"];?>">E-mail</a></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["enterdate"];?></font></td>
<td><form action="<? echo $_SERVER['PHP_SELF'];?>" method="post">
<input type="hidden" name="fname" value="<? echo $row["First"];?>" />
<input type="hidden" name="lname" value="<? echo $row["Last"];?>" />
<input type="hidden" name="email" value="<? echo $row["Email"];?>" />
<input type="hidden" name="phone" value="<? echo $row["phone"];?>" />
<input type="hidden" name="phone2" value="<? echo $row["phone2"];?>" />
<input type="hidden" name="address" value="<? echo $row["Address"];?>" />
<input type="hidden" name="city" value="<? echo $row["City"];?>" />
<input type="hidden" name="state" value="<? echo $row["State"];?>" />
<input type="hidden" name="zip" value="<? echo $row["Zip"];?>" />
<input type="hidden" name="enter_date" value="<? echo $row["enterdate"];?>" />
<input type="submit" name="add_member" value="Become a Member!" />
</form></td>
</tr><?
}
echo "</table>";
echo "<br>$link<br>";
}
?>
Again, you might have to play around wiht this to get it working. Also, reply with any error messages you may be getting with this script.
[edited by: jatar_k at 4:07 am (utc) on May 31, 2006]
[edit reason] fixed sidescroll [/edit]
Notice: Undefined index: add_member in /home/cfdshopp/public_html/search/submit.php on line 11
Notice: Undefined variable: name in /home/cfdshopp/public_html/search/submit.php on line 45
No search criteria given
It's like it doesn't understand the add_member function ( which how could it, I haven't clicked on the activate button yet )
and the 2nd error is puzzling as well cause it's asking for an undefined variable, which is defined just later in the script...Are things backwards here?
I only want to "activate or add the member and delete the member from the old db" after I click on the button, I don't want it to do it automatically based on the search criteria from search.html.....know what I mean?
Change the top to this:
if(isset($_POST["add_member"]))
{activate();}
else
{show_users();}
Thats for the second notice, and for the first, change the following:
$name = trim($name);
if(!$name){
echo "No search criteria given.";
echo $link;
exit;
}
Change this to:
if(isset($name)) {
$name = trim($name);
}
else {
echo "No search criteria given.";
echo $link;
exit;
}
Other than these errors, does the script actually work? Also, if $name if coming from search.html, make sure that you add this to the to of the script (if $name is coming from a post form):
$name = $_POST["name"];
Good luck!
<html>
<head>
<title>User Search Page</title>
</head><body>
<H2>Search for a Lead</H2>
<br>
<form action="results.php" method="post" enctype="multipart/form-data" name="Search">
Please enter a search criteria:<br>
<br>
<input name="name" type=text> <font size="-2" color="#3366CC">This can be FisrtName, LastName or Phone#</font>
<br>
<br>
<input type="submit" value="Search">
</form>
</body>
</html>
Here is what I am using for results.php that search.html is calling out:
<?php
$name = $_POST["name"];
error_reporting(E_ALL);
if(isset($_POST["add_member"])
{activate();}
else
{show_users();}
function activate()
{
$link = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $link);
$_POST = array_map("mysql_real_escape_string",$_POST); $query = "INSERT INTO full_members VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[email]', '$_POST[phone]', '$_POST[phone2]', '$_POST[address]', '$_POST[city]', '$_POST[state]', '$_POST[zip]', '$_POST[enter_date]')";
$result = mysql_query($query,$link) or die("ADD query not working<br>".mysql_error());
mysql_close($link);
if($result){ echo "Added successfully!"; }
else { echo "Added unsuccessfully"; }
delete_member($_POST["email"]);
echo "Thank you for becoming a FULL Member!";
}
function delete_member($email)
{
$link = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $link);
$query = "DELETE FROM leads WHERE email like \"".mysql_real_escape_string($email)."\"";
$result=mysql_query($query,$link) or die("DELETE query not working<br>".mysql_error());
mysql_close($link);
if($result)
{ echo "Delete Successful!"; }
else { echo "Delete error!"; }
}
function show_users() {
$link = "<br><br><a href='search.html'>Do another Search CLICK HERE</a>";
if(isset($name)){
$name = trim($name);
}
else{
echo "No search criteria given.";
echo $link;
exit;
}
$db = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $db);
$name = mysql_real_escape_string($name);
$query = "SELECT First,Last,Address,City,State,Zip,phone,phone2,email,enterdate FROM leads WHERE First LIKE '%".$name."%' OR Last LIKE '%".$name."%' OR phone LIKE '%".$name."%' ORDER BY First asc";
$result = mysql_query($query) or die (mysql_error());
if (mysql_num_rows($result) == 0){
echo "Sorry no results found using that criteria";
echo $link;
exit;
}
?>
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Phone</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Phone2</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Address</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">City</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">State</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Zip</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Email</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">EnterDate</font></th>
<th><font face="Arial, Helvetica, sans-serif" color="#0000FF">Become a Customer!</th>
</tr>
<?
mysql_close();
while ($row=mysql_fetch_array($result)) {
?>
<tr>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["First"]." ".$row["Last"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["phone"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["phone2"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["Address"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["City"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["State"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["Zip"];?></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><a href="mailto:<? echo $row["Email"];?>">E-mail</a></font></td>
<td><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $row["enterdate"];?></font></td>
<td><form action="<? echo $_SERVER['PHP_SELF'];?>" method="post">
<input type="hidden" name="fname" value="<? echo $row["First"];?>" />
<input type="hidden" name="lname" value="<? echo $row["Last"];?>" />
<input type="hidden" name="email" value="<? echo $row["Email"];?>" />
<input type="hidden" name="phone" value="<? echo $row["phone"];?>" />
<input type="hidden" name="phone2" value="<? echo $row["phone2"];?>" />
<input type="hidden" name="address" value="<? echo $row["Address"];?>" />
<input type="hidden" name="city" value="<? echo $row["City"];?>" />
<input type="hidden" name="state" value="<? echo $row["State"];?>" />
<input type="hidden" name="zip" value="<? echo $row["Zip"];?>" />
<input type="hidden" name="enter_date" value="<? echo $row["enterdate"];?>" />
<input type="submit" name="add_member" value="Become a Member!" />
</form></td>
</tr>
<?
}
echo "</table>";
echo "<br>$link<br>";
}
?>
This is the error which I have tried removing the { } and get a bad function error:
Parse error: syntax error, unexpected '{' in /home/cfdshopp/public_html/search/submit.php on line 13
[edited by: jatar_k at 4:06 am (utc) on May 31, 2006]
[edit reason] fixed sidescroll [/edit]
if(isset($_POST["add_member"]))
{activate();}
else
{show_users();}
No search criteria given.
Do another Search CLICK HERE
So it's not reading the variable from the search.html form right? I thought I declared that at the top of the script so...hmmmmm
If I add echo "$name"; to the top of my script it outputs this:
GEORGENo search criteria given.
Do another Search CLICK HERE
GEORGE being the name I typed in the search.html text box...SO...it is passing the variable name on to the results.php script but for some reason it's not declaring it or something..right?
[edited by: RogueDogg at 3:06 am (utc) on May 31, 2006]
{show_users();}
$name = $_POST["name"]; *EDIT* Ok I added it to
function show_users() {
$name = $_POST["name"]; and that fixed that issue, now when I click on "become a member" button this is what I get: Added successfully!Delete Successful!Thank you for becoming a FULL Member!
Notice: Undefined index: name in /home/cfdshopp/public_html/search/submit.php on line 16
[edited by: RogueDogg at 3:12 am (utc) on May 31, 2006]
I'm not even sure if this is going to fix it; it should have worked the other way. Just make sure that you are actually getting the $_POST["name"] variable by echoing it at the beginning of the script. Add echo $_POST["name"]; at the top of the script. I really need to get to doing my work and then get to sleep. I'm sure there will be many more people willing to help you while I'm gone. I'll check in the morning to see if you got it. Good luck!