Jump to content

Jax2

Members
  • Posts

    282
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Jax2's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi all. I have a database that contains a large list of businesses (over 35,000) and I am trying to create a search page to display what people are looking for (I.e. Plumbing Detroit or Plumbing 48312)... I am getting results with my SQL query, but they are not right. Here is the submission form and the resulting search query... Index.php: <form action="search.php" method="get"> <input type="text" name="type" id="query" size="30" placeholder="Business type/name"/> <input type="text" name="location" size="15" placeholder="City, Town or Zip"> <input type="submit" value="Search"/> </form> Search.php: if (isset($_GET['type'])){ $type=$_GET['type']; } if (isset($_GET['location'])){ $location=$_GET['location']; } $stmt = $db->prepare("SELECT * FROM `listings` WHERE `Primary_City` LIKE '%$location%' OR `Primary_Zip` LIKE '$location' AND `Line_Of_Business` LIKE '%$type%' OR `Primary_Industry` LIKE '%$type%' "); $stmt->execute(); $total=$stmt->rowCount(); echo "<div style='padding-left:50px; padding-top:10px;'> <strong>Your search for ".$type." in ".$location." returned ".$total." records.</strong></div><br /><br />"; while ($row=$stmt->fetch()) {?> This returns (for one city!) over 5400 results, when I type in Plumbing Midland into the search boxes (type, location), with results from all different cities in the state, instead of just the city name or zip code I entered and I am unsure as to how to fix it to only show the records that have a Primary_Zip or Primary_City that equals $location... Thanks if you can help!
  2. You You were correct, thank you - I didn't actually call the post data for the original $password. I thought I had it just under session at the top of the page but apparently had omitted it. I appreciate the help. As for not creating my own password mechanism, it works, and it works well, so I do not see any reason not to use it, personally.
  3. Hi again, I have an add user form and a login form which both use a salt added to the password, then converted to a sha1 hash. Problem is, when I add the user, store the salt, and store the salted password, they're not matching when I try to log in. I am doing it the same both ways, as far as I can tell, so I'm not sure why the salted password would be different. Here are the code snips... Add user: //Generate random 64 char salt. $salt = ''; $characters="abcdefghijklmnopqrstuvwxyz0123456789"; for ($i = 0; $i < 64; $i++) { $salt .= $characters[rand(0, strlen($characters) - 1)]; } //Generate Salted SHA1 password hash $salted_password = sha1($salt.$password); //Add user to database $sql = "INSERT INTO users(fName, lName, username, password, salt, email) VALUES (:fName, :lName, :username, :password, :salt, :email)"; $stmt = $db->prepare($sql); $stmt->bindParam(':fName', $_POST['fName']); $stmt->bindParam(':lName', $_POST['lName']); $stmt->bindParam(':username', $_POST['username']); $stmt->bindParam(':password', $salted_password); $stmt->bindParam(':salt', $salt); $stmt->bindParam(':email', $_POST['email']); $stmt->execute(); //check if successful. IF ($db->lastInsertId()) This successfully stores the user information, the $salt.$password hash and the $salt itself. Now for login: $password = $_POST['password']; $username = $_POST['username']; //Connect to database. Get Salt and Password. $stmt = $db->prepare("SELECT * FROM users where username = :username"); $stmt->bindParam(':username', $username); $stmt->execute(); $count= $stmt -> rowCount(); IF ($count==1) { while ($row = $stmt->fetch()) { $salt=$row['salt']; $salted_password=sha1($salt.$password); echo "Password From Form: ".$password."<br>"; echo "Salt from Database: " .$row['salt']."<br>"; echo "Salt + password: ".$salted_password."<br>"; echo "Database Password:".$row['password']."<br>"; IF ($salted_password==$row['password']) { $_SESSION['loggedIn']=1; echo "<h2>Logged In!</h2>"; } ELSE { echo "<h2>Login Failed</h2>"; } } } I cannot spot an error here... I am taking the username and password (which I echo'ed just to be sure the variable is correct, and compared sha1($salt.$password) to $row['password'] (previously saved as same sha1(salt.password) combination) but I only get a login failed result. I do not understand what I am doing wrong. I join $salt + $password and create an SHA1 hash from that., then I combine $salt + $password from login form and create an SHA1 hash from that as well, but end up with a different salted password hash. I have tried creating numerous users with different passwords, and each one has it's own salt in the database which corresponds to the salt being echoed when I try and log in... every one fails. Could someone be so kind as to point out where I am going wrong? Thank you.
  4. Hi all, I need some guidance and hoping some of you might be able to point me in the right direction. I am working on a project for a client that includes a very large database of business contacts and a simple one line search box. I will explain as best I can: The database contains prefix, first name, last name, company name, company type (roofing, tiling, flooring...etc), address, city, county, zip code, phone number and other variables. The search box on the websites homepage is only one line. The pre-populated text says: Enter Business type, city, county or zipcode. The user is "supposed" to add a type of business (I.e. Roofing, tiling, dry walling ...etc) followed by either a city, a county or a zip code. I need to figure out how to take this text (I.e. Roofing macomb county, or, Roofing 48333, or Roofing Detroit) and first find all companies that match type (roofing) and then match either city, county or zipcode, depending on what the user enters. Traditionally, I have used multi-part search boxes, such as a drop down for company type, text box for city, county or zip, and assigned each as a search variable, easy stuff, but I am unsure as to how I would progress with a single text string that I'm not even sure how a customer will enter. They could, for example, type the zipcode or city first, followed by the company type (I.e. 48333 roofing) or they may not enter a company type at all, simply entering a zip code, in which case I'd have to be able to prompt them to add a company type as well so we know which companies to return. Could anyone please give me some advice on how I should start on this? I have 2 weeks to complete the entire project and this is the only area I am unfamiliar with. The rest is just a lot of coding and pretty standard. Thank you so much in advance!
  5. Hi all, been a while since I've been on here. I am in the process of designing a site similar to dating sites like plenty of fish, or ok cupid. The only spot I am running into trouble is with images. If you are familiar with either of these sites, you will understand what I am looking for. Basically, a user is able to upload one or more images via an uploader (Not sure if it's ajax or flash to be honest, but I would like to stick to PHP/Ajax). While uploading, they have the ability to crop their images to specific sizes set by the site - for example, the image must be cropped to fit a 400 px X 400 px area, so they have the ability to decide which part of a larger image is saved rather than just have the system crop it and perhaps not show what was intended. After they finish and click upload, the image is saved to the server, as well as a thumbnail, which, without a refresh, is then added to their page along with their previous images if there were any. From that point, they have the option to delete images they don't like, set the main image for their profile and edit/add captions to the images, again, all without refreshing the page. Would anyone happen to know of a script I could start with and change to suit my needs, but that would pretty much allow this kind of image uploading/manipulation? I've done google searches for hours now and have looked at a ton of scripts but not a single one I have found seems to be able to do any of these things. Most just have multiple file uploads with cropping ability, but not by the users themselves, just a predetermined dimension. Any help pointing me in the right direction would be greatly appreciated. Jax
  6. I would like to figure out if something is even possible, and if so, how I might do it... if not, is there another way in which I could possibly do this? I'll explain: I am creating a script (or trying to anyhow) that would allow people to create their own content, much like a story with multiple paths. I have only figured out the first part, creating the first page and adding options and links to new pages. User creates story title and brief description --> Story title saved to database, random link generator creates a random # from 1million to 9,999,999. Number is checked against another table that includes all links already generated, and creates a new temp random number if needed, until it finds a free number. That number becomes the first page of the story. On the bottom of each page, the user can create up to 4 choices for the reader to choose from. Each choice is saved in the database along with the page number it came from. So now we're up to 5 possible pages. The user may also choose to make a page a "The End" page, meaning there will be no more links from that page, end of story. HERE IS MY PROBLEM! I do not know how I could easily allow the user to keep track of where they are in their stories. What I mean is, if they start on page 1 and offer 4 choices, they will have to continue writing for each of the choices. As they continue adding pages, and more choices, it will become more and more difficult to remember which page has choices on it you haven't written content for yet. What I would like to do somehow is create a map maybe, so for each page they do, it will add to the map, much like a family tree, branching out until each page is an end page and has no more choices. They would also have to be color coded, so, for example, if they offer 3 choices, and haven't written the content for each choice, the box on the map showing that page would be red. If they have completed the next page for each choice, the box would be green. This way, they can quickly glance at the "map" and see Oh, there is a page with 1 or more choices on it, but I haven't written a new segment for at least 1 of them, I need to go back to this page and continue it. I really hope someone out there can make sense of what I am saying and tell me if there is any way to create a map, or a branch directory so to speak for their story. ANY suggestions would be helpful, as I'm at a complete loss now. Thank you in advance, and if this interests you at all but I'm not clear on something, please let me know and I'll try to explain better!
  7. Muddy, changed it around just a little and it works perfectly. I even learned what I was doing wrong, so thank you very much
  8. Ok, I will explain first what I am trying to do, and show you how I am going about it, which isn't working I have a table set up. It has missing ID numbers, such as, 1 2 3 6 7 8 11 12 ..etc. I am trying to pull a random ID number from all valid ID numbers. (Meaning, I don't want to get an ID of a record that is no longer there, so skip all the missing ID's) This is for a cron job to change which record is being shown each day, randomly. I figured, logically, the best way to do this would be to pull all the valid ID's into an array, and then use array_rand($id_array,1); to pull one random ID number out of the array. So, I tried using this code: //Set variable as an array $id_array = array(); //Populate array with valid ID's $sql="SELECT ID FROM riddles"; $result=mysql_query($sql,$db) or die(mysql_error()); while($row = mysql_fetch_array($result,$db)) { $id_array[] = $row['ID']; }; print_r(array($id_array)); $new_rotd=(array_rand($id_array[0],1)); I am running into 2 problems with this code. First, when I print_r the array, I get the following: The numbers are not correct. It is the correct number of total records, but it is not putting the correct ID number in there. 2) When I try and pull a random number out of the array, I get an error saying the First argument has to be an array. It IS an array?! I need to get this working, so any help would be much appreciated. To summarize I need to: Pull all valid ID #'s out of the table and put them in an array. Pull one random number out of that array and set it as variable: $new_rotd
  9. Very strange ... usually with auto-increment it starts with 0 and counts up ... it shouldn't be trying to insert a larger number unless your code is telling it what to put there for some reason. If the table is empty, you could always go into phpmyadmin and click on the right table, then click on SQL, and type in TRUNCATE TABLE (table name here) without the ( ) 's of course... If that doesn't solve it, try asking in the mysql section. Doesn't sound like a php issue unless again, it's because of your code. Can you paste the part of the code dealing with the inserting of data?
  10. as stated above, if you have the information in a database, it's all rather simple... for example: $sql="SELECT * FROM USERS WHERE user_name=$name"; $result=mysql_query($sql); while ($row=mysql_fetch_array($result)) { echo "Name: ".$row['name']."/r/n"; echo "Email: ".$row['email']."/r/n"; } And so on to get their info. One piece of advice ... think ahead on how you plan on doing this. For example, if you use login sessions, make sure that the person logged in, if they're looking at their own user info, be sure to use an if statement and check against the database before you show any private info an such ... otherwise, everything that is shown on the user page will be available to everyone else too... You can also use this for hiding albums, sending mail back and forth and much more.
  11. Login is simple if vbulletin uses sessions, which hopefully it does instead of cookies, just figure out what the login session is and use that ... I.e. if (!$SESSION['loggedIn']) { echo 'You must be <a href=www.yoursite.com/login.php>logged in</a>'; exit; } Put that at the top of any page where they have to be logged in and it will show them that message until they're logged in.
  12. If you're just trying to use select boxes to save data to the database, it's a simple form really ... for example: <form method=post action=nextpage.php> <input type="checkbox" name="fruit[]" value="apples">Apples<br> <input type="checkbox" name="fruit[]" value="oranges">Oranges<br><br> <input type="submit" value="Continue"> </form> on the next page, you'd call your post variable array $fruit[]: $fruit=$_POST['fruit']; and then you can store the array into your database. For displaying all the options chosen by the user somewhere else, you can use something like: for ($i=0; $i<count($fruit); $i++) { echo( ($i+1) . ") " . $fruit[$i] . "<br>"); }; I'm sure there's more to it than that, but that should get you started hopefully.
  13. I was trying to correct it in my code paste as well, but it didn't look as nice as yours
  14. Well, one thing you could do is just have the drop down use a quick javascript call the same page as soon as someone selects something in the first box ... the page would refresh (I.e., call itself) and you could pass the variables up to the second box... As for keeping the variable in the first box, I'd try a switch statement or an if/else statement for each option and depending on what option was selected (Which is stored in $box1 variable or something) figure out how to insert "selected" in the option statement, such as <select name="box1"> <option value="somevalue" <?php echo $is_selected;?> >some value</option> <option value="somevalue2" <?php echo $is_selected2;?> >some value 2</option> </select> And then try something like: if ($box1=="somevalue") { $is_selected="selected"; } ELSE if ($box1=="somevalue2") { $is_selected2="selected"; } ELSE { $is_selected3="selected"; }; Now, as I said, that could get long if you have a lot of options, so you'd have to figure out some way to shorten it, but that should get you in the right direction. You can look up how to change / refresh the page on the selection of a drop down option with javascript, it's pretty small, usually like an onsubmit or onclick or some other function. Not a JS guy myself. Good luck! And if someone has a better idea how he can choose where the 'selected' goes, please do speak up lol
  15. May not be correct, but from what I see in the code, it looks like you're saying if their IP address is EXACTLY 10.65, then show them connected ... Wouldn't it need to be if ($remote_addr like 10.65%) { ...etc ? <?php $VPNremote_ip = "REMOTE_ADDR"; ?> <div class="lowerMessage" style="MARGIN: 10px auto; WIDTH: 400px"> <p align="left"> <?php if (VPNremote_ip == "10.65") { ?> SSL CONNECTION STATUS- <span style="COLOR: #000099; FONT-SIZE: 14px; FONT-WEIGHT: bold">CONNECTED</span> </p> <p align="left"> <?php } else { ?> SSL CONNECTION STATUS - <span style="COLOR: #cc0000; FONT-SIZE: 14px; FONT-WEIGHT: bold">FAILED</span> <?php } <script type="text/javascript"> openWin('not_connected.html'); </script> <br ><br > YOUR IP ADDRESS IS: <b><?php echo getenv('REMOTE_ADDR'); ?></b></p>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.