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?
to this:
$query = "INSERT INTO full_members (First, Last, email, phone, phone2, Address, City, State, Zip, enter_date) VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[email]', '$_POST[phone]', '$_POST[phone2]', '$_POST[address]', '$_POST[city]', '$_POST[state]', '$_POST[zip]', '$_POST[enter_date]')";
This should fix how you data is being entered into the table, that is, as long as this table is identical to the other table with column names. As for the delete, i would echo the query to see what is going on with it. Try maybe entering it in manually to see if it works. Gooc luck!
[edited by: jatar_k at 4:06 am (utc) on May 31, 2006]
[edit reason] fixed sidescroll [/edit]
<?php $query = "INSERT INTO full_members (fname,lname,email,phone,phone2,address,city,state,zip,enterdate) VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[email]', '$_POST[phone]', '$_POST[phone2]', '$_POST[address]', '$_POST[city]', '$_POST[state]', '$_POST[zip]', '$_POST[enter_date]')"; function delete_member($email) function show_users() while ($row=mysql_fetch_array($result)) { <tr> <input type="hidden" name="email" value="<? echo $row["email"];?>" /> <?
$name = $_POST["name"];
error_reporting(E_ALL);
if(isset($_POST["add_member"]))
{activate();}
else
{show_users();}
function activate()
{
$backlink = "<br><br><a href='search.html'>Do another Search CLICK HERE</a>";
$link = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("dbname", $link);
$_POST = array_map("mysql_real_escape_string",$_POST);
$result = mysql_query($query,$link) or die("ADD query not working<br>".mysql_error());
if($result){ echo "Added to database successfully!<br>"; }
else { echo "Added unsuccessfully<br>"; }
delete_member($_POST["email"]);
echo "<br>Thank you for becoming a FULL Member!<br>";
echo "$backlink";
mysql_close($link);
}
{
$backlink = "<br><br><a href='search.html'>Do another Search CLICK HERE</a>";
$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());
if($result)
{ echo "Delete from database Successful!<br>"; }
else { echo "Delete error!<br>"; }
mysql_close($link);
}
{
$backlink = "<br><br><a href='search.html'>Do another Search CLICK HERE</a>";
if(isset($_POST["name"])){$name = $_POST["name"];}
if(isset($name)){
$name = trim($name);
}
else{
echo "No search criteria given.";
echo $backlink;
exit;
}
$backlink = "<br><br><a href='search.html'>Do another Search CLICK HERE</a>";
$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 $backlink;
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();
?>
<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="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>$backlink<br>";
}
?>
The only thing I don't like so far is that I had to declare the "$backlink" like 4 times in order for it to show up under all circumstances ( i.e. back search value, successful search value, adding/deleting of user from the 2 db's ). I guess if I was smart I would make a php file of it and just do an include maybe? or sometype of global variable? I dunno but anyways it's working, now the trick is to get it to work with the actual db's and not my test db's. :-(
[edited by: jatar_k at 4:38 am (utc) on May 31, 2006]
[edit reason] fixed sidescroll [/edit]
*EDIT* Nevermind I already have a column with CUID and it's auto_increment...DOH! I have a question though, I am having a huge brain fart here....I want to delete every entry in the table but keep the columns...so in essence start over with a clean db & table...I forgot how to do this, actually I never really learned how to do this, just to delete everything ( including columns...which I don't want to do ). Know what I mean? <--do I keep typing that...hehe
*EDIT 2* WOW I make more edits than anyone I think, anyways, I fount a way in mysql to copy the table structure with no data so I will make a copy of it and delete the old one. I'm good I think...for now
>>>delete every entry in the table but keep the columns
Just run this query:
delete from table_name;
[dev.mysql.com...]
this should reset auto increment values as well
Also I should be able to pass that CUID/Username to db2 without having to display it after the search from db1 right? Keep it hidden?
you could also select the highest value from db2 and start at that number + 1 and use a counter in your insert loop
or you could just set the auto increment on db2 and not use that value on insert, let it take car eof the incrementing
cats should be nervous, there's alot of ways to skin 'em ;)
Now that I've got that complete, of course my boss wants to change this and that and add more to it....argh...the fun never stops.
Thanks again to you all who helped me, I'm sure I'll need more of it in the future... :0)