Jump to content

NewcastleFan

Members
  • Posts

    64
  • Joined

  • Last visited

Posts posted by NewcastleFan

  1. I'm not sure if this is possible but im looking to get an object say a ball, and drop it into a pool of water at the bottom of of the page and for the water to splash upwards and freeze (like watching a video of it).


    Is this possible not using flash? This is for a web project on a browser so I'm not sure if it is possible using html5, css, jquery?


    If it is possible does anyone know of any examples that use or do this sort of thing it that I could look at?


    Thanks!


  2. Hey all, I'm trying a little project to help improve my php and mysql knowledge.

     

    I'm struggling with email validation and security.

     

    I'm looking to check if an email is valid or not before I add the ability to add it into a database.

     

    What I have so far:

    <?php
    	$errormsg ="";
    	if (isset($_POST['adduser'])){
    
    	$email = mysql_real_escape_string($_POST['email']);
    	$pword = mysql_real_escape_string($_POST['pword']);
    	$pword2 = mysql_real_escape_string($_POST['pword2']);
    
    	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    	
    		if ($email == "") {
    			$errormsg ="Error, You must fill in the email box.";
    		}
    		else if ($pword == "") {
    			$errormsg ="Error, You must fill in the password box.";
    		}
    		else if ($pword2 == "") {
    			$errormsg ="Error, You must fill in the repeat password box.";
    		}
    		else if ($pword != $pword2) {
    			$errormsg ="Error, Your passwords don't match!";
    		}
    		else {
    			$errormsg = "Success!";
    		}
    	} else {
    			$errormsg = "Invalid email format, please use a valid email address.";
    	
    	}	
    	
    }
    ?>
    

    This always outputs the error message "Error, You must fill in the email box" now, however without the Filter_Validate_email it outputs success when all boxes are filled in.

     

    Anyone got any help on a ) whats going wrong and b ) any other security features I can add?

     

    Thanks!

  3. Hey everyone, I'm trying to select multiple rows from one table, depending on the ID given from another table.

     

    I've got it half working with the code below, however it echo's out each blog multiple times depending on how many different tags are assigned to it, how would I go about so it displays multiple tag's on one copy of the blog post?

    
    	$sqlCommand = "SELECT blogid, blogtitle, content, blogtime, category, blogseourl, author FROM blog ORDER BY blogtime DESC";
    		$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
    	$blogDisplay = '';
    			while ($row = mysqli_fetch_array($query)) {
    			$blogid = $row["blogid"];
    			$blogtitle = $row["blogtitle"];
    			$content = $row["content"];
    			$blogtime = $row["blogtime"];
    			$category = $row["category"];
    			$blogseourl = $row["blogseourl"];
    			$author = $row["author"];
    			$contentshort =  substr($content, 0, 250);
    		$sqlCommand2 = "SELECT tag FROM blogtags WHERE blogid='$blogid'";
    		$query2 = mysqli_query($myConnection, $sqlCommand2) or die (mysqli_error());		
    			while ($row = mysqli_fetch_array($query2)) {
    			$tag = $row['tag'];
    			
    	$blogDisplay .= '<h1><a href="/blog/'. $blogseourl .'"> ' . $blogtitle . ' </a></h1> ' . $contentshort . '... <a href="/blog/'. $blogseourl .'">Read More...</a><br /><br /> ' . $author . ' posted on ' . $blogtime . ' |	 Category: ' . $category . ' |	 Tags: ' . $tag . ' | <a href="/blog/'. $blogseourl .'#disqus_thread"></a>'; 
    			}
    			}
    	mysqli_free_result($query);	
    

    So everything is working correctly apart from it echoing multiple $blogDisplay's for each tag.

     

    Anyone got any ideas? 

  4. Was hoping I wouldn't have to create another table :(

     

    So I need another table like:

     

    BlogID ¦ Tag

    1 ¦ testtag1

    1 ¦ testtag2

    1 ¦ test

    2 ¦ testtag2

    2 ¦ test

    2 ¦ testtag1

     

    To then re-write everything to pull from both tables? I thought it would of been a lot simpler to just use one table and the implode and explode functions :(

  5. Remove "%" from LIKE statement, search only pageid like e.g. "LIKE '$pageid'" in WHERE clause of SELECT query

     

    That would work if I only had one tag for each post correct? The tag column has the option of multiple values e.g; "testtag1, testtag2". So if I only used the "LIKE '$pageid'" it will only filter items if they are the exact match so I couldn't have a tag page for testtag1 and a separate page for testtag2 it would have to be a page for both testtag1 and testtag2.

  6. Hey guys, not sure if anyone will be able to help with this but I have a small issue with a select filter I'm trying to use.

     

    I'm trying to select posts with the correct tag's to display a list of the posts in the page. I've got it working to a certain extent with the code below, however I have this small issue:

     

    If I click the link that says "testtag1" it will filter the posts and only show the posts with testtag1.

     

    But If I have a shortened link say the tag is called just "test" it will bring up anything with test in it, so posts with testtag1, testtag2, test will appear.

     

    is there a way to refine the LIKE filter in mysql to stop this?

    	if (!$_GET['tagseourl']) {
    		$pageid = '';
    	} else {
    		$pageid = $_GET['tagseourl'];
    	}	
    			
    		$sqlCommand = "SELECT blogid, blogtitle, content, blogtime, category, blogseourl, tag, author FROM blog WHERE tag LIKE '%$pageid%'";
    		$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
    	$blogDisplay = '';
    			while ($row = mysqli_fetch_array($query)) {
    			$blogid = $row["blogid"];
    			$blogtitle = $row["blogtitle"];
    			$content = $row["content"];
    			$blogtime = $row["blogtime"];
    			$category = $row["category"];
    			$blogseourl = $row["blogseourl"];
    			$tag = $row["tag"];
    			$author = $row["author"];
    			$contentshort =  substr($content, 0, 250);
    			
    	$blogDisplay .= '<h1><a href="/blog/'. $blogseourl .'"> ' . $blogtitle . ' </a></h1> ' . $contentshort . '... <a href="/blog/'. $blogseourl .'">Read More...</a><br /><br /> ' . $author . ' posted on ' . $blogtime . ' |	 Category: ' . $category . ' |	 Tags: ' . $tag . ' | <a href="/blog/'. $blogseourl .'#disqus_thread"></a>'; 
    			
    			}
    	mysqli_free_result($query);
    

    The field tag in the database looks like this:

     

    ID ¦ tags

    1 ¦ testtag1, testtag2, testtag3

    2 ¦ test. testtag1

    3 ¦ testtag2, testtag3

     

    etc.

  7. Not sure how its working now but this is what worked no idea why if anyone else is stuck:

     

    $sqlCommand = "SELECT tag FROM tags";
    $query2 = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
    $tagoptions="";
    $posttag = explode(',', str_replace(' ', '', $posttag));
    while ($row = mysqli_fetch_array($query2)) { 
        $tag = $row["tag"];   
        if (in_array($tag, $posttag)) {
            $checked = "checked";
        }
        else {
            $checked = "";
        }
        $tagoptions.="<input type='checkbox' name='checkboxname[]' value='$tag' $checked>".$tag.'<br>';
    }
    
  8. $tagoptions was echoed yes, it output the correct list of check boxes but none were selected.

     

    $posttag was pulled from the database column posttag which is a text field, and had the value of "tag1, tag2" so the check boxes for tag1 and tag2 should be selected.

  9.  

    $sqlCommand = "SELECT tag FROM tags";
    $query2 = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
    $tagoptions="";
    $postag = explode(',', str_replace(' ', '', $postag));
    while ($row = mysqli_fetch_array($query2)) { 
        $tag = $row["tag"];   
        if (in_array($tag, $postag)) {
            $checked = "checked";
        }
        else {
            $checked = "";
        }
        $tagoptions.="<input type='checkbox' name='checkboxname[]' value='$tag' $checked>".$tag.'<br>';
    }
    

     

    Thanks for the reply, this still unfortunately does nothing :(

     

    I've tried to take it back to basics and remove the database calls just to figure out how to get this to work:

     

    <?php 
    $posttag = "tag1, tag2";
    $posttag = explode(',', str_replace(' ', '', $posttag));
    $tag = "tag1, tag2, tag3";   
        if (in_array($tag, $posttag)) {
            $checked = "checked";
        }
        else {
            $checked = "";
        }
    }
    
    echo $posttag;
      
    ?>
    <br>
     <input type='checkbox' name='checkboxname[1]' value='tag1' <?php echo $checked ?>>Tag1<br>
     
     <input type='checkbox' name='checkboxname[2]' value='tag2' <?php echo $checked ?>>Tag2<br>
     
     <input type='checkbox' name='checkboxname[3]' value='tag3' <?php echo $checked ?>>Tag3<br>
    

     

    However this now isn't even working ha, just returns a blank screen :(

  10.  

    $sqlCommand = "SELECT tag FROM tags";
    $query2 = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
    $tagoptions="";
    while ($row = mysqli_fetch_array($query2)) { 
        $tag = $row["tag"];   
        if (in_array($tag, $postag)) {
            $checked = "checked";
        }
        else {
            $checked = "";
        }
        $tagoptions.="<input type='checkbox' name='checkboxname[]' value='$tag' $checked>".$tag.'<br>';
    }
    

     

    That doesn't seem to do anything, no boxes are checked no matter the value of $posttag.

     

    Not sure if I've explained it correctly I'm not the greatest at explaining sorry.

     

    $posttag would come through with a value of "tag1, tag2"

    $tag would come through in an array with my while loop "tag1" "tag2" "tag3"

  11. The posttag is opened up in the array here?

     

    $string = $posttag;
    	$array = explode(',', $string);
    				if ($string == $array) {
    							$checked = "checked";
    							}
    						else {
    							$checked = "";
    						}
    

     

    I've used explode to separate them but then I'm not sure how to get from that point to checking to check the box?

  12. Hey guys, 

     

    Not sure if anyone is able to help me out I'm trying to split up some data from a table and select check boxes depending on if the tag exists:

     

    Database:

     

    Table: Tags

    Fields: id, tag

     

    PHP so far:

     

    $sqlCommand = "SELECT tag FROM tags";
    $query2 = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
    $tagoptions="";
    while ($row = mysqli_fetch_array($query2)) { 
        $tag = $row["tag"];
    $string = $posttag;
    $array = explode(',', $string);
    if ($string == $tag) {
    $checked = "checked";
    }
    else {
    $checked = "";
    }
    $tagoptions.="<input type='checkbox' name='checkboxname[]' value='$tag' $checked>".$tag.'<br>';
    }
    

     

     


    The data in the tag's field:

    ID - TAG

    1 tag1

    2 tag2

    3 tag3

     

    The tag table is used to generate the tag check boxes. Once they are generated (Which works).

     

    I then have the data been requested from a different table which could be multiple options e.g.:

     

    tag1, tag3

     

    However if only one tag is selected then the box is checked, if 2 tags or more are selected then neither work.

     

    Anyone have any ideas where I am going wrong here?

  13. Hey guys,

     

    I'm trying to make the value pulled from the mysql database be the selected option which the list is dynamically selected from a directory.

     

     <?php 
      function list_files($the_path) { 
      $handle = dir($the_path); 
       while ($file = $handle->read()) { 
     if (($file != ".") && ($file != "..")) { 
         $options .= "<option value='$file' selected='$picked'>$file</option>\n"; 
     }   
       } 
           return $options; 
      } 
     ?> 
     <select name="tempname"> 
     <?php echo list_files("../templates/pages/"); ?> 
     </select>
    

     

    I'm trying to make the value of $picked to be "true". I've pulled the file name from the database and it is stored in $tempname and I'm trying to use something like:

     

    <?php
    if ($file == $tempname) {
     $picked = "true";
    }
    ?>
    

     

    But I can't seem to get it to work, I don't think the $file variable can be edited in the function.

     

    Anyone got any ideas or suggestions?

  14. I really hope all this is a "just for fun" project...

     

    It's for fun yes, I'm using this to teach my self more php.

     

    Sorry, but I still cannot see the sense in triplicating all the data when only the prices are different.

     

    How would you suggest doing it so I could have 3 price bands and the ability to override the percentage off then? I'm no php expert so I'm trying to learn.

  15. I figured it out!

     

    Not sure how efficient it is but it works ha If anyone else is struggling with this here is what I used:

     

     

    
    
    <?php
    if(isset($_POST['updateprices'])) { 
    
    $sql1= mysqli_query($myConnection, "REPLACE INTO pricestwo (priceid,productname,productweight,productprice) SELECT priceid,productname,productweight,productprice *0.9 FROM prices");
    
    $sql2= mysqli_query($myConnection, "REPLACE INTO pricesthree (priceid,productname,productweight,productprice) SELECT priceid,productname,productweight,productprice *0.85 FROM prices");
    
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=edit_product_prices.php#tabone-tab\">";
    } 
    ?>
    

  16. And it would be impossible to edit the prices if they were all in one table :confused:

     

    As far as I'm aware? I may not be explaining it correctly lets give an example:

     

    Product 1 is set to £10.00, I update this across all tables so the data looks like:

     

    Tableone

    Product 1, £10.00

    Product 2, £20.00

     

    Tabletwo

    Product 1, £9.00

    Product 2, £18.00

     

    Tablethree

    Product 1, £8.50

    Product 2, £17.00

     

    Now that's what I'm trying to make happen on the update of all the tables.

     

    But I currently want to run an offer for users of the tablethree group, I want to reduce product 1 to £6.50 so I go manually update the price in tablethree.

     

    Does that make any sense? ha.

     

    I've played around with it a bit more now and got to this point:

     

    
    <?php
    if(isset($_POST['updateprices'])) {
    
    $sql1= mysqli_query($myConnection, "REPLACE INTO pricestwo (priceid,productname,productweight,productprice) SELECT priceid,productname,productweight,productprice FROM prices");
    
    $sql2= mysqli_query($myConnection, "REPLACE INTO pricesthree (priceid,productname,productweight,productprice) SELECT priceid,productname,productweight,'$productpricetwo' FROM prices");
    
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=edit_product_prices.php#tabone-tab\">";
    }
    ?>
    

     

     

     

    However I still cannot figure out how to reduce the productprice column by a % on update :(

  17. Sorry, if this is a stupid question, but I've read through your posts here and I'm wondering why you need separate tables. In fact, do you need to even store price2 and price3 at all?

     

    First, why are you needing to store these in separate tables? Why not store price2 and price3 in the same table in different fields? Then you don't have to duplicate the data across the tables. There might be a valid reason for doing this but, if not, you will save yourself a ton of problems by putting them in the same table.

     

    Second, if price2 and prioce3 will always be the same percentage off from price1 then you don't need to store price2 and price3 at all. Just hard-code or have a configuration on what the offset for price2 and price3 should be. Then dynamically change the price based upon your need. Example:

    //Config vars for the offsets
    $price1 = 1;
    $price2 = .9;
    $price3 = .8;
    
    //Then in your code have some logic to determine the offset
    switch($user_type)
    {
    case 'Big Buyer':
     $price_offset = $price3;
     break;
    case 'Frequent Buyer':
     $price_offset = $price2;
     break;
    case 'Normal Buyer':
    Default:
     $price_offset = $price1;
     break;
    }
    
    //Then use that offset in any queries to get price
    $query = "SELECT name, (price * $price_offset) as price
    	 FROM products";

     

    Thanks for your reply, Unfortunately I need them to be stored separate because once the data is passed to the other tables with the % off I need the ability to manually edit the price for special offers etc for certain price bands.

  18. Forget the looping. All you need is a couple of update queries

     

    UPDATE pricetwo p2
    INNER JOIN priceone p1 USING (priceid)
    SET
    p2.price = p1.price * 0.9,
    p2.productname = '$name',
    p2.producweight = $weight
    WHERE p1.priceid = $id

     

    ... and similar for pricethree table.

     

    Of course, you need to sanitize those POST variable first.

     

    Thanks for your reply, I've never used inner join, not 100% sure how it works but I've done the following as per your example however it returns a server error. How are the variables p1.priceid defined?

     

    
    
    <?php
    // Variables defined for update of multiple tables
    $priceid = $_POST['priceid'] ;
    $name = $_POST['productname'] ;
    $weight = $_POST['productweight'];
    $price = $_POST['productprice'];
    
    if(isset($_POST['updateprices'])) {
    
    for($i=0;$i<$count;$i++){
    
    $sql1= mysqli_query($myConnection, "UPDATE pricetwo p2
    INNER JOIN priceone p1 USING (priceid)
    SET
    p2.price = p1.price * 0.9,
    p2.productname = '$name',
    p2.producweight = $weight
    WHERE p1.priceid = $priceid";
    
    
    $sql2= mysqli_query($myConnection, "UPDATE pricesthree SET productname='$name[$i]', productweight='$weight[$i]', productprice='$price[$i]' WHERE priceid='$priceid[$i]'");
    }
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=edit_product_prices.php#tabone-tab\">";
    }
    ?>
    

     

    Not sure if I'm completely off the mark here, feeling a tad out of my knowledge depth at the moment!

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