Jump to content

Recommended Posts

I have a form that is in my user cp that allows users to update information. When the click on edit display this page with the form pops up with their current information. I added all the echos and the form displayed all the current information as designed. Then when I go to add the information to update the information the form doesn't display the information anymore and the form doesn't update. I have been going over this for two days and can't see where I am going wrong.

 

Here is the code for the entire file.

 

<?php

require ('session.php');
include ('db_connect.php');

  $email = $_SESSION['email'];
  $sql = "SELECT * FROM users WHERE email='$email'";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_array($result);
      $id = $row["id"];
      $displayname = $row['displayname'];
      $displaytype = $row['displaytype'];
      $description = $row['description'];
      $address = $row['address'];
      $address2 = $row['address2'];
      $city = $row['city'];
      $state = $row['state'];
      $postal = $row['postal'];
      $country = $row['country'];
      $website = $row['website'];
    } else {
      die("No user found");
    }
  } else {
    die(mysql_error());
  }

$email = $_SESSION['email'];

      $displayname = $_POST['displayname'];
      $displaytype = $_POST['displaytype'];
      $description = $_POST['description'];
      $address = $_POST['address'];
      $address2 = $_POST['address2'];
      $city = $_POST['city'];
      $state = $_POST['state'];
      $postal = $_POST['postal'];
      $country = $_POST['country'];
      $website = $_POST['website'];

if($_POST['submit']) {

mysql_query("UPDATE users SET displayname = '$displayname', displaytype = '$displaytype', description = '$description', address = '$address', address2 = '$address2', city = '$city', state = '$state', postal = '$postal', country = '$country', website = '$website'
WHERE email='$email'");

} else {

?>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>	
	<table width="100%" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">

<td><a href="user.php?action=editprofile">Edit Profile</a> | <a href="submit.php">Add Entry</a> | <a href="user.php?action=edit">Edit Display</a> | <a href="user.php?action=images">Edit Images</a> | <a href="logout.php">Log Out</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>  </td>
<tr>
<td>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr>
  <td>Display Name*</td><td><input name="displayname" value="<?php echo $displayname; ?>" size="40" type="text"></td></tr>

<tr>
  <td>Display Type*</td><td><select name="displaytype"><option value="Residential">Residential</option><option value="Neighborhood">Neighborhood</option><option value="Commercial">Commercial</option><option value="City/Government">City/Government</option><option value="Sponsored">Sponsored</option></select></td></tr>

<tr><td>Description*</td><td><textarea name="description" cols="30" rows="5"><?php echo $description; ?></textarea></td></tr>

<tr><td>Address*</td><td><input name="address" value="<?php echo $address; ?>" size="40" type="text"></td></tr>

<tr><td>Address 2</td><td><input name="address2" value="<?php echo $address2; ?>" size="40" type="text"></td></tr>

<tr><td>City*</td><td><input name="city" size="30" type="text" value="Mesquite"></td></tr>

<tr><td>State/Province*</td><td><input name="state" size="30" type="text" value="Texas"></td></tr>

<tr><td>Postal Code*</td><td><select name="postal"><option value="75149">75149</option><option value="75150">75150</option><option value="75180">75180</option><option value="75181">75181</option><option value="75185">75185</option><option value="75187">75187</option></select></td></tr>

<tr><td>Country*</td><td><input name="country" size="30" type="text" value="United States"></td></tr>

<tr><td>Website</td><td><input name="website" size="50" value="<?php echo $website; ?>" type="text"></td></tr>

<tr><td>  </td></tr>

<tr>

<td colspan="2" style="border-top: 1px solid black;" align="left">

<br />

* Fields are required.</td>

<td  colspan="2" style="border-top: 1px solid black;" align="right">

<br />

<input type='submit' name='submit' value='Update'></td></tr>

</tbody>
    </table></form>
</td>
   </tr>
       </table>
<?php
}
?>

 

Any help would be great

 

-Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/87882-solved-form-not-updating-on-submit/
Share on other sites

The first part retrieves a user record or dies, which is fine

2nd part, it gets the POST info, which isn't ok.

3rd it checks 'submit' for? and does an update OR it displays the user info

 

on 2nd part, why replace variables if submit wasn't pushed?

on 1st pass, ya will get empty variables, cuz there is no POST info (so fields will be blank)

on 3rd, use isset($_POST['submit']) now it's checking the existance of a POST

move the 2nd part into this section of the if statement

 

remove the } else { and it's matcing }

 

okay now ya got that done

move the if $_POST section above the 1st part

this way it updates the record, before retrieving the record

than it always will display the record.

 

 

that shud do it

The first part retrieves a user record or dies, which is fine

2nd part, it gets the POST info, which isn't ok.

3rd it checks 'submit' for? and does an update OR it displays the user info

 

on 2nd part, why replace variables if submit wasn't pushed?

on 1st pass, ya will get empty variables, cuz there is no POST info (so fields will be blank)

on 3rd, use isset($_POST['submit']) now it's checking the existance of a POST

move the 2nd part into this section of the if statement

 

remove the } else { and it's matcing }

 

okay now ya got that done

move the if $_POST section above the 1st part

this way it updates the record, before retrieving the record

than it always will display the record.

 

 

that shud do it

 

 

Ok I made the suggested changes and now I am getting this error. Did I not change to code right?

 

Parse error: syntax error, unexpected T_VARIABLE in /home/mesquit1/public_html/local/update.php on line 10

 

Here is the updated code

 

<?php

require ('session.php');
include ('db_connect.php');

$email = $_SESSION['email'];

      isset($_POST['submit'])

      $displayname = $_POST['displayname'];
      $displaytype = $_POST['displaytype'];
      $description = $_POST['description'];
      $address = $_POST['address'];
      $address2 = $_POST['address2'];
      $city = $_POST['city'];
      $state = $_POST['state'];
      $postal = $_POST['postal'];
      $country = $_POST['country'];
      $website = $_POST['website'];

mysql_query("UPDATE users SET displayname = '$displayname', displaytype = '$displaytype', description = '$description', address = '$address', address2 = '$address2', city = '$city', state = '$state', postal = '$postal', country = '$country', website = '$website'
WHERE email='$email'");

  $email = $_SESSION['email'];
  $sql = "SELECT * FROM users WHERE email='$email'";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_array($result);
      $id = $row["id"];
      $displayname = $row['displayname'];
      $displaytype = $row['displaytype'];
      $description = $row['description'];
      $address = $row['address'];
      $address2 = $row['address2'];
      $city = $row['city'];
      $state = $row['state'];
      $postal = $row['postal'];
      $country = $row['country'];
      $website = $row['website'];
    } else {
      die("No user found");
    }
  } else {
    die(mysql_error());
  }

?>

 

-Thanks

Ok maybe I need to be a little clearer on what this form does. When you first register you will be presented with this form to submit your display. It will be secured by sessions once I am finished with it.

 

http://mesquitechristmas.com/local/submit.php

 

Then in the User CP for registered users which is secured now you have an option to update this information if you need to. So once you click on Edit Display it will show you a form like the one in the link above but it will be filled in with your current information that you entered previsouly from the form in that link. I was able to show that information before I was suggested I move the post above the output. Now not only does it not show the information in the form anymore, but it doesn't allow you to update it ether so I am going back to the at least half working code that at least displayed the information. Now If I can get it to update the information if you chose to change any of it that would be great. So here is the current code

 

<?php

require ('session.php');
include ('db_connect.php');

  $email = $_SESSION['email'];
  $sql = "SELECT * FROM users WHERE email='$email'";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_array($result);
      $id = $row["id"];
      $displayname = $row['displayname'];
      $displaytype = $row['displaytype'];
      $description = $row['description'];
      $address = $row['address'];
      $address2 = $row['address2'];
      $city = $row['city'];
      $state = $row['state'];
      $postal = $row['postal'];
      $country = $row['country'];
      $website = $row['website'];
    } else {
      die("No user found");
    }
  } else {
    die(mysql_error());
  }

$email = $_SESSION['email'];

      if($_POST['submit']) {

      $displayname = $_POST['displayname'];
      $displaytype = $_POST['displaytype'];
      $description = $_POST['description'];
      $address = $_POST['address'];
      $address2 = $_POST['address2'];
      $city = $_POST['city'];
      $state = $_POST['state'];
      $postal = $_POST['postal'];
      $country = $_POST['country'];
      $website = $_POST['website'];

mysql_query("UPDATE users SET displayname = '$displayname', displaytype = '$displaytype', description = '$description', address = '$address', address2 = '$address2', city = '$city', state = '$state', postal = '$postal', country = '$country', website = '$website'
WHERE email='$email'");

} else {

?>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>	
	<table width="100%" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">

<td><a href="user.php?action=editprofile">Edit Profile</a> | <a href="submit.php">Add Entry</a> | <a href="user.php?action=edit">Edit Display</a> | <a href="user.php?action=images">Edit Images</a> | <a href="logout.php">Log Out</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>  </td>
<tr>
<td>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr>
  <td>Display Name*</td><td><input name="displayname" value="<?php echo $displayname; ?>" size="40" type="text"></td></tr>

<tr>
  <td>Display Type*</td><td><select name="displaytype"><option value="Residential">Residential</option><option value="Neighborhood">Neighborhood</option><option value="Commercial">Commercial</option><option value="City/Government">City/Government</option><option value="Sponsored">Sponsored</option></select></td></tr>

<tr><td>Description*</td><td><textarea name="description" cols="30" rows="5"><?php echo $description; ?></textarea></td></tr>

<tr><td>Address*</td><td><input name="address" value="<?php echo $address; ?>" size="40" type="text"></td></tr>

<tr><td>Address 2</td><td><input name="address2" value="<?php echo $address2; ?>" size="40" type="text"></td></tr>

<tr><td>City*</td><td><input name="city" size="30" type="text" value="Mesquite"></td></tr>

<tr><td>State/Province*</td><td><input name="state" size="30" type="text" value="Texas"></td></tr>

<tr><td>Postal Code*</td><td><select name="postal"><option value="75149">75149</option><option value="75150">75150</option><option value="75180">75180</option><option value="75181">75181</option><option value="75185">75185</option><option value="75187">75187</option></select></td></tr>

<tr><td>Country*</td><td><input name="country" size="30" type="text" value="United States"></td></tr>

<tr><td>Website</td><td><input name="website" size="50" value="<?php echo $website; ?>" type="text"></td></tr>

<tr><td>  </td></tr>

<tr>

<td colspan="2" style="border-top: 1px solid black;" align="left">

<br />

* Fields are required.</td>

<td  colspan="2" style="border-top: 1px solid black;" align="right">

<br />

<input type='submit' name='submit' value='Update'></td></tr>

</tbody>
    </table></form>
</td>
   </tr>
       </table>
<?php
}
?>

 

-Thanks

 

 

try this

<?php

require ('session.php');
include ('db_connect.php');

  $email = $_SESSION['email'];
if(isset($_POST['submit'])) {

      $displayname = $_POST['displayname'];
      $displaytype = $_POST['displaytype'];
      $description = $_POST['description'];
      $address = $_POST['address'];
      $address2 = $_POST['address2'];
      $city = $_POST['city'];
      $state = $_POST['state'];
      $postal = $_POST['postal'];
      $country = $_POST['country'];
      $website = $_POST['website'];

mysql_query("UPDATE users SET displayname = '$displayname', displaytype = '$displaytype', description = '$description', address = '$address', address2 = '$address2', city = '$city', state = '$state', postal = '$postal', country = '$country', website = '$website' WHERE email='$email'");

}
  $sql = "SELECT * FROM users WHERE email='$email'";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_array($result);
      $id = $row["id"];
      $displayname = $row['displayname'];
      $displaytype = $row['displaytype'];
      $description = $row['description'];
      $address = $row['address'];
      $address2 = $row['address2'];
      $city = $row['city'];
      $state = $row['state'];
      $postal = $row['postal'];
      $country = $row['country'];
      $website = $row['website'];
    } else {
      die("No user found");
    }
  } else {
    die(mysql_error());
  }

?>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>	
	<table width="100%" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">

<td><a href="user.php?action=editprofile">Edit Profile</a> | <a href="submit.php">Add Entry</a> | <a href="user.php?action=edit">Edit Display</a> | <a href="user.php?action=images">Edit Images</a> | <a href="logout.php">Log Out</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>  </td>
<tr>
<td>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr>
  <td>Display Name*</td><td><input name="displayname" value="<?php echo $displayname; ?>" size="40" type="text"></td></tr>

<tr>
  <td>Display Type*</td><td><select name="displaytype"><option value="Residential">Residential</option><option value="Neighborhood">Neighborhood</option><option value="Commercial">Commercial</option><option value="City/Government">City/Government</option><option value="Sponsored">Sponsored</option></select></td></tr>

<tr><td>Description*</td><td><textarea name="description" cols="30" rows="5"><?php echo $description; ?></textarea></td></tr>

<tr><td>Address*</td><td><input name="address" value="<?php echo $address; ?>" size="40" type="text"></td></tr>

<tr><td>Address 2</td><td><input name="address2" value="<?php echo $address2; ?>" size="40" type="text"></td></tr>

<tr><td>City*</td><td><input name="city" size="30" type="text" value="Mesquite"></td></tr>

<tr><td>State/Province*</td><td><input name="state" size="30" type="text" value="Texas"></td></tr>

<tr><td>Postal Code*</td><td><select name="postal"><option value="75149">75149</option><option value="75150">75150</option><option value="75180">75180</option><option value="75181">75181</option><option value="75185">75185</option><option value="75187">75187</option></select></td></tr>

<tr><td>Country*</td><td><input name="country" size="30" type="text" value="United States"></td></tr>

<tr><td>Website</td><td><input name="website" size="50" value="<?php echo $website; ?>" type="text"></td></tr>

<tr><td>  </td></tr>

<tr>

<td colspan="2" style="border-top: 1px solid black;" align="left">

<br />

* Fields are required.</td>

<td  colspan="2" style="border-top: 1px solid black;" align="right">

<br />

<input type='submit' name='submit' value='Update'></td></tr>

</tbody>
    </table></form>
</td>
   </tr>
       </table>

I was wondering if the form is not working because of where it is pointing.

 

I have this for the action

 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

 

The url is actually.

 

user.php?action=edit&id=X

 

Where X is the number of the users display being edited. When you hit submit to edit the form it returns to just

 

user.php

 

So could that be the problem where the script is being called?

 

I have been working on this for about 5 hrs strait since my last post and I have tried everything and out of options. I hope someone can help

 

-Thanks

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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