Jump to content

Boldonglen

Members
  • Posts

    19
  • Joined

  • Last visited

    Never

Posts posted by Boldonglen

  1. I have realised what the problem is and i am going to have to appologise for wasting your time. I was using the preg_replace() function to try and prevent SQL injection and this was taking the space out of the search term. Again im sorry but thank you for your help.

  2. This is exactly how my code is:

     

    $search_exploded = explode(' ',$search);
    
    				$searches = array();
    
    			foreach($search_exploded as $search_each)
    				{
    					   $searches[] =  "keywords LIKE '%$search_each%'";
    				}
    			$construct = "SELECT * FROM products WHERE " . implode(' OR ' , $searches);

     

    And the output of this when using "test test" is:

     

    SELECT * FROM products WHERE keywords LIKE '%testtest%'

     

    Have i copied the code wrong?

  3. I tried using this code but when i test to see what the queery will look like when using the search terms "test test" i get SELECT * FROM products WHERE keywords LIKE '%testtest%' This is not the queery i need to produce. i would want the queery to look something like SELECT * FROM products WHERE keywords LIKE '%test%' OR keywords LIKE '%test%'

  4. I have a foreach function within my website, it is used as part of a search engine i have created. The code was working and then i restarted my computer and now the code is not working. The code uses the explode function to separate each search term into an array. And then if there is more than one search term it adds a extra line of code onto the SQL query. If anyone could tell me why this is not working that would be a great help.

     

    $search_exploded = explode(" ",$search);
    			$x = 0;
    
    			foreach($search_exploded as $search_each)
    			{
    				$x++;
    				if ($x==1)
    					$construct .= "keywords LIKE '%$search_each%'";
    				else
    					$construct .= " OR keywords LIKE '%$search_each%'";
    
    			}
    
    
    		$construct = "SELECT * FROM products WHERE $construct";

     

     

    Thanks Boldonglen

     

    Edit: I forgot to mention that what is happening is when i search for more than one term it is just showing the "SELECT * FROM products WHERE keywords LIKE '%$search_each%'" and not the OR statement. The $search_each is showing both the search results but just taking away the space.

  5. Im a little confused with the code that you supplied im not 100% with PHP The links that i have created are on every web page i have created and would like them all to link to one web page named product_list and for that page to be populated with the products of the brand selected. The code for my links are:

     

    <p><a href="product_list">Brand1</a></p>
              <p><a href="product_list">Brand2</a></p>
              <p><a href="product_list">Brand3</a> </p>

  6. I have tried messing around with my code but i cannot find a way of storing information after the user clicks a link. For example i have a list of brands on my website and each one has a hyperlink. When the user clicks the hyperlink i would like the name of that brand to be stored into a variable so that i can use the variable within the query. Could anyone help me out with this problem. Or recommend another solution to how i could show the products that are of the particular brand that the user clicks.

     

    Thanks Boldonglen

  7. I have designed and created a ecommerce website that allows the user to add products to a shopping cart and for the admin to edit the inventory list. However i would like to have a navigational bar on the website where the user can choose a brand of product and the webpage shows only that brand. I know i can do this by using the WHERE command in a query however would i have to make a separate web page for each brand?

     

    Thanks Boldonglen

  8. Im sorry im new to this forum forgot to put the code in Here is my code:

     

    <?php
    
    		session_start();
    
    		if ($_SESSION['username'])
    			echo "Welcome, ".$_SESSION['username']."! <br><a href='logout.php'>Logout!</a>";
    		else
    			echo "<a href='register.php'>Register?</a>";
    			  
    		?>
    
    		<form action='login.php' method="post">
    		Username: 
    		<input type="text" name="username">
    		<br>
    		Password: 
    		<input type="password" name="password">
    		<br>
    		<input type="submit" value="Log in">
    		</form>

     

    I would like to put the form above into the else part of the if statement.

  9. Hello firstly i would like to say im very new to this forum (Signed up 5 minutes ago). I have decided to join as im in my final year at university and have been asked to create a website, so im guessing ill be coming back here a lot for help! :P.

     

    Anyway my most current problem is i have an if statement that hides the "Register" button if the user is logged in and Shows a welcome message and the users name if the user is logged in. However i would like to make the log in form disappear if the user is logged in. I know that by putting the form code in the else part of my if statement it will disappear if the user is logged in however when i do this it stops my whole website working.

     

    Any help would be very grateful.

     

    Thanks Glen.

×
×
  • 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.