Jump to content

wildteen88

Staff Alumni
  • Posts

    10,480
  • Joined

  • Last visited

    Never

Posts posted by wildteen88

  1. Are you getting a directory listing of all the images in that folder? This is called FancyIndexing. You should be able to disable it by adding the following line into a .htaccess file within your photos directory

    Options -Indexes

    Or you can simply add a blank index.html file inside that directory.

     

    Which ever option you take you'll get a 403 forbidden error or a blank screen when going to mysite.com/photos/

  2. You don't need to call  mysql_select_db($database_swb, $swb); every time you run a query. I assume this is code that Dreamweaver has generated. You should really learn to hand code your script rather than relying on dreamweaver.

  3. Killing the script for each instance where the user hasn't filled in the form correctly is bad application design.

     

    You should instead add your error messages into an array when your validation for whaterver field fails, example for the Name field

    	if($Name == '')
    {
    	$errors[] = '<P class="form">Name field left empty</p>';
    }

     

    When you have finished validating the user input you can check whether any errors have accrued. if there are errors then display them, along with the form. If there are no errors then display your success message.

    if(!empty($errors))
    {
        echo 'Sorry correct the following errors: <ul><li>' . implode('</li><li>', $errors);
        // display your form here
    }
    else
    {
        echo("<P class=\"passed\">Thankyou for submiting your details, you will be added to our directory shortly</p>"); 
    }

     

     

  4. Change the foreach loop to

    foreach($checkbox_values as $cbox_value)
    {
        $selected = null;
        $cbox_label = $cbox_value;
    
        if(in_array($cbox_value, $db_values))
        {
            $selected = ' checked="checked"';
            $cbox_label = "<b>$cbox_value</b>";
        }
    
        echo '<input type="radio" name="stage" value="' . $cbox_value . '"' . $selected . ' />' . $cbox_label . '<br />';
    }

  5. You code sets $reg to the string " AND status=0 "; if you select Unpaid from the drop down box. And it is inserting this value into your query correctly.

     

    Could you explain what you mean by unexpected result. The problem is not so much to do with your PHP code, but your SQL query. Although placing raw user input into query is not recommended for security reasons, you should be validating/sanitizing your user input.

  6. You need to check if the fields are not empty within the for loop when building the query.

    				if(!empty($store[$i]) && !empty($item[$i]) && !empty($itemprice[$i]))
    			    $values[$i] = "( '{$id[$i]}', '{$store[$i]}', '{$item[$i]}', '{$itemprice[$i]}', '{$itemnumber[$i]}', '{$couponvalue[$i]}', '{$couponsused[$i]}')"; // build the array of values for the query string

    That if statement will check to make sure the fields store, item, and price have not been left empty. It'll only add the rows that have these three fields filled out.

  7. This is because you need to check if these variables are set before using them

    if(isset($_GET['username']) && isset($_GET['pwd']))
    {
         // your code here for authenticating the user
    }
    else
    {
         // display login form here
    }

     

    having the username/password within the url is insecure. You should be submitting your form with the post method.

  8. Because PHP does not pass on variables page to page. You can save the posted data into a session. So when you submit the first form to your second form save the posted data into a session, eg

    $_SESSION['step1_data'] = $_POST;

    After you have saved the posted data. Display your next form. On your final page you can work with the data you have collected. Here is an example

     

    step1.php

    <form action="step2.php" method="post">
    
        <p>
          Loan Type:
          <select name="loanType">
            <option>Loan Type 1</option>
            <option>Loan Type 2</option>
            <option>Loan Type 3</option>
          </select>
        </p>
    
        <p>
          Property Type:
          <select name="peopertyType">
            <option>Property Type 1</option>
            <option>Property Type 2</option>
            <option>Property Type 3</option>
          </select>
        </p>
    
        <p>
          Property State:
          <select name="peopertyState">
            <option>Property State 1</option>
            <option>Property State 2</option>
            <option>Property State 3</option>
          </select>
        </p>
    
        <p><input type="submit" name="step1_submit" value="Continue →" /></p>
    </form>
    

     

    step2.php

    <?php
    session_start();
    if(isset($_POST['step1_submit']))
    {
        $_SESSION['step1_data'] = $_POST; /* add all data from step1 to session variable */
    ?>
    <form action="step3.php" method="post">
    
        <p>
          Credit Score:
          <select name="creditScore">
            <option>500 - 600</option>
            <option>600 - 700</option>
            <option>800 - 900</option>
          </select>
        </p>
    
        <p>
          Phone Number: <input type="text" name="phoneNumber" />
        </p>
    
        <p>
          Email Address: <input type="text" name="emailAddress" />
        </p>
    
        <p><input type="submit" name="step2_submit" value="Continue →" /></p>
    </form>
    <?php
    }
    else
    {
    ?>
    Please fill in <a href="step1.php">Step 1</a>
    <?php
    };
    ?>

     

    step3.php

    <?php
    session_start();
    
    if(isset($_POST['step2_submit']) && isset($_SESSION['step1_data']))
    {
        echo "Your data: <h1>Step 1</h1>";
    
        foreach($_SESSION['step1_data'] as $field => $value)
        {
            if($field != 'step1_submit')
                echo "<p><b>$field</b> = $value</p>";
        }
    
        echo "<h1>Step 2</h1>";
    
        foreach($_POST as $field => $value)
        {
            if($field != 'step2_submit')
                echo "<p><b>$field</b> = $value</p>";
        }
    }
    else
    {
        echo 'Fill in <a href="step1.php">Step 1</a>';
    }
    ?>

     

  9. In main.php you're submitting the form to attendence.php

    <form name="form1" action="attendance.php" method="get">

     

    If you don't want the user to go to attentdence.php then set the forms submit action to main.php. Now above your form include attendence.php. Also I'd recommend you to change your forms submit method to post. Passing usernames/passwords over the url is insecure. You should also be encrypting your passwords within the database too.

  10. Okay I have fixed the code.

    Change this line

    @$rows[$j] .= ' <td class="member">'.$data."</td>";

    to

    @$rows[$j][] = ' <td class="member">'.$data."</td>";

     

    Now change the foreach loop to

        foreach($rows as $row)
        {
            echo " <tr>" . implode("\n", $row);
    
            // if the current row doesn't have enough columns 
            // then output the required number of blank cells to complete the row
            if($j = (count($row) < $num_cols))
            {
                for($i = 0; $i < $j; $i++)
                    echo '<td class="member"></td>';
            }
    
            echo " </tr>";
        }

     

    The @ symbol is used for error suppression.

  11. Where are you calling $product->getPrice()? Is it in the same file as when you initiated the product object (when you created the product). Or in a different page?

    If its in a different page then variables you define in one page will not be passed on to the next. Variables die when the script finishes.

  12. It's in a .php file and I'm using include

    Where are you using the include?

     

    All PHP code must be within a .php file. PHP code will not work within any other file type (unless the server is configured to do so).

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