•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 425,928 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,655 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1544 | Replies: 2
![]() |
•
•
Join Date: Jun 2006
Posts: 29
Reputation:
Rep Power: 3
Solved Threads: 0
Ive done several echo's and such to make sure info is in my variables before. When i do the first update on the page, i think the second one is running too. Either way, my record is being deleted for whatever reason...
Aside from some help with the current setup, i would like to know if there is another way of splitting up the sumbits, or if the current way i am doing this is sufficient enough.
[php]<?
// editusernew.php
// by Ryan Wood
// TODO: Gets a user name then sets all of the information in input boxes to be UPDATED.
// REQUIRES //
require ($_SERVER["DOCUMENT_ROOT"]."/backend/config.php");
$connection = @mysql_connect($server, $db_user, $db_password) or die("Error: Could not connect to MySQL server");
mysql_select_db($database, $connection);
require_once($_SERVER['DOCUMENT_ROOT'].'/backend/checklogin.php');
// END REQUIRES //
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Edit User</title>
</head>
<body>
<font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<form action="<?php echo $PHP_SELF; ?>" method="get">
User : <input name="user" type="text" maxlength="64"><br><br>
<input value="Submit" type="submit">
</form>
<?
$user = $_GET["user"];
$query = "SELECT * FROM userinfo WHERE user_name ='$user'";
$result = mysql_query($query);
$id = 0;
if(mysql_num_rows($result) > 0)
{
$row = mysql_fetch_object($result);
$id = $row->autoID;
?>
<form action='<?php echo $PHP_SELF; ?>' method='post'>
Username : <input name='txt_username' type='text' maxlength='64' value="<? echo $row->user_name; ?>">
<br><br>
Password : <input name='txt_password' type='text' maxlength='64'>
<br><br>
Email : <input name='txt_email' type='text' maxlength='64' value="<? echo $row->user_email; ?>">
<br><br>
Percent Complete : <input name='txt_percentcomplete' type='text' maxlength='64' value="<? echo $row->percentcomplete; ?>"> <br><br>
Temporary Price : <input name='txt_tempprice' type='text' maxlength='64' value="<? echo $row->tempprice; ?>">
<br><br>
Amount Paid : <input name='txt_amountpaid' type='text' maxlength='64' value="<? echo $row->amountpaid; ?>">
<br><br>
Date for completion : <input name='txt_datecomplete' type='text' maxlength='64' value="<? echo $row->dateforcomplete; ?>"> <br><br>
<input value='Update' type='submit'>
</form>
<br>
<?
}
$txt_username = $_POST["txt_username"];
$txt_email = $_POST["txt_email"];
$txt_percentcomplete = $_POST["txt_percentcomplete"];
$txt_tempprice = $_POST["txt_tempprice"];
$txt_amountpaid = $_POST["txt_amountpaid"];
$txt_datecomplete = $_POST["txt_datecomplete"];
/*if( ($txt_username != $row->user_name) ||
($txt_email != $row->user_email) ||
($txt_percentcomplete != $row->percentcomplete) ||
($txt_tempprice != $row->tempprice) ||
($txt_amountpaid != $row->amountpaid) ||
($txt_datecomplete != $row->dateforcomplete) )
{*/
$query2 = "UPDATE userinfo SET user_name='$txt_username' WHERE autoID='$id'";
mysql_query($query2, $connection);
//}
?>
</font>
</body>
</html>
[/php]
Aside from some help with the current setup, i would like to know if there is another way of splitting up the sumbits, or if the current way i am doing this is sufficient enough.
[php]<?
// editusernew.php
// by Ryan Wood
// TODO: Gets a user name then sets all of the information in input boxes to be UPDATED.
// REQUIRES //
require ($_SERVER["DOCUMENT_ROOT"]."/backend/config.php");
$connection = @mysql_connect($server, $db_user, $db_password) or die("Error: Could not connect to MySQL server");
mysql_select_db($database, $connection);
require_once($_SERVER['DOCUMENT_ROOT'].'/backend/checklogin.php');
// END REQUIRES //
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Edit User</title>
</head>
<body>
<font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<form action="<?php echo $PHP_SELF; ?>" method="get">
User : <input name="user" type="text" maxlength="64"><br><br>
<input value="Submit" type="submit">
</form>
<?
$user = $_GET["user"];
$query = "SELECT * FROM userinfo WHERE user_name ='$user'";
$result = mysql_query($query);
$id = 0;
if(mysql_num_rows($result) > 0)
{
$row = mysql_fetch_object($result);
$id = $row->autoID;
?>
<form action='<?php echo $PHP_SELF; ?>' method='post'>
Username : <input name='txt_username' type='text' maxlength='64' value="<? echo $row->user_name; ?>">
<br><br>
Password : <input name='txt_password' type='text' maxlength='64'>
<br><br>
Email : <input name='txt_email' type='text' maxlength='64' value="<? echo $row->user_email; ?>">
<br><br>
Percent Complete : <input name='txt_percentcomplete' type='text' maxlength='64' value="<? echo $row->percentcomplete; ?>"> <br><br>
Temporary Price : <input name='txt_tempprice' type='text' maxlength='64' value="<? echo $row->tempprice; ?>">
<br><br>
Amount Paid : <input name='txt_amountpaid' type='text' maxlength='64' value="<? echo $row->amountpaid; ?>">
<br><br>
Date for completion : <input name='txt_datecomplete' type='text' maxlength='64' value="<? echo $row->dateforcomplete; ?>"> <br><br>
<input value='Update' type='submit'>
</form>
<br>
<?
}
$txt_username = $_POST["txt_username"];
$txt_email = $_POST["txt_email"];
$txt_percentcomplete = $_POST["txt_percentcomplete"];
$txt_tempprice = $_POST["txt_tempprice"];
$txt_amountpaid = $_POST["txt_amountpaid"];
$txt_datecomplete = $_POST["txt_datecomplete"];
/*if( ($txt_username != $row->user_name) ||
($txt_email != $row->user_email) ||
($txt_percentcomplete != $row->percentcomplete) ||
($txt_tempprice != $row->tempprice) ||
($txt_amountpaid != $row->amountpaid) ||
($txt_datecomplete != $row->dateforcomplete) )
{*/
$query2 = "UPDATE userinfo SET user_name='$txt_username' WHERE autoID='$id'";
mysql_query($query2, $connection);
//}
?>
</font>
</body>
</html>
[/php]
Hi Woobag,
you should use
instead of There is no problem with your UPDATE statement since php echo it nicely,but you've used $PHP_SELF incorrectly.
I hope this help you.
Good luck.
you should use
•
•
•
•
'<?php echo $_SERVER['PHP_SELF']; ?>'
•
•
•
•
'<?php echo $PHP_SELF; ?>'
I hope this help you.
Good luck.
Last edited by mostafadotnet : Aug 25th, 2006 at 8:41 am.
•
•
Join Date: Jun 2006
Posts: 29
Reputation:
Rep Power: 3
Solved Threads: 0
Thanks for the help mostafadotnet, but my problem appeared to be not the actual update query itself. Once i hit the first submit button the query was running with an "empty" value because it had not gotten the values from the POST. Therefore i simply adding an if statement correcting this flaw. Took me a week of on and off debugging to find that thing!
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- How can i update a query that have more than 3 tables using adodc in vb? (Visual Basic 4 / 5 / 6)
- CD - DVD ROM Drive not working properly (Storage)
- Need a Serial to usb driver (Peripherals)
- Need update query--Remove the coma "," (PHP)
- Error while trying the update query (ASP)
- Intel D815EEA PCI cards are not working properly (Windows NT / 2000 / XP / 2003)
Other Threads in the PHP Forum
- Previous Thread: Can't open any xml file
- Next Thread: Help Guys!


Linear Mode