You're welcome. It was a lot more fun than my honey-do list for today :)
CFROG commented: Couldn't have asked for a better person to help. Patient and thorough all the way to end. +1
You're welcome. It was a lot more fun than my honey-do list for today :)
Odd that mysql would not complain if there were an id field in each table, but you could add to your select statement that started like
SELECT u.*, up.* FROM users AS u
and change to
SELECT u.id AS mykey,u.*, up.* FROM users AS u
then use
$id = $row['mykey']
Kind of a kludge but not sure without seeing the
DESCRIBE users
and
DESCRIBE user_profile
Well, if it didn't error, then you have at least one row of data in there that matches. Now before here
while($r1=mysql_fetch_array($res1))
echo $numr and $sql1 and then die(). Then run the $sql1 through phpmyadmin and make sure you get a row. $numr should tell you that you found at least one but it's good to check. After this, repeat the process just before the next mysql_fetch_assoc() to see which one of those looped queries is not executing correctly.
If phpmyadmin showed one row, then what error message do you see when you execute the script. You said it stopped at
while ($row = mysql_fetch_array($res))
it should have at least run through that once. As a check you can put this around that loop
if (!mysql_num_rows($res))
{
echo "Found no rows\n";
}
else
{
while ...
}
You said the second query gave up while reading the first row of the query. Did you run the script the second time and echo $query and run it from phpmyadmin?
No, that is a global option. You can change error_reporting on the fly to simply stop the warning for deprecated functions by doing this.
<?php
error_reporting(E_ALL);
// code for session_is_registered();
error_reporting(E_ALL & E_STRICT);
That just stops the warning for your code, then resets it to the default.
Better would be to write your own function for session_is_registered() that sets error_reporting, does the function, then sets error_reporting back.
After Line 58, put
print_r($terms);
echo $query . "\n"
die();
Also, your $_GET variables are not lined up. I see you comparing lf1 to lf2 etc. Did you mean to do that?
Once you get the echo of $query, go to your database using the command-line client and enter that query, post the error message you get.
Really you should use something like
if (isset($_SESSION['variable']))
instead as that function will not be available in PHP 6.
For now, you can go change your php.ini file. Look for
error_reporting = E_ALL & E_STRICT
or something like that. Remove the E_STRICT and you will not see those warnings anymore.
Whitespace won't throw it off, but echoing the $query variable as well as having the table schema, we should be able to see if you are looking for AND or OR in your multiple search criteria.
if (isset($_GET['lf2']) && $_GET['lf2'] != '')
{
$value = $_GET['lf2']; // other validation for what value you want goes here
$query .= " AND up.lf2 = '" . addslashes($value) . "'";
}
add an echo and die() before the syntax error so we can see what $query contains. Please post that variable as well as the table schema for both tables.
Are you saying that the field name in your table is not lf1? It is really up.friends and up.networking?
Well, the real issue is the query. It is not going to do what you think it will.
$page="SELECT u.*, up.* FROM users AS u INNER JOIN user_profile AS up ON u.id = up.user_id WHERE u.zip IN ({$zcodes}) AND u.gender='$gender' AND u.age BETWEEN '$min_age' and '$max_age' AND up.lf1 OR up.lf2 OR up.lf3 OR up.lf4 OR up.lf5 OR up.lf6 OR up.lf7 IN ({$looking_for})";
The above will NOT check if ANY or ALL of the lf(1-6) work for the array. It is only checking if those exist all all (evaluate to TRUE) OR up.lf7 IN (array)
You didn't mention what the values of any of the
$_GET['lf']
could be, but you'd probably be better off checking for the existance of each lf element and dynamically creating the mysql query like the following example.
$query="SELECT u.*, up.* FROM users AS u INNER JOIN user_profile AS up ON u.id = up.user_id WHERE u.zip IN ({$zcodes}) AND u.gender='$gender' AND u.age BETWEEN '$min_age' and '$max_age'";
if (isset($_GET['lf2']) && $_GET['lf2'] != '')
{
$value = $_GET['lf2']; // other validation for what value you want goes here
$query .= " AND up.lf2 = " . $value;
}
if (isset($_GET['lf3']) && $_GET['lf3'] != '')
{ $value = $_GET['lf3']; // other validation for what value you want goes here
$query .= " AND up.lf3 = " . $value;
}
echo $query . "\n";
I think there is a much easier way. Before I go on, I'll read back to you what I think you want. You have a two column list. You have a new two column list. You'd like the first lists' price column to be updated if there is a matching code in the codes column in the second list. If the above is correct, here's what I would do.
1. Create a mysql table with fields for code and price with a primary key on code. This will make sure you only have one row of data for each unique code. Also helps #4 below work.
2. Export your new columns from excel to a .csv file.
3. Use your favorite language to read that .csv file one line at a time.
4. Use the following type of statement on the data you just read.
INSERT INTO tablename (code, price) VALUES ('codevalue','pricevalue') ON DUPLICATE KEY UPDATE price = 'pricevalue'
I believe your original question was how to match http://awebsite.com to http://www.awebsite.com or awebsite.com.
I accomplished that, but it appears you have user input that you are not validating. Your original post said the user was entering a domain name. You must check that they actually did enter a domain name or web address.
I am simply removing the subdomain and protocol if it exists. You must also go through your database and update the rows to have the shortened domain as well.
Maybe a few rows of the relevant database table as well as the structure would help as well as a few search terms that you entered?
$searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection
gets replaced by
$domainPieces = tld_domain($searchTerms);
$searchTermDB = mysql_real_escape_string($domainPieces[0]);
as well as putting that function at the bottom of your page
Skip the str_replace then and use something like this. This should also work for domains like http://www.example.co.uk
<?php
function tld_domain($host)
{
if (preg_match('/([a-z0-9][a-z0-9\-]{1,63})\.([a-z]{3}|[a-z]{2}\.[a-z]{2})$/i', $host, $regs))
{
return $regs;
}
return false;
}
$fullDomain = "http://www.example.com";
$domainPieces = tld_domain($fullDomain);
$domain = $domainPieces[0];
echo $domain . "\n";
?>
I think you have a few other problems and the query isn't going to scale well, however the code below should fix your array() problems.
<?php
$terms = array();
for ($x = 1; $x < 9; $x++)
{
$searchTerm = "lf" . $x;
if (isset($_GET[$searchTerm]) && $_GET[$searchTerm] != '')
{
$terms[] = $_GET[$searchTerm];
}
}
if (in_array("Any",$terms))
{
$page="SELECT * FROM users WHERE zip IN ({$zcodes}) AND gender='$gender' AND age BETWEEN '$min_age' and '$max_age'";
}
else
{
$looking_for = implode(",", $terms);
$page="SELECT u.*, up.* FROM users AS u INNER JOIN user_profile AS up ON u.id = up.user_id WHERE u.zip IN ({$zcodes}) AND u.gender='$gender' AND u.age BETWEEN '$min_age' and '$max_age' AND up.lf1 OR up.lf2 OR up.lf3 OR up.lf4 OR up.lf5 OR up.lf6 OR up.lf7 IN ({$looking_for})";
}
?>
Why not normalize the database so there are no http:// or https:// in your search field? Once that is done, do a
str_replace("http://","",$searchTerm) && str_replace("https://","",$searchTerm)
on the user input.
The above would then match. You could take it a step further and check for the existance of www. in front of the domain (both in the database and in user input) to match even better.