Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/topic.php on line 737
Форумы портала PHP.SU :: Cookie

 PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи


 Страниц (1): [1]   

> Описание: Cookie
Leaderss
Отправлено: 21 Июня, 2013 - 18:01:37
Post Id


Новичок


Покинул форум
Сообщений всего: 20
Дата рег-ции: Июнь 2013  


Помог: 0 раз(а)




Помогите с Cookie
как перевести код в cookie
вот Cookie код там надо $_COOKIE['user_id'] поставить вместо $user_id

PHP:
скопировать код в буфер обмена
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5.   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6.   <title>Mismatch - Edit Profile</title>
  7.   <link rel="stylesheet" type="text/css" href="style.css" />
  8. </head>
  9. <body>
  10.   <h3>Mismatch - Edit Profile</h3>
  11.  
  12. <?PHP
  13.   require_once('appvars.php');
  14.   require_once('connectvars.php');
  15.  
  16.   // Connect to the database
  17.   $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  18.  
  19.   if (isset($_POST['submit'])) {
  20.     // Grab the profile data from the POST
  21.     $first_name = mysqli_real_escape_string($dbc, trim($_POST['firstname']));
  22.     $last_name = mysqli_real_escape_string($dbc, trim($_POST['lastname']));
  23.     $gender = mysqli_real_escape_string($dbc, trim($_POST['gender']));
  24.     $birthdate = mysqli_real_escape_string($dbc, trim($_POST['birthdate']));
  25.     $city = mysqli_real_escape_string($dbc, trim($_POST['city']));
  26.     $state = mysqli_real_escape_string($dbc, trim($_POST['state']));
  27.     $old_picture = mysqli_real_escape_string($dbc, trim($_POST['old_picture']));
  28.     $new_picture = mysqli_real_escape_string($dbc, trim($_FILES['new_picture']['name']));
  29.     $new_picture_type = $_FILES['new_picture']['type'];
  30.     $new_picture_size = $_FILES['new_picture']['size'];
  31.     list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']);
  32.     $error = false;
  33.  
  34.     // Validate and move the uploaded picture file, if necessary
  35.     if (!empty($new_picture)) {
  36.       if ((($new_picture_type == 'image/gif') || ($new_picture_type == 'image/jpeg') || ($new_picture_type == 'image/pjpeg') ||
  37.         ($new_picture_type == 'image/png')) && ($new_picture_size > 0) && ($new_picture_size <= MM_MAXFILESIZE) &&
  38.         ($new_picture_width <= MM_MAXIMGWIDTH) && ($new_picture_height <= MM_MAXIMGHEIGHT)) {
  39.         if ($_FILES['file']['error'] == 0) {
  40.           // Move the file to the target upload folder
  41.           $target = MM_UPLOADPATH . basename($new_picture);
  42.           if (move_uploaded_file($_FILES['new_picture']['tmp_name'], $target)) {
  43.             // The new picture file move was successful, now make sure any old picture is deleted
  44.             if (!empty($old_picture) && ($old_picture != $new_picture)) {
  45.               @unlink(MM_UPLOADPATH . $old_picture);
  46.             }
  47.           }
  48.           else {
  49.             // The new picture file move failed, so delete the temporary file and set the error flag
  50.             @unlink($_FILES['new_picture']['tmp_name']);
  51.             $error = true;
  52.             echo '<p class="error">Sorry, there was a problem uploading your picture.</p>';
  53.           }
  54.         }
  55.       }
  56.       else {
  57.         // The new picture file is not valid, so delete the temporary file and set the error flag
  58.         @unlink($_FILES['new_picture']['tmp_name']);
  59.         $error = true;
  60.         echo '<p class="error">Your picture must be a GIF, JPEG, or PNG image file no greater than ' . (MM_MAXFILESIZE / 1024) .
  61.           ' KB and ' . MM_MAXIMGWIDTH . 'x' . MM_MAXIMGHEIGHT . ' pixels in size.</p>';
  62.       }
  63.     }
  64.  
  65.     // Update the profile data in the database
  66.     if (!$error) {
  67.       if (!empty($first_name) && !empty($last_name) && !empty($gender) && !empty($birthdate) && !empty($city) && !empty($state)) {
  68.         // Only set the picture column if there is a new picture
  69.         if (!empty($new_picture)) {
  70.           $query = "UPDATE mismatch_user SET first_name = '$first_name', last_name = '$last_name', gender = '$gender', " .
  71.             " birthdate = '$birthdate', city = '$city', state = '$state', picture = '$new_picture' WHERE user_id = '$user_id'";
  72.         }
  73.         else {
  74.           $query = "UPDATE mismatch_user SET first_name = '$first_name', last_name = '$last_name', gender = '$gender', " .
  75.             " birthdate = '$birthdate', city = '$city', state = '$state' WHERE user_id = '$user_id'";
  76.         }
  77.         mysqli_query($dbc, $query);
  78.  
  79.         // Confirm success with the user
  80.         echo '<p>Your profile has been successfully updated. Would you like to <a href="viewprofile.php">view your profile</a>?</p>';
  81.  
  82.         mysqli_close($dbc);
  83.         exit();
  84.       }
  85.       else {
  86.         echo '<p class="error">You must enter all of the profile data (the picture is optional).</p>';
  87.       }
  88.     }
  89.   } // End of check for form submission
  90.   else {
  91.     // Grab the profile data from the database
  92.     $query = "SELECT first_name, last_name, gender, birthdate, city, state, picture FROM mismatch_user WHERE user_id = '$user_id'";
  93.     $data = mysqli_query($dbc, $query);
  94.     $row = mysqli_fetch_array($data);
  95.  
  96.     if ($row != NULL) {
  97.       $first_name = $row['first_name'];
  98.       $last_name = $row['last_name'];
  99.       $gender = $row['gender'];
  100.       $birthdate = $row['birthdate'];
  101.       $city = $row['city'];
  102.       $state = $row['state'];
  103.       $old_picture = $row['picture'];
  104.     }
  105.     else {
  106.       echo '<p class="error">There was a problem accessing your profile.</p>';
  107.     }
  108.   }
  109.  
  110.   mysqli_close($dbc);
  111. ?>
  112.  
  113.   <form enctype="multipart/form-data" method="post" action="<?PHP echo $_SERVER['PHP_SELF']; ?>">
  114.     <input type="hidden" name="MAX_FILE_SIZE" value="<?PHP echo MM_MAXFILESIZE; ?>" />
  115.     <fieldset>
  116.       <legend>Personal Information</legend>
  117.       <label for="firstname">First name:</label>
  118.       <input type="text" id="firstname" name="firstname" value="<?PHP if (!empty($first_name)) echo $first_name; ?>" />      <label for="lastname">Last name:</label>
  119.       <input type="text" id="lastname" name="lastname" value="<?PHP if (!empty($last_name)) echo $last_name; ?>" />      <label for="gender">Gender:</label>
  120.       <select id="gender" name="gender">
  121.         <option value="M" <?PHP if (!empty($gender) && $gender == 'M') echo 'selected = "selected"'; ?>>Male</option>
  122.         <option value="F" <?PHP if (!empty($gender) && $gender == 'F') echo 'selected = "selected"'; ?>>Female</option>
  123.       </select>      <label for="birthdate">Birthdate:</label>
  124.       <input type="text" id="birthdate" name="birthdate" value="<?PHP if (!empty($birthdate)) echo $birthdate; else echo 'YYYY-MM-DD'; ?>" />      <label for="city">City:</label>
  125.       <input type="text" id="city" name="city" value="<?PHP if (!empty($city)) echo $city; ?>" />      <label for="state">State:</label>
  126.       <input type="text" id="state" name="state" value="<?PHP if (!empty($state)) echo $state; ?>" />      <input type="hidden" name="old_picture" value="<?PHP if (!empty($old_picture)) echo $old_picture; ?>" />
  127.       <label for="new_picture">Picture:</label>
  128.       <input type="file" id="new_picture" name="new_picture" />
  129.       <?PHP if (!empty($old_picture)) {
  130.         echo '<img class="profile" src="' . MM_UPLOADPATH . $old_picture . '" alt="Profile Picture" />';
  131.       } ?>
  132.     </fieldset>
  133.     <input type="submit" value="Save Profile" name="submit" />
  134.   </form>
  135. </body>
  136. </html>
  137.  

(Добавление)
помогите! Пожалуйста
(Добавление)
Кто нить поможет мне???
 
 Top
esterio
Отправлено: 22 Июня, 2013 - 02:22:48
Post Id



Активный участник


Покинул форум
Сообщений всего: 5025
Дата рег-ции: Нояб. 2012  
Откуда: Украина, Львов


Помог: 127 раз(а)




setcookieкоторый должен идти перед выводом. также код стоит выкладивать только тот в котором проблема, а не весь где все навалено на кучу
 
 Top
Страниц (1): [1]
Сейчас эту тему просматривают: 0 (гостей: 0, зарегистрированных: 0)
« Вопросы новичков »


Все гости форума могут просматривать этот раздел.
Только зарегистрированные пользователи могут создавать новые темы в этом разделе.
Только зарегистрированные пользователи могут отвечать на сообщения в этом разделе.
 



Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB