Jump to content
Larry Ullman's Book Forums

Ghamdan

Members
  • Posts

    55
  • Joined

  • Last visited

Posts posted by Ghamdan

  1. I am using charset utf8 for database connection, sql database, mysqli table of content and html but the question mark shows at the end of some posts and it returns one question mark only the reset of the text is fine.

    Some of the output:

     

    Article: المغناطيسية. الإعلان جميل جداً، ولكنه يفتقر إلى الشمولية والوضوح، فلو أن أحدهم لم يعرف عن سيرفيس وميزاته الداخلية البرمجية والصلبة من قبل، فلن يلفت انتباهه في الإعلان سوى الرقص والراقصين. وذكرت مايكروسوفت في نهاية الإعلان موعد إطلاق الحاسب رسمياً وهو السادس والعشرين م� ...

     

    This is Arabic.

    ..............................

    Thank you.

  2. I am working on chapter 18 and trying to show some pages in the header if the user is admin but it does not show the link for admin.

    It just shows links for registered users but not for admin.

     

    The code is below:

     

    <?php

    // Display links based upon the login status:

    if(isset($_SESSION['user_id'])) {

    echo ' <li> <a href="logout.php" title="Logout">Logout</a> </li>

    <li> <a href="change_password.php" title="Change your password"> Change Password</a> </li>';

     

    // Show links if the user is admin:

    if($_SESSION['user_id'] == 1) {

    echo ' <li> <a href="view_users.php" title="View all the users"> View Users </a> </li>

    <li> <a href="#" title=" admin page"> admin page</a> </li>';

    }

     

    } else { // Not logged in.

    echo ' <li> <a href="register.php" title="Register for the site"> Register</a> </li>

    <li> <a href="login.php" title="Login"> Login </a> </li>

    <li> <a href="forgot_password.php" title="Reset password"> Reset Password </a> </li>';

     

    }

    ?>

    How can I show the links for the admin?

    Note: the admin has got user_level of 1.

    Thank you.

  3. Chapter 18 - registration form.

    I am working on chapter 18 registration form when I validate the name with reg exp it does not accept the input value and reset works fine.

     

    php code:

    // Validate name:

    if(preg_match( '/^[A-Z \'.-]{2, 40}$/i' , $trimmed['name'])) {

    $p_name = mysqli_real_escape_string($dbc , $trimmed['name'] );

     

    } else {

    echo '<p class="error"> Please enter your name. </p>';

     

    }

     

     

    html code:

     

    <label for="name" > Name: </label>

    <input type="text" id="name" name="name" size="30" maxlength="40"

    value="<?php if(isset($trimmed['name'])) echo $trimmed['name'] ; ?>" />

     

     

     

    How can I solve this issue?

  4. <nav>

    <ul>

    <?php

     

    $pages = array(

    'Home Page' => 'index.php',

    'Register' => 'register.php'

     

    );

     

    $this_page = basename($_SERVER['PHP_SELF']);

     

    foreach($pages as $k => $v) {

    echo '<li';

    if($this_page == $k) {

    echo ' class="current"';

    echo ' > <a href="'.$v.'"> <span> ' . $k . ' </span> </a> </li> ';

    }

    }// End of foreach loop

     

    ?>

     

    </ul>

    </nav>

  5. Even I have tried to upload a file to a live server but it is not working.

    display_errors error is already on.

    That is really strange !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    ====================================================================

     

    ; http://php.net/display-errors

    display_errors = On

    ====================================================================

    ; The display of errors which occur during PHP's startup sequence are handled

    ; separately from display_errors. PHP's default behavior is to suppress those

    ; errors from clients. Turning the display of startup errors on can be useful in

    ; debugging configuration problems. But, it's strongly recommended that you

    ; leave this setting off on production servers.

    ; Default Value: Off

    ; Development Value: On

    ; Production Value: Off

    ; http://php.net/display-startup-errors

    display_startup_errors = On

  6. ;;;;;;;;;;;;;;;;

    ; File Uploads ;

    ;;;;;;;;;;;;;;;;

     

    ; Whether to allow HTTP file uploads.

    ; http://php.net/file-uploads

    file_uploads = On

     

    ; Temporary directory for HTTP uploaded files (will use system default if not

    ; specified).

    ; http://php.net/upload-tmp-dir

    upload_tmp_dir = "C:\xampp\tmp"

     

    ; Maximum allowed size for uploaded files.

    ; http://php.net/upload-max-filesize

    upload_max_filesize = 2M

     

    ; Maximum number of files that can be uploaded via a single request

    max_file_uploads = 20

  7. I am working on File uploads and the script does not work.

    I have checked for php.ini and everything is fine.

    file_uploads = on

    ;upload_tmp_dir =

    upload_max_filesize = 2m

    max_file_uploads = 20

    =====================

    I am using windows 7.

    uploads folder is inside htdoc and the web root folder inside htdoc.

    ============================================================

    How can I fix this issue?

    Thank you

    ==================================================================

    <h2> Upload An Image </h2>

     

    <?php

    # Upload An Image scripts.

    if($_SERVER['REQUEST_METHOD'] == 'POST') {

    // Check for an uploaded file:

    if(isset($_FILE['upload'])) {

    // Validate image type:

    $allowed = array('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png' );

     

    if(in_array($_FILES['upload']['type'], $allowed) ) {

    // Move the file over:

    if(move_uploaded_file($_FILES['upload']['tmp_name'], "../uploads/{$_FILES['upload']['name']}") ) {

    echo '<p> <em> The file has been uploaded! </em> </p>';

     

    }// End of move_uploaded_file

     

    } else { // Invalid type.

    echo '<p> Please upload a jpeg or png image. </p>';

    }

     

     

    }// End of if(isset($_FILE['upload']))

     

    // Check for an error:

    if($_FILES['upload']['error'] > 0) {

    echo '<p> The file could not be uploaded because: <strong> ';

     

    // Print a message base upon the error.

    switch($_FILES['upload']['error']) {

    case 1:

    print 'The file exceeds the upload_max_filesize setting in php.ini';

    break;

     

    case 2:

    print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';

    break;

     

    case 3:

    print 'The file was only partially uploaded.';

    break;

     

    case 4:

    print 'No file was uploaded.';

    break;

     

    case 6:

    print 'No temporary folder was available.';

    break;

     

    case 7:

    print 'Unable to write to the disk';

    break;

     

    case 8:

    print 'File upload stopped.';

    break;

     

    default:

    print 'A system error ocurred.';

    break;

     

    }// End of SWITCH.

    print '</strong> </p>';

     

    } // End of error IF.

     

    // Delete the file if it still exists:

    if(file_exists($_FILES['upload']['tmp_name']) && is_file($_FILES['upload']['tmp_name'])) {

    unlink($_FILES['upload']['tmp_name']);

     

    }

     

    } // End of the main submition if statement.

     

    ?>

     

    <form style="margin:10px;" action="upload_image.php" method="post" enctype="multipart/form-data">

     

    <input type="hidden" name="MAX_FILE_SIZE" value="524288" />

     

    <fieldset>

    <legend> Select a jpeg or png image of 512KB or smaller to be uploaded:

    <p style="margin:10px;"> <strong>File: </strong> <input type="file" name="upload" /> </p>

    </legend>

    </fieldset>

    <p> <input type="submit" name="submit" value="Upload" /> </p>

     

    </form>

  8. // Process checkbox:

    if(isset($scrubbed['service'])) {

    $service = $scrubbed['service'];

     

    } else {

    $service = NULL;

    $errors[] = "<p class=\"errors\">Please check some of the boxes. </p>";

    }

     

    <fieldset class="checkbox">

    <p>Service type: </p>

     

    <ul>

    <li> <input type="checkbox" name="service" id="service-one" value="one" />

    <label for="service-one"> service-one </label> </li>

     

    <li> <input type="checkbox" name="service" id="service-two" value="two" />

    <label for="service-two">service-two </label> </li>

     

    <li> <input type="checkbox" name="service" id="service-three" value="three" />

    <label for="ervice-three"> service-three</label> </li>

     

    <li> <input type="checkbox" name="service" id="other-service" value="other-service" />

    <label for="other-service"> Other </label> </li>

    </ul>

    </fieldset>

×
×
  • Create New...