473,508 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Display and Update record in php

8 New Member
I have problem in retrieving record from mysql using php form, I was able to retrieve the record, if I edit, the changes is not updated in mysql.
find below my code
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <?php
  4. $db = mysql_connect("localhost", "root");
  5. mysql_select_db("k1",$db);
  6. $id = $_POST["id"]; 
  7. echo $id;
  8. if ($submit) {
  9. $first  = $_POST['first'];
  10. $last = $_POST['last'];
  11. $address = $_POST['address'];
  12. $position = $_POST['position'];
  13. $sql = "UPDATE 'employees' SET 'first'='$first','last'='$last','address'='$address','position'='$position' WHERE 'id'='$id'";
  14. $result = mysql_query($sql);
  15. echo $first;
  16. echo "Thank you! Information updated.\n";
  17. } else {
  18. if ($id) {
  19. $sql = "SELECT * FROM employees WHERE id=$id";
  20. $result = mysql_query($sql);
  21. $myrow = mysql_fetch_array($result);
  22. $first  = $myrow['1'];
  23. $last = $myrow['2'];
  24. $address = $myrow['3'];
  25. $position = $myrow['4'];
  26. $id = $myrow['id'];
  27. $submit = 'submit';
  28. }
  29. }
  30. ?>
  31. <form method="post" action="<?php echo $PHP_SELF?>">
  32. <input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
  33. First name:<input type="Text" name="first" value="<?php echo $first ?>"><br>
  34. Last name:<input type="Text" name="last" value="<?php echo $last ?>"><br>
  35. Address:<input type="Text" name="address" value="<?php echo $address ?>"><br>
  36. Position:<input type="Text" name="position" value="<?php echo $position ?>"><br>
  37. <input type="Submit" name="submit" value="Enter information">
  38. </form>
  39. </body>
  40. </html>
[Please use CODE tags when posting source code. Thanks! --pbmods]
Jun 22 '07 #1
4 2219
Purple
404 Recognized Expert Contributor
Hi Bakarre and welcome to TSDN !!

Can you take a look at

this excellent post by Motoma where he works through options to get debug output from PHP. I suspect from looking at your code you have not got error messages turned on.

Purple
Jun 22 '07 #2
Purple
404 Recognized Expert Contributor
And try this

[PHP]<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("k1",$db);
if(isset($_POST["id"])) $id = $_POST["id"];
//echo $id;
if (isset($_POST['submit']))
{
$first = $_POST['first'];
$last = $_POST['last'];
$address = $_POST['address'];
$position = $_POST['position'];
$sql = "UPDATE 'employees' SET 'first'='$first','last'='$last','address'='$addres s','position'='$position' WHERE 'id'='$id'";
$result = mysql_query($sql);
echo $first;
echo "Thank you! Information updated.\n";
}
elseif (isset($id))
{
$sql = "SELECT * FROM employees WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$first = $myrow['1'];
$last = $myrow['2'];
$address = $myrow['3'];
$position = $myrow['4'];
$id = $myrow['id'];
$submit = 'submit';
}
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
First name:<input type="Text" name="first" value="<?php echo $first ?>"><br>
Last name:<input type="Text" name="last" value="<?php echo $last ?>"><br>
Address:<input type="Text" name="address" value="<?php echo $address ?>"><br>
Position:<input type="Text" name="position" value="<?php echo $position ?>"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
</body>
</html>[/PHP]

Let me know how you get on

Purple
Jun 22 '07 #3
Bakarre
8 New Member
Hi,
is perfectly now working.
You can buy experience.
I gained alot.

Bakare
Jun 26 '07 #4
Bakarre
8 New Member
Hi,
is perfectly now working.
You cann't buy experience.
I gained alot.

Bakarre
Jun 26 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2196
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if...
1
2918
by: BLUE WATER | last post by:
Does anyone know how I can see a value in my form field text box ? I tried to add a text box, but the record source doesn't list the variable I want to see for each record. The variable is the...
0
5797
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
2
286
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if...
2
1554
by: bobh | last post by:
In Access97 on a bound form, client wants a button that will duplicate the currently displayed record and give it a new meeting nbr. I have done it except for being able to display the new record...
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5631
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.