Forum Moderators: coopster

Message Too Old, No Replies

search script issue

         

RogueDogg

8:04 pm on May 30, 2006 (gmt 0)

10+ Year Member



<?
$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?

jatar_k

8:07 pm on May 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



your query is dying, try changing this line

$result = mysql_query($query);

to this

$result = mysql_query($query) or die (mysql_error());

to get the actual error coming from mysql

eelixduppy

8:07 pm on May 30, 2006 (gmt 0)



You have an error in your query. I would first start by checking the value of $name to make sure that it isn't creating any errors.

RogueDogg

8:19 pm on May 30, 2006 (gmt 0)

10+ Year Member



Ok I made those changes and found out that name in my where claus was an issue, so I changed it to FirstName like in my db. Now it's just showing blank as my result. Meaning there are no errors now it's just not showing any results. I first did an echo from my search.html form to make sure that the variable was being passed to the results.php form and it was. So I shouldn't be running into that issue am I?

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]

jatar_k

8:25 pm on May 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



another thing you can do is echo the query to make sure it is properly constructed

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

RogueDogg

9:30 pm on May 30, 2006 (gmt 0)

10+ Year Member



Ok I got a few things added and sorted out, so here is what I came up with:

<?
$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?

jatar_k

9:41 pm on May 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



when you click activate then take the selected info and insert it into the new db

you may need to use a form with all hidden values that is posted when the user submits it with the activate link/button

RogueDogg

9:49 pm on May 30, 2006 (gmt 0)

10+ Year Member



I kinda know what you mean, I've never built a form with hidden values but it makes sense that instead of displaying the values you want to hide them but again not very clear on that. So for the name of the hidden value it would be the $variable? Maybe an example if you have one handy? :0) thx

eelixduppy

10:14 pm on May 30, 2006 (gmt 0)




you may need to use a form with all hidden values that is posted when the user submits it with the activate link/button

Wouldn't it be easier to just have the hidden values for the search criteria, and then when the user pushes the button, it runs another query for that criteria and then adds the info to the database?....just a thought....

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.

RogueDogg

10:30 pm on May 30, 2006 (gmt 0)

10+ Year Member



This won't actually work with my present script though right? Because I'm not giving each output value a variable name:

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
?>

eelixduppy

10:37 pm on May 30, 2006 (gmt 0)



To get the actual value for each field and set it to its own variable, you can change this:
while ($record = mysql_fetch_assoc($result)){
while (list($fieldname, $fieldvalue) = each ($record)){

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.

RogueDogg

11:36 pm on May 30, 2006 (gmt 0)

10+ Year Member



Ok since I have been messing with searching a db and displaying results from a db with several different methods this is what I've come up with that seems to be putting me on the right path to being able to create the "activate" button I want to make and give me the variable names I can use in a form with hidden fields? Sound about right?

<?
$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?

eelixduppy

11:59 pm on May 30, 2006 (gmt 0)



I would first start by condensing the following:

$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 :)

RogueDogg

12:10 am on May 31, 2006 (gmt 0)

10+ Year Member



You lost me on your cleaning up my script...I'm not exactly sure what you mean.

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?

RogueDogg

12:17 am on May 31, 2006 (gmt 0)

10+ Year Member



Is this a start to my form for my "activate" button.

<form action="activate.php" method="post" enctype="multipart/form-data" name="activate">
<input name="first" type="hidden" value="$First">
<input name="last" type="hidden" value="$Last">
<br>
<input type="submit" value="Activate">
</form>

eelixduppy

12:46 am on May 31, 2006 (gmt 0)



Ok I understand. Let me see if I can make the whole script for you. If not, get you moving along with making your own ;)

<?php

if($_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) ;)

RogueDogg

12:57 am on May 31, 2006 (gmt 0)

10+ Year Member



ok looking good...now my next question is, is it calling out another php file for the "new database" connection info or should I add that info into this script you created for me, and is it taking all the fields I have searched for and adding them to the new db or do I have to specify them elsewhere? I really appreciate your helping me, as you can tell i'm a noob trying to learn a lot in a short amount of time. And thx to you it's coming along nicely

*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

eelixduppy

1:05 am on May 31, 2006 (gmt 0)



Well I made everything take place with the same script. You have to change the form's action to the name of the script, or you can use $_SERVER['PHP_SELF'] as the action. I just used submit.php as an example.

<form method="post" action="<? echo $_SERVER['PHP_SELF'];?>">

eelixduppy

1:17 am on May 31, 2006 (gmt 0)



The functions should then be something like this:

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);

}


Again, off the top of my head...hope it works though. And I know there are other ways of accomplishing this, i just can't think too much right now ;)

[edited by: jatar_k at 4:08 am (utc) on May 31, 2006]
[edit reason] fixed sidescroll [/edit]

RogueDogg

1:34 am on May 31, 2006 (gmt 0)

10+ Year Member



I don't know if it's me or what but now I'm all screwed up....nothing seems to be working at all. argh...

eelixduppy

1:39 am on May 31, 2006 (gmt 0)



It could very well be my scripting, after all i haven't checked it--i haven't really even re-read any of it. Here is the full script anyway:

<?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]

RogueDogg

1:56 am on May 31, 2006 (gmt 0)

10+ Year Member



Ok after running search.html calling out submit.php this is the error that I get

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?

eelixduppy

2:01 am on May 31, 2006 (gmt 0)



What you get are just notices, but if you want to fix them change it to the following:

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!

RogueDogg

2:33 am on May 31, 2006 (gmt 0)

10+ Year Member



Here is what I am using for search.html

<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]

eelixduppy

2:51 am on May 31, 2006 (gmt 0)



Change it to this; it was missing a ')':

if(isset($_POST["add_member"]))
{activate();}
else
{show_users();}

Sorry about that ;)

RogueDogg

3:00 am on May 31, 2006 (gmt 0)

10+ Year Member



Ok that got rid of that error: Here is what the output was:

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]

eelixduppy

3:03 am on May 31, 2006 (gmt 0)



Add $name = $_POST["name"]; as the first thing in the show_users function.

RogueDogg

3:09 am on May 31, 2006 (gmt 0)

10+ Year Member



Like so:

{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]

eelixduppy

3:12 am on May 31, 2006 (gmt 0)



Like this:
function show_users() {
if(isset($_POST["name"])){$name = $_POST["name"];}
$link = "<br><br><a href='search.html'>Do another Search CLICK HERE</a>";
......

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!

eelixduppy

3:23 am on May 31, 2006 (gmt 0)



I just read your edit. So did it successfully add the data to the other table and delete it from the potential member table? Did we do it? Can we celebrate?
This 44 message thread spans 2 pages: 44