Im trying to make my code so if you type www.license.com OR http://www.license.com it will say its found (if it finds www.license.com or http://www.license.com in the mysql database) and not found if its not in the database. If i type www.license.com in the field box and click submit, it says its found, but if i type http://www.license.com it says its not found. Its kind of confusing and i cant really make it easier to understand... hope you can. Heres the mysql code i have: $sdb = $_POST['check']; $sdbht = 'http://'.$_POST['check'].''; $query = "SELECT * FROM licensed WHERE domain = '$sdb' OR domain = '$sdbht'"; $result = mysql_query($query); $myrecord = mysql_fetch_array($result); Code (markup):
$sdb = $_POST['check']; $sdbht = 'http://'.$_POST['check'].''; $query = "SELECT * FROM licensed WHERE domain LIKE '$sdb' OR domain LIKE '$sdbht'"; $result = mysql_query($query); $myrecord = mysql_fetch_array($result); Will do the trick I think?
Try this: $sdb = str_replace("http://", "", $_POST['check']); // removes the http:// if entered into the form $query = "SELECT * FROM licensed WHERE domain = '$sdb'; $result = mysql_query($query); $myrecord = mysql_fetch_array($result);
The line starting with $query is missing the end quote on the SQL String. It should be: $query = "SELECT * FROM licensed WHERE domain = '$sdb'"; I'm not sure if that caused the error you're getting, I got a different one, but once I fixed it, it works fine.
I think you can just use str_replace() again: $sdb = str_replace("http://", "", $_POST['check']); // removes the http:// if entered into the form $sdb = str_replace("www.", "", $sdb); //remove www. $sdb = str_replace("/", "", $sdb); //remove slashes $query = "SELECT * FROM licensed WHERE domain = '$sdb'"; $result = mysql_query($query); $myrecord = mysql_fetch_array($result); PHP: Note: only remove the slashes if you are working with pages without a subdirectory in their url (eg. http://www.page.com/users/ needs the slashes otherwise it won't load the correct page [page.comusers does not exist]) EDIT: I think it would not be that hard to write a function that would remove only the last slash of an url. Let us know if that's what you are looking for.
I didnt know you can use the same variable twice ($sdb) thanks (i actually did $sdb, $sdbn, $sdbf) I dont need to be able to enter sub directories.