Jump to content

spiderwell

Members
  • Posts

    1,008
  • Joined

  • Last visited

Posts posted by spiderwell

  1. in sites i have made in the past, i have an auto edit form that pre populates the users info, and depending on if that user is an admin or just a normal user, the user group option is hidden or in a drop down.

    i.e. an ordinary user will not get the option to change group from user to admin, but the same form viewed by admin will have an extra field with these options.

     

    in fact the same form also works for adding new users via the cms backend or as a register form on the front end.

     

     

  2. how often does a menu change on a website? , is it really necessary to keep it in the database?, thats one extra db call on every page you dont really need

     

    i use this as a common included file for a navigation on many sites i write/have written, obviously you would adapt the output to your needs:

    $navarray['Logout'] = 'login.php?action=logout';
    $navarray['View Exhibitions'] = 'exhibitions.php';
    $navarray['My Sales'] = 'mysales.php';
    $navarray['View Images'] = 'images.php';
    $navarray['Consigned Images'] = 'consigned.php';
    $navstring = "<div class=\"shadetabs\"><ul>";
    foreach ($navarray as $key => $value)
        {
    	$navstring .= "<li";
    
    	if (strpos($_SERVER['PHP_SELF'], $value)) $navstring .= " class='selected'";
    	$navstring .= ">\r";
    	$navstring .= "<a href='" . $value  . "'>"; 
    	$navstring .= $key;
    	$navstring .= "</a>\r";					
    	$navstring .= "</li>\r";
    }
    $navstring .= $outputstr;
    $navstring .= "</ul></div>";
    echo $navstring;
    

     

    this out the menu into a <ul> list and those have so many css interpretations they can look like anything

  3. if you want to use the id from a row that you just inserted, you can call it back using  mysql_insert_id()

     

    <?php 
    session_start();
    
    if (isset($_SESSION['id'])) {
        $userid = $_SESSION['id'];
        $username = $_SESSION['username'];
       	
    
    $fname = $_POST['firstname'];
    $lname = $_POST['lastname']; 
    $telephone = $_POST['telephone'];
            $city = $_POST['city'];
    $state = $_POST['state'];
    $itemname = $_POST['product_name'];
    $price = $_POST['price'];
    $details = $_POST['details'];
            $category = $_POST['category'];
    $subcategory = $_POST['subcategory'];
            $product_id = $_POST['product_id'];
    $customer_id = $_POST['customer_id'];
            $date_sold = $_POST['date_sold'];
    
    
    
          $sqlinsert = "INSERT INTO customers
                                (id,firstname,lastname,telephone,city,state,product_name,price,details)            
                                VALUES('','$fname','$lname', '$telephone','$city','$state','$itemname','$price','$details')";
          $enterquery = mysql_query($sqlinsert) or die(mysql_error()); 
          $customer_id= mysql_insert_id();
    
          $sqlinsert2 = "INSERT INTO products
                                (id,product_name,price,details,category,subcategory)            
                                VALUES('','$itemname','$price','$details','$category','$subcategory')";
          $enterquery2 = mysql_query($sqlinsert2) or die(mysql_error());
          $product_id =  mysql_insert_id();
          	$sqlinsert3 = "INSERT INTO sales
                                   (id,product_id, customer_id, date_sold)            
                                   VALUES('','$product_id','$customer_id','$date_sold')";
    
    
    
    
    $enterquery3 = mysql_query($sqlinsert3) or die(mysql_error()); 
    }
    ?>

  4. Splitting up HTML and PHP doesn't mean you can't show any error's, you can just pass them:

     

    $errors = array();
    
    include('page.html');
    

     

    In your page.html you could then have:

     

    <?php if(sizeof($errors)): ?>
    <ul>
      <li><?php print $errors[0]; ?></li>
    </ul>
    <?php endif; ?>

     

    Show us your entire script and I'll show you how you can refactor it for reusability.

    dont you need to have .php extension though or the php wont execute?

  5.  

    <?php
            $query2 = "SELECT * FROM psychofarm_gen WHERE `id`!=".$randomNumber;
            $result2 = mysql_query($query2);
            while($row = mysql_fetch_array($result2))
    {
    	$wrong_answer[] = $row['name']; 
    }
    ?>
    

     

     

    you dont need the $i counter, it will automatically set the key value when omitted, unless you want to explicitly set it of course

  6. really i guess its down to personal preference, if you do a redirect, I am guessing you will need to send variables to that redirect, I can't see the point in that personally.

     

    you could make a function for the payment method or use an include file to keep the code seperate.

     

    I guess it boils down to if that payment process is a code you need to use on other pages or not? if not used anywhere else why not keep it all in the same page. if its used multiple times by different pages, i would put it in its own page in a function/ or in a class.

  7. the first line is what i mean by outside i.e. its not inside quotes, as you can out put variables inline "something $variable ".

     

    echo " alot of text here and then treasure holdings: ".round($row['team_treasure'],2)." and some more text here"; 
    //works 
    echo " alot of text here and then treasure holdings:round($row['team_treasure'],2) and some more text here"; 
    //wont work
    
    

  8. While you're at it, there's no need to concatenate the variables into the strings all the time like that. The output from the following is the same as what will be generated by your echoes.

     

    echo "You sent $amount to $member<br />";
    }
    }
    echo " $amount and $member";

     

    is there a performance difference with doing it this way? i always use the . concatenate method , just because i find it easier to read in notepad++, lol

  9. do you want this to be able to send each member the same amount of different amounts?

    a form with a dropdown box with members listed with a text input next to it should get you started, however that means you would only be able to send to one member at a time.

    a multiselect box would bring issues of only being able to send the same amount to all members.

     

    a form a bit like this would work for one member at a time:

     

    <?php
    if($_POST)
    {
    $amount = $_POST['amount'];
    $sendtomember = $_POST['memberlist'];
    //i going to skip some obvious stuff like DB connecting,error trapping  etc
    $balance = $row['field']; // execute query to get amount in DB
    if($amount <= $balance) 
       {
        //do querys to send amount to member, and subtract from balance of sender, using $amount and $sendtomember variables
    
        }
        else
        {
          echo " you cannot send more than you have";
         }
    }
    ?>
    <form method="POST">
    <select name="memberlist">
    <option>Choose a member</option>
    <option value="1">johnny</option> <!-- value is ID of user in db -->
    <option value="2">peter</option>
    </select>
    <input type="text" name="amount">
    <input type="submit" value="send amount">
    </form>
    

     

    obviously this code wont work, but like you said, it might point you in the right direction

    you could be clever and use ajax to add extra rows in the form, if user desired to send to another member, but of course that will involve having more error trapping and multiple querys to DB etc

  10. you need to use the $_SESSION object to store the usrname and/or password

    then check for that session existing on each protected page.

     

    I would give an example but i have to go out now, sorry buddy !

  11. that script is going to work, but the issue is that the loginreferingtoken.html page isnt protected by a login check, being a plain html document.

     

    what could be done is that you could set a session variable once a user is logged in, and on each page (change extenstions to .php) to check if that session is set, and if not redirect away.

     

     

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