Jump to content

marcus

Members
  • Posts

    1,842
  • Joined

  • Last visited

Posts posted by marcus

  1. You can use substr

     

    <?php
    //say you have a sql query already and $row = mysql_fetch_assoc($res)
    
    $body = substr($row[body],0,90); //the 1st character to the 90th character
    echo $body;
    
    //to find character length of the blob use:
    echo strlen($row[body]);
    ?>
    

  2. die(); would work easily, but if you put it all together and leave the mail function at the end it would work:

     

    <?php
    
    $var = $_POST['var'];
    
    if($var){
    
    if(strlen($var) > 32){
    echo "error";
    }else {
    	if(!ctype_alnum($var)){
    	echo "error";
    	}else {
    		//send mail
    	}
    }
    }else {
    echo "var not defined";
    }
    
    ?>
    

  3. I wouldn't use 0 as a value for a session, so look at it this way:

     

    1: normal member

    2: admin

     

    if($_SESSION['permission']){
    
    if($_SESSION['permission'] == 1){
    //whatever you want to do with a normal member
    }
    
    if($_SESSION['permission'] == 2){
    //whatever you want to do with an admin
    }
    }
    

  4. The foreach the queries are in it defines the set.

     

    If y = 0 then it means it's only one number,but if it isn't it creating |$itemids

     

    So If I had 1 number it would create a number as: 55342

     

    But if I had the max of 5 numbers it would create 55342|55343|55344|55345|55346

     

    In this case it's creating 5 queries for one set.

     

    So it's creating an individual query for just 55342, 55343, 55344, 55345 and 55346, instead of one whole query with the |'s in side it

     

    I'll post the whole cost how it's created:

     

    <?php
    $global_check=3;
    $trade_check=3;
    include('/home/MYSITE/public_html/global.php');
    login($_COOKIE[uid]);
    
    $act = $_GET[act];
    
    if(!$act){
    $sql = "SELECT * FROM `user_items` WHERE `place` ='Inventory' AND `uid` =$_COOKIE[uid] ORDER BY RAND()";
    $res = mysql_query($sql) or die(mysql_error());
    if(mysql_num_rows($res) > 0){
    echo "<form action=\"?act=go\" method=post>\n";
    echo "<table border=0 cellspacing=3 cellpadding=3 name=check width=600>\n";
    echo "<tr><td colspan=5 align=center class=bar>Clicking the checkbox below the item name will make the item up for trades when you hit the submit button. Once the checkbox is enabled the image will be given a 3 point green border, showing you the item is now being traded once you hit the submit button. To remove the green border along with the check in the checkbox, just click the image and it will be no longer up for trades!</td></tr>\n";
    ?>
    <script language="Javascript">
    function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) {
            var countedTextBox = opt_countedTextBox ? opt_countedTextBox : "counttxt";
            var countBody = opt_countBody ? opt_countBody : "countBody";
            var maxSize = opt_maxSize ? opt_maxSize : 1024;
    
            var field = document.getElementById(countedTextBox);
    
            if (field && field.value.length >= maxSize) {
                    field.value = field.value.substring(0, maxSize);
            }
            var txtField = document.getElementById(countBody);
                    if (txtField) { 
                    txtField.innerHTML = field.value.length;
            }
    }
    </script>
    <?php
    echo "<tr>\n";
    $x=1;
    
    //for($i=1;$i<=50;$i++){
    while($row = mysql_fetch_assoc($res)){
    //$d = $i;
    $id = $row[id];
    $itemid = $row[itemid];
    $res2 = mysql_query("SELECT * FROM `items` WHERE `itemid` =$itemid") or die(mysql_error());
    $row2 = mysql_fetch_assoc($res2);
    $src = $row2[image];
    $name = $row2[name];
    
    
    echo "<td align=center><img onClick=\"document.getElementById('cb$id').checked=false;document.getElementById('img$id').style.border='0px';\" src=\"/images/items/$src\" style=\"border:0px;\" id=\"img$id\"><br>$name<br><input id=\"cb$id\" type=checkbox name=\"items[]\" value=\"$id\" onClick=\"document.getElementById('img$id').style.border='3px solid green'\"></td>\n";
    if($x == 5){
    echo "</tr><tr>\n";
    $x=0;
    }
    $x++;
    
    }
    
    echo "<tr><td colspan=5 align=center>\n";
    echo "<textarea id=wishlist name=wishlist cols=30 rows=6 onkeyup=\"counterUpdate('wishlist', 'wltxt','250');\"></textarea>\n";
    echo "<br>You typed <B><span id=\"wltxt\">0</span></b> characters<br>Max. Length : 250 Chars\n";
    echo "</td></tr>\n";
    echo "<tr><td colspan=5 align=center>\n";
    echo "<input type=submit value=\"Start Trading\"></td></tr>";
    echo "</table></form>\n";
    
    }else {
    echo "You do not have any items to trade!";
    }
    
    }
    
    if($act == go){
    $items = $_POST[items];
    
    if($items){
    print_r($items);
    $x=0;
    foreach($items as $sluts){
    $x++;
    }
    if($x > 5){
    echo "5 items only!";
    }else {
    	$y=0;
    	foreach($items as $whores){
    		if(!is_numeric($whores)){
    		echo "Item #$y [$whores] is not numeric!<br>\n";
    		}else {
    			$sql = "SELECT * FROM `user_items` WHERE `id` =$whores AND `uid` =$_COOKIE[uid]";
    			$res = mysql_query($sql) or die(mysql_error());
    				if(mysql_num_rows($res) == 0){
    				echo "One of those items does not belong to you!<br>\n";
    				}else {
    					$row = mysql_fetch_assoc($res);
    					$sql2 = "SELECT * FROM `items` WHERE `itemid` =$row[itemid]";
    					$res2 = mysql_query($sql2) or die(mysql_error());
    					if(mysql_num_rows($res2) == 0){
    					echo "One of those items is not a real item!<br>\n";
    					}else {
    					$wishlist = protect($_POST['wishlist']);
    						if($wishlist){
    							if(strlen($wishlist > 250)){
    							echo "Your wishlist is too much!";
    							die();
    							}
    						}
    						if($y == 0){                   
    						$set = "$whores";
    						}else{
    						$set = "|$whores";
    						}
    							$time = time();
    							//$sql = "INSERT INTO `trades` (`uid`,`items`,`wishlist`,`time`) VALUES('$_COOKIE[uid]','$set','$wishlist','$time');";
    							//$res = mysql_query($sql) or die(mysql_error());
    							//$limit = $y-1;
    							//$sql2 = "DELETE FROM `trades` WHERE `uid` =$_COOKIE[uid] AND `time` =$time AND `items` ='$set' LIMIT $limit";
    							//$res2 = mysql_query($sql2) or die(mysql_error());
    					}
    				}
    		}
    
    	$y++;
    	}
    
    }
    echo "You trade has been created successfully!\n";
    }else {
    echo "YOU NEED TO SELECT ATLEAST ONE ITEM";
    }
    
    }
    
    include('/home/ataria/public_html/bottom.php');
    ?>
    

  5. Ok, I'm creating a trade system for a website I work for. The problem is, when I'm selecting the items and then splitting them, I can easily echo all one-five number(s) with | between each one.

     

    So it would look like: 1|2|53|5345

     

    The problem is, I'm submitting the data into the table inside that foreach, but it's creating a separate query for each number.

     

    How can I get all the numbers to stay one [1|2|53|5345] instead of having four queries for 1, 2, 53 and 5345?

     

    if($act == go){
    $items = $_POST[items];
    
    if($items){
    print_r($items);
    $x=0;
    foreach($items as $sluts){
    $x++;
    }
    if($x > 5){
    echo "5 items only!";
    }else {
    	$y=0;
    	foreach($items as $itemids){
    		if(!is_numeric($itemids)){
    		echo "Item #$y [$itemids] is not numeric!<br>\n";
    		}else {
    			$sql = "SELECT * FROM `user_items` WHERE `id` =$itemids AND `uid` =$_COOKIE[uid]";
    			$res = mysql_query($sql) or die(mysql_error());
    				if(mysql_num_rows($res) == 0){
    				echo "One of those items does not belong to you!<br>\n";
    				}else {
    					$row = mysql_fetch_assoc($res);
    					$sql2 = "SELECT * FROM `items` WHERE `itemid` =$row[itemid]";
    					$res2 = mysql_query($sql2) or die(mysql_error());
    					if(mysql_num_rows($res2) == 0){
    					echo "One of those items is not a real item!<br>\n";
    					}else {
    					$wishlist = protect($_POST['wishlist']);
    						if($wishlist){
    							if(strlen($wishlist > 250)){
    							echo "Your wishlist is too much!";
    							die();
    							}
    						}
    						if($y == 0){                   
    						$set = "$itemids";
    						}else{
    						$set = "|$itemids";
    						}
    							$time = time();
    							//$sql = "INSERT INTO `trades` (`uid`,`items`,`wishlist`,`time`) VALUES('$_COOKIE[uid]','$set','$wishlist','$time');";
    							//$res = mysql_query($sql) or die(mysql_error());
    							//$limit = $y-1;
    							//$sql2 = "DELETE FROM `trades` WHERE `uid` =$_COOKIE[uid] AND `time` =$time AND `items` ='$set' LIMIT $limit";
    							//$res2 = mysql_query($sql2) or die(mysql_error());
    					}
    				}
    		}
    
    	$y++;
    	}
    
    }
    echo "You trade has been created successfully!\n";
    }else {
    echo "YOU NEED TO SELECT ATLEAST ONE ITEM";
    }
    
    }
    

  6. <?php
    // initialize variable $searchType
    $searchtype = $_POST['searchtype'];
    // connect
    $sql = "SELECT * FROM members_images WHERE images_name='$searchtype'";
    $result = mysql_query($sql) or die(mysql_error());
    	if (mysql_num_rows($result) > 0) {
    		while ($row = mysql_fetch_assoc($result)) {
    		$images_name = $row['images_name'];
    		echo "<img src=\"$images_name\" height=\"127\" width=\"170\" alt=\" \" />";
    		}
    	} else {
    	echo "No results found";
    	}
    ?>
    

     

    Give that a go.

  7. Make the input slot:

     

    photo_filename[]

     

    $files = $_FILES['photo_filename'];
    $filenames = $_FILES['photo_filename']['name'];
    
    $filenames = array_reverse($filenames,true);
    
    $x=1;
    foreach($filenames as $file){
    echo "$x. $file<br>\n";
    $x++;
    }
    

     

    See if they go in reverse order here, but don't allow upload atm.

  8. print_r($_FILES);
    

     

    What do you get? Is it even being passed?

     

    You can use the same variable name.

     

    I tested it with an array and it worked fine

     

    <?php
    $array = array('hello','goodbye','hi');
    $x=1;
    foreach($array as $arra){
    echo "$x. $arra<br>\n";
    $x++;
    }
    echo "<br>\n";
    $array = array_reverse($array,true);
    $y=1;
    foreach($array as $arra){
    echo "$y. $arra<br>\n";
    $y++;
    }
    ?>
    

  9. You can use iframes.

     

    <html>
    <head>
    <title>asdas</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
    <iframe src="index.php" name="body" frameborder="0" width="100%" height="100%">
    Sorry, but your web browser does not support iframes
    </iframe>
    </body>
    </html>
    

     

    Each link mush have: target="body" before you end the first part of the tag.

     

    You could also do:

     

    <?php
    //this file is index.php
    $page = $_GET['page'];
    
    if($page){
    $dir = $_GET['dir'];
    
    if(!$dir){
    $file = "/home/yoursite/public_html/$page.php";
    }else {
    $file = "/home/yoursite/public_html/$dir/$page.php";
    }
    
    	if(file_exists($file)){
    	include "$file";
    	}else {
    	include "/home/yoursite/public_html/main.php";
    	}
    }else {
    include "/home/yoursite/public_html/main.php";
    }
    ?>
    

     

    In this case, your URLs must be:

     

    About: /index.php?page=about

    which will be: /home/yoursite/public_html/about.php

     

    Something Else: /index.php?page=login&dir=user

    which will be: /home/yoursite/public_html/user/login.php

  10. <?php
    $string = "Peter";
    $st = strlen($string);
    for($i=0;$i<$st;$i++){
    echo $string{$i} . "<br>\n";
    }
    ?>
    

     

    The for statement will emit:

    P

    E

    T

    E

    R

     

    But if you want each individual letter:

     

    P = $string{0}

    E = $string{1}

    T = $string{2}

    E = $string{3}

    R = $string{4}

  11. Just do:

     

    $query = "INSERT INTO email_news (level,author,date,time,subject,message,associated,display)
                  VALUES ('$level','$author','$date','$time','$subject','$message','$last_id','1')";                                       
    $result = mysql_query($query) or die('Query failed: ' . mysql_error()); 
    $lastid = mysql_insert_id();
    $sql = "UPDATE `email_news` SET `associated` =$lastid WHERE `id` = $lastid";
    $res = mysql_query($sql) or die(mysql_error());
    

     

     

  12. Are you trying to find all ITEMS in the category PHP?

     

    Just do something like:

     

    $item = $_GET['item'];
    
    if($item){
    $item = mysql_real_escape_string($item);
    $sql = "SELECT * FROM `myTable` WHERE `item` ='$item'";
    $res = mysql_query($sql) or die(mysql_error());
    
       if(mysql_num_rows($res) > 0){
          while($row = mysql_fetch_assoc($res)){
          echo "$row['name']<br>\n"; //do whatever to that line
          }
       }else {
       echo "No items exist";
       }
    }else {
    echo "You need to have an item defined";
    }
    

  13. When the sessions are granted parameters, are you using session_start(), or just creating them out of the blue?

     

    And plus the following isn't really necessary:

     

        unset($_SESSION['user']); 
        unset($_SESSION['pwd']);
        unset($_SESSION['id']);   // DESTROY
        $_SESSION = array(); // reset session array
        session_destroy();   // destroy session.
    

     

    Just have something like:

     

    <?php
    session_start();
    if (!empty($_SESSION['valid_user']) && !empty($_SESSION['password'])) //this and the next line two down from there are exactly the same, if the value ISNT empty, meaning it's set, so isset is useless
    {
      if (isset($_SESSION['valid_user']) && isset($_SESSION['password']))
      {
        session_destroy();   // destroy session.
        echo "<p class='genmed'>Logged out.</p><br>";
        do_html_url("login.php", "Login");
      }
      else
      {
       // they were logged in and could not be logged out
        echo "Could not log you out.<br>";
      }
    }
    else
    {
      // if they weren't logged in but came to this page somehow 
      if(!$logged_in){ //where is this variable defined?
        echo "<p class='genmed'>You were not logged in, and so have not been logged out.</p><br>";
        do_html_url("login.php", "Login"); //only needed one end quote there
      }
    }
    ?>
    

  14. Try this:

     

    <?php
    
    include "connect.php";
    $query = "SELECT * FROM sms_cat";
    $results = mysql_query($query) or die(mysql_error());
    
    
    $num = mysql_num_rows($results);
    
    if($num > 0){
    
    $category = $_GET['cat'];
    
    
    while($row = mysql_fetch_array($results)){
    $sql = "SELECT * FROM `sms_cat` WHERE `id` =$row[id]";
    $res = mysql_query($sql) or die(mysql_error());
    $row2 = mysql_fetch_assoc($res);
    
    	$cat = $row2['cat'];
    	$itemid = $row2['itemid']; //or whatever your field is for itemid
    	$price = $row2['price'];
    	$name = $row2['name'];
    
                
    
    	if($category){
    		if($category == $cat){
    
    		echo "<a href=\"shop.php?cat=$cat&item=$itemid\">$name</a><br />\n";
    
    		}
    	}
    }
    }
    
    ?>
    

  15. You don't need to escape variables in your URL.

     

    echo "<a href=\"shop.php?cat=$cat&item=$itemid\">$name</a><br />\n";
    

     

    Also change this line:

     

    $results = mysql_query($query);
    

     

    To:

     

    $results = mysql_query($query) or die(mysql_error());
    

     

    Change:

     

    $num = mysql_fetch_array($results);
    
    if($num > 0){
    

     

    To:

     

    $num = mysql_num_rows($results);
    
    if($num > 0){
    

     

    Below that add:

     

    $row = mysql_fetch_array($results);
    

     

    Change all your $num variables to $row.

     

    Also change:

     

    while($i < $num){
    

     

    To:

     

    while($i <= $num){
    //in this you could also do
    //while($row = mysql_fetch_array($results)){
    //then manually select each row
    //$sql = "SELECT * FROM `myTable` WHERE `id` =$row[id]";
    //$res = mysql_query($sql) or die(mysql_error());
    //$row2 = mysql_fetch_assoc($res);
    //then change all the $num variables to $row2 and you wouldn't have to use $i
    

     

    I also suggest using normal apostrophes and quotes, ' and "

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