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 -
<html>
-
<body>
-
<?php
-
$db = mysql_connect("localhost", "root");
-
mysql_select_db("k1",$db);
-
$id = $_POST["id"];
-
echo $id;
-
if ($submit) {
-
$first = $_POST['first'];
-
$last = $_POST['last'];
-
$address = $_POST['address'];
-
$position = $_POST['position'];
-
$sql = "UPDATE 'employees' SET 'first'='$first','last'='$last','address'='$address','position'='$position' WHERE 'id'='$id'";
-
$result = mysql_query($sql);
-
echo $first;
-
echo "Thank you! Information updated.\n";
-
} else {
-
if ($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>
[Please use CODE tags when posting source code. Thanks! --pbmods] 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
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
Hi,
is perfectly now working.
You can buy experience.
I gained alot.
Bakare
Hi,
is perfectly now working.
You cann't buy experience.
I gained alot.
Bakarre
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |