Jump to content


Photo

Help, Form/MySQL Problem!


  • Please log in to reply
5 replies to this topic

#1 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 16 August 2006 - 05:57 AM

Hi I have an "account editor" on my site and it works.. here is the code for my "update email" form:
<?php 
if($_POST['updateI']){
$username = $_SESSION['username'];
$new_email = mysql_real_escape_string(trim($_POST['emailNew']));

$sql = "UPDATE `users` SET `email` = '$new_email' WHERE `username` = '$username'"; 
$query = mysql_query($sql) or die(mysql_error()); 
} 
?>
<?php
$sql = "SELECT * FROM users WHERE username = '$_SESSION[username]' LIMIT 1";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<b>Current E-mail: '" .$row['email']. "'</b>";
}
?>
<form action="" method="post">
      <table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td ><font color=black>New E-mail:</font></td><td><input type="text" name="emailNew" maxlength="30"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="updateI" value="-Update-"></td></tr>
</table>
    </form>
now that works fine. and here is my update Name code:
<?php 
if($_POST['updateFNAME']){
$username = $_SESSION['username'];
$new_name = mysql_real_escape_string(trim($_POST['fnameNew']));

$sql = "UPDATE `users` SET `fname` = '$new_name' WHERE `username` = '$username'"; 
$query = mysql_query($sql) or die(mysql_error()); 
} 
?>
<?php
$sql = "SELECT * FROM users WHERE username = '$_SESSION[username]' LIMIT 1";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<b>Current First Name: '" .$row['fname']. "'</b>";
}
?>
<form action="" method="post">
      <table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td ><font color=black>New First Name:</font></td><td><input type="text" name="fnameNew" maxlength="30"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="updateFNAME" value="-Update-"></td></tr>
</table>
    </form>
**NOW, heres my problem, I have a button that is supposed to change everything at once, cuz right now if you want to update any of those above, you need to press each single button for each item.. heres my code thats NOT WORK, that is suposed to combine bothe codes from above:
<?php 
if($_POST['updateALL']){
$username = $_SESSION['username'];
$new_name = mysql_real_escape_string(trim($_POST['fnameNew']));
$new_email = mysql_real_escape_string(trim($_POST['emailNew']));

$sql = "UPDATE `users` SET `fname` = '$new_name', `email` = '$new_email' WHERE `username` = '$username'"; 
$query = mysql_query($sql) or die(mysql_error()); 
} 
?>
<form action="" method="post">
      <table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td colspan="2" align="right"><input type="submit" name="updateALL" value="-Save All-"></td></tr>
</table>
    </form>
</center>
How can I change that to update all the fields at once??
Link shortener with advanced, detailed statistics:

http://tyny.us/

#2 stickman

stickman
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 16 August 2006 - 06:03 AM

This line:

<input type="text" name="fnameNew" maxlength="30">

And this line:

<input type="text" name="emailNew" maxlength="30">

Both have to be within the <form> tags for the update all form or the the values $_POST['fnameNew'] and $_POST['emailNew'] will both be empty.

..:: FREE NINTENDO WII OR $250 CASH ::..
..:: Click here for more information ::..


#3 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 16 August 2006 - 06:13 AM

wont ading those lines add text boxes?? i dont want that, i just want tthe update all button to update all the inromation at once, i only want one text box for each piece of information
Link shortener with advanced, detailed statistics:

http://tyny.us/

#4 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 16 August 2006 - 06:18 AM

A submit button only sends data within that form.  There is no data in your form and therefore nothing is being sent.
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#5 stickman

stickman
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 16 August 2006 - 06:24 AM

wont ading those lines add text boxes?? i dont want that, i just want tthe update all button to update all the inromation at once, i only want one text box for each piece of information

Yeah. You should just create one form with three different submit buttons with three different names. If you have three different forms, then you'll have to have six different text boxes (in your case).

..:: FREE NINTENDO WII OR $250 CASH ::..
..:: Click here for more information ::..


#6 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 16 August 2006 - 06:25 AM

Hey I got it! . heres what i ended up with:
<center> 
<?php 
if($_POST['updateI']){
$username = $_SESSION['username'];
$new_email = mysql_real_escape_string(trim($_POST['emailNew']));

$sql = "UPDATE `users` SET `email` = '$new_email' WHERE `username` = '$username'"; 
$query = mysql_query($sql) or die(mysql_error()); 
} 
?>
<?php
$sql = "SELECT * FROM users WHERE username = '$_SESSION[username]' LIMIT 1";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<b>Current E-mail: '" .$row['email']. "'</b>";
}
?>
<form action="" method="post">
      <table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td ><font color=black>New E-mail:</font></td><td><input type="text" name="emailNew" maxlength="30"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="updateI" value="-Update-"></td></tr>
</table>
<! - END EMAIL - !>
<hr width=35%>
<! - UPDATE FNAME - !>
<?php 
if($_POST['updateFNAME']){
$username = $_SESSION['username'];
$new_name = mysql_real_escape_string(trim($_POST['fnameNew']));

$sql = "UPDATE `users` SET `fname` = '$new_name' WHERE `username` = '$username'"; 
$query = mysql_query($sql) or die(mysql_error()); 
} 
?>
<?php
$sql = "SELECT * FROM users WHERE username = '$_SESSION[username]' LIMIT 1";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<b>Current First Name: '" .$row['fname']. "'</b>";
}
?>
      <table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td ><font color=black>New First Name:</font></td><td><input type="text" name="fnameNew" maxlength="30"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="updateFNAME" value="-Update-"></td></tr>
</table>
<table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td colspan="2" align="right"><input type="submit" name="updateALL" value="-Save All-"></td></tr>
</table>
    </form>
</center>
<!-  END FNAME - !>

<! - UPDATE ALL - !>
<?php 
if($_POST['updateALL']){
$username = $_SESSION['username'];
$new_name = mysql_real_escape_string(trim($_POST['fnameNew']));
$new_email = mysql_real_escape_string(trim($_POST['emailNew']));

$sql = "UPDATE `users` SET `fname` = '$new_name', `email` = '$new_email' WHERE `username` = '$username'"; 
$query = mysql_query($sql) or die(mysql_error()); 
} 
?>
<!-  END ALL - !>

Link shortener with advanced, detailed statistics:

http://tyny.us/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users