Current location: Hot Scripts Forums » Programming Languages » PHP » edit problem


edit problem

Reply
  #1 (permalink)  
Old 10-28-11, 05:59 PM
williamh26 williamh26 is offline
Wannabe Coder
 
Join Date: Jul 2010
Posts: 132
Thanks: 2
Thanked 0 Times in 0 Posts
edit problem

I wanna try to edit my customers but i have an error... can someone help me
PHP Code:

<?php # edit_user.php


// This page edits a user.
// This page is accessed through view_users.php.

$page_title 'Edit a User';
include (
'./includes/header.html');

// Check for a valid user ID, through GET or POST.
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) )
   { 
// Accessed through view_users.php
    
$id $_GET['id'];

} elseif ( (isset(
$_POST['id'])) && (is_numeric($_POST['id'])) )
   { 
// Form has been submitted.
    
$id $_POST['id'];
} else { 
// No valid ID, kill the script.
    
echo '<h1 id="mainhead">Page Error</h1>
    <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'
;
    include (
'./includes/footer.html');
    exit();
}

require_once (
'./includes/mysql_connect.php'); // Connect to the db.

// Check if the form has been submitted.
if (isset($_POST['submitted'])) {

    
$errors = array(); // Initialize error array.

    // Check for a first name.
    
if (empty($_POST['first_name'])) {
       
$errors[] = 'You forgot to enter your first name.';
    } else {
       
$fn escape_data($_POST['first_name']);
    }

    
// Check for a last name.
    
if (!empty($_POST['last_name'])) {
       
$errors[] = 'You forgot to enter your last name.';
    } else {
       
$ln escape_data($_POST['last_name']);
    }

    
// Check for an email address.
    
if (empty($_POST['email'])) {
       
$errors[] = 'You forgot to enter your email address.';
    } else {
       
$e escape_data($_POST['email']);
    }

    if (empty(
$errors)) { // If everything's OK.

       //  Test for unique email address.
       
$query "SELECT user_id FROM users WHERE email='$e' AND user_id != $id";
       
$result mysql_query($query);
       if (
mysql_num_rows($result) == 0) {

          
// Make the query.

$query "UPDATE users SET first_name='$fn', last_name='$ln', email='$e'
            WHERE user_id=
$id";
          
$result mysql_query ($query) or die (mysql_error()); // Run the query.
          
if($result)
          {

          if (
mysql_affected_rows() == 1) { // If it ran OK.
          
{
          
// Print a message.
          
echo '<h1 id="mainhead">Edit a User</h1>
          <p>The user has been edited.</p><p><br /><br /></p>'
;


          }

           
// If it did not run OK.
          
echo '<h1 id="mainhead">System Error</h1>
          <p class="error">The user could not be edited due to a system error.
          We apologize for any inconvenience.</p>'
;
           
// Public message.
          
echo '<p>' mysql_error() . '
           }
          }
          <br /><br />
          Query: ' 
$query '</p>'// Debugging message.
          
include ('./includes/footer.html');
          exit();
  
// End of if (empty($errors)) IF.
 
$query "SELECT first_name, last_name, email FROM users WHERE user_id=$id";
 
$result = @mysql_query ($query); // Run the query.

if (mysql_num_rows($result) == 1) { // Valid user ID, show the form.
    // Get the user's information.
    
$row mysql_fetch_array ($resultMYSQL_NUM);
    
// Create the form.
    
echo '<h2>Edit a User</h2>
<form action="edit_user.php" method="post">
<p>First Name: <input type="text" name="first_name" size="15"
   maxlength="15" value="' 
$row[0] . '" /></p>
<p>Last Name: <input type="text" name="last_name" size="15"
   maxlength="30" value="' 
$row[1] . '" /></p>
<p>Email Address: <input type="text" name="email" size="20"
   maxlength="40" value="' 
$row[2] . '"  /></p>
<p><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE" />
<input type="hidden" name="id" value="' 
$id '" />
</form>'
;

 
// Not a valid user ID.
    
echo '<h1 id="mainhead">Page Error</h1>
    <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'
;



mysql_close(); // Close the database connection.
 
?>

  include ('./includes/footer.html');
The error said that
Parse error: syntax error, unexpected $end in C:\wamp\www\RegistrationChemath.com\edit_user.php on line 122

but it is no line 122???

thanks for ur help
Reply With Quote
  #2 (permalink)  
Old 10-31-11, 05:33 AM
hemi hemi is offline
Wannabe Coder
 
Join Date: Aug 2009
Posts: 117
Thanks: 15
Thanked 0 Times in 0 Posts
The error is not line 122 or it is not related to mysql query. It is regarding the if else brackets. u did not close three if loops so it is giving u error.

Just check this out


<?php # edit_user.php



// This page edits a user.

// This page is accessed through view_users.php.



$page_title = 'Edit a User';

include ('./includes/header.html');



// Check for a valid user ID, through GET or POST.

if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) )

{ // Accessed through view_users.php

$id = $_GET['id'];



} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) )

{ // Form has been submitted.

$id = $_POST['id'];

} else { // No valid ID, kill the script.

echo '<h1 id="mainhead">Page Error</h1>

<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';

include ('./includes/footer.html');

exit();

}



require_once ('./includes/mysql_connect.php'); // Connect to the db.



// Check if the form has been submitted.

if (isset($_POST['submitted']))
{

$errors = array(); // Initialize error array.
// Check for a first name.

if (empty($_POST['first_name']))
{

$errors[] = 'You forgot to enter your first name.';

} else
{
$fn = escape_data($_POST['first_name']);

}



// Check for a last name.

if (!empty($_POST['last_name'])) {

$errors[] = 'You forgot to enter your last name.';

} else {

$ln = escape_data($_POST['last_name']);

}



// Check for an email address.

if (empty($_POST['email'])) {

$errors[] = 'You forgot to enter your email address.';

} else {

$e = escape_data($_POST['email']);

}



if (empty($errors)) { // If everything's OK.



// Test for unique email address.

$query = "SELECT user_id FROM users WHERE email='$e' AND user_id != $id";

$result = mysql_query($query);

if (mysql_num_rows($result) == 0) {



// Make the query.



$query = "UPDATE users SET first_name='$fn', last_name='$ln', email='$e' WHERE user_id=$id";

$result = mysql_query ($query) or die (mysql_error()); // Run the query.

if($result)

{



if (mysql_affected_rows() == 1) // If it ran OK.

{

// Print a message.

echo '<h1 id="mainhead">Edit a User</h1>

<p>The user has been edited.</p><p><br /><br /></p>';





}



// If it did not run OK.

echo '<h1 id="mainhead">System Error</h1>

<p class="error">The user could not be edited due to a system error.

We apologize for any inconvenience.</p>';

// Public message.

echo '<p>' . mysql_error() . '



<br /><br />

Query: ' . $query . '</p>'; // Debugging message.
}

}

include ('./includes/footer.html');

exit();

// End of if (empty($errors)) IF.

$query = "SELECT first_name, last_name, email FROM users WHERE user_id=$id";

$result = @mysql_query ($query); // Run the query.



if (mysql_num_rows($result) == 1) { // Valid user ID, show the form.

// Get the user's information.

$row = mysql_fetch_array ($result, MYSQL_NUM);

// Create the form.

echo '<h2>Edit a User</h2>

<form action="edit_user.php" method="post">

<p>First Name: <input type="text" name="first_name" size="15"

maxlength="15" value="' . $row[0] . '" /></p>

<p>Last Name: <input type="text" name="last_name" size="15"

maxlength="30" value="' . $row[1] . '" /></p>

<p>Email Address: <input type="text" name="email" size="20"

maxlength="40" value="' . $row[2] . '" /></p>

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

<input type="hidden" name="submitted" value="TRUE" />

<input type="hidden" name="id" value="' . $id . '" />

</form>';



// Not a valid user ID.

echo '<h1 id="mainhead">Page Error</h1>

<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';



}}} // close these loops according to ur logic.



mysql_close(); // Close the database connection.





include ('./includes/footer.html');
?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
login, roles problem dbrook007 ASP.NET 10 11-10-06 03:42 PM
Form Display Problem neevrap02 Visual Basic 1 09-05-06 05:18 AM
edit form problem using nl2br and str_replace Tim Mousel PHP 1 02-12-05 02:05 AM
Edit page infrustructure - design questions davidklonski JavaScript 2 06-30-04 05:54 PM
can't edit multiple rows at the same time conundrum PHP 2 04-01-04 12:50 AM


All times are GMT -5. The time now is 08:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.