Right, first of all I'm new to PHP and I was trying if I could update information in table via a form.

So here's the problem:

I was unable to UPDATE my existing data in a table through a form using this code:

$updateFN = "UPDATE person SET firstName='$_POST[updateFN]' WHERE personID='$_POST[perID]'";

But If I would change from personID='$_POST[perID]' to personID='1' , surprisingly it works. So why did the perID variable failed to be detected? personID is a PRIMARY_KEY, AUTO_INCREMENT and NOT NULL in the respective table.

This is the error messages I've been getting:

Notice: Undefined index: perID in C:\...updatinginfo.php on line 4

Notice: Undefined index: perID in C:\...updatinginfo.php on line 5

Notice: Undefined index: perID in C:\...updatinginfo.php on line 6

Warning: mysql_query() expects at most 2 parameters, 3 given in C:\...processinginfo.php on line 9

//line 9
mysql_query($updateFN, $updateLN, $updateA);

I've even tried to verify the error using this method: echo ($updateFN ." \n". $updateLN ." \n ". $updateA);

But still I am unable to solve the issue. This is what it printed out:

UPDATE person SET firstName='Bob' WHERE personID='' UPDATE person SET lastName='Smith' WHERE personID='' UPDATE person SET Age='58' WHERE personID=''

So why isn't there any value for the personID?


Here's the source code for the form:

<form action="updatinginfo.php" method="post">
Please Enter your ID number stated above: <input type="textbox" name"perID" />


First Name: <input type="textbox" name="updateFN" />

Last Name: <input type="textbox" name="updateLN" />

Age: <input type="textbox" name="sage" />


<input type="submit" value="Update" />
</form>

Just a suggestion:

Put the data you're posting into variables:

$firstName = $_POST['updateFN'];
$id = $_POST['perID'];

Just a suggestion:

Put the data you're posting into variables:

$firstName = $_POST['updateFN'];
$id = $_POST['perID'];

Tried it, but error still persist.

$firstName = $_POST['updateFN'];
$lastName = $_POST['updateLN'];
$age = $_POST['updateA'];
$personID = $_POST['pID']; //line 7


$updateFirstName = "UPDATE person SET firstName='$firstName' WHERE personID='$personID'";
$updateLastName = "UPDATE person SET lastName='$lastName' WHERE personID='$personID'";
$updateAge = "UPDATE person SET Age='$age' WHERE personID='$personID'";

$update = mysql_query($updateFirstName, $updateLastName, $updateAge); //line 14

Gave me this error instead:

Notice: Undefined index: pID in C:\...updatinginfo.php on line 7

Warning: mysql_query() expects at most 2 parameters, 3 given in C:\xampp\htdocs\Fauzi\updateprocess.php on line 14

You can't do it, you have 3 queries in 1 query?

$firstName = $_POST['updateFN'];
$lastName = $_POST['updateLN'];
$age = $_POST['updateA'];
$personID = $_POST['pID']; //line 7


$update= "UPDATE person SET firstName='$firstName', lastName='$lastName', Age='$age' WHERE personID='$personID'";
$result = mysql_query($update) or trigger_error('Cannot update user');

Try that :)

You can't do it, you have 3 queries in 1 query?

$firstName = $_POST['updateFN'];
$lastName = $_POST['updateLN'];
$age = $_POST['updateA'];
$personID = $_POST['pID']; //line 7


$update= "UPDATE person SET firstName='$firstName', lastName='$lastName', Age='$age' WHERE personID='$personID'";
$result = mysql_query($update) or trigger_error('Cannot update user');

Try that :)

It seems that every errors has been tidied up. Alas, it's not working.

line 7 still persist:

Notice: Undefined index: pID in C:\...updatinginfo.php on line 7

Please, everytime you post code.. Can you put them in tags please? It just makes it easier to read things (and hopefully, sort your problem out in less time)

<form action="updatinginfo.php" method="post">
Please Enter your ID number stated above: <input type="text" name="pID" />


First Name: <input type="text" name="updateFN" />

Last Name: <input type="text" name="updateLN" />

Age: <input type="text" name="updateA" />


<input type="submit" value="Update" />
</form>

Hope this helps you :)

I'm afraid that didn't resolve the issue :'(

Here's the entire code for the form:

<?php
include 'connection.php'
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Index</title>
</head>

<body>
<b>Update for:</b> <br  />
<?
$getdb = mysql_query("SELECT * FROM person WHERE firstName='$_POST[updateN]'");

while($getdata = mysql_fetch_array($getdb))
{
	echo "ID no. " . $getdata['personID'];
	echo "<br />";
	echo "Name: " . $getdata['firstName']	. " " . $getdata['lastName'];
	echo "<br />";
	echo "Age: " . $getdata['Age'];
}


mysql_close($connection);
?>

<hr  />

<p>
<form action="updatinginfo.php" method="post">
	Please Enter your ID number stated above: <input type="text" name"pID"  /> <br  /><br  />
    
    
 	First Name: <input type="text" name="updateFN"  /> <br />
    
    Last Name:  <input type="text" name="updateLN"  /><br />
    
    Age: <input type="text" name="updateA"  /> <br /><br />
    
    <input type="submit" value="Update" />
</form>
</p>

</body>
</html>

And here's the entire code for the updatinginfo.php:

<?php
include 'connection.php';

$firstName = $_POST['updateFN'];
$lastName = $_POST['updateLN'];
$age = $_POST['updateA'];
$personID = $_POST['pID'];


$update = "UPDATE person SET firstName='$firstName', lastName='$lastName', Age='$age'  WHERE personID='$personID'";


$result = mysql_query($update) or trigger_error('Unable to update');


mysql_close($connection);

?>
<?php
include 'connection.php'
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Index</title>
</head>

<body>
<b>Update for:</b> <br  />
<?
$getdb = mysql_query("SELECT * FROM person WHERE firstName='$_POST[updateN]'");

while($getdata = mysql_fetch_array($getdb))
{
	echo "ID no. " . $getdata['personID'];
	echo "<br />";
	echo "Name: " . $getdata['firstName']	. " " . $getdata['lastName'];
	echo "<br />";
	echo "Age: " . $getdata['Age'];
}


mysql_close($connection);
?>

<hr  />

<p>
<form action="updateprocess.php" method="post">
	Please Enter your ID number stated above: <input type="text" name="pID"  /> <br  /><br  />
    
    
 	First Name: <input type="text" name="updateFN"  /> <br />
    
    Last Name:  <input type="text" name="updateLN"  /><br />
    
    Age: <input type="text" name="updateA"  /> <br /><br />
    
    <input type="submit" value="Update" />
</form>
</p>

</body>
</html>

The index of "pID" cannot be identified because it isn't be posted, because of this line:

Please Enter your ID number stated above: <input type="text" name"pID"  /> <br  /><br  />

You need to have an = between name="pId" I am pretty sure I resolved this in my last post?

It works fine on my server once the pID is being processed =)

commented: Very thorough and helpful +1

OMG!!! THANK YOU!! THANK YOU!!THANK YOU!!THANK YOU!!THANK YOU SO MUCH for pointing that out! I extremely appreciate your assistance :):):):)

No worries :) Could have been solved quicker my dear!

If your problem has been solved, please mark this thread as solved! And, give reputation if you think someone helped you!

Good luck :) !

Also, it's not really ideal to use shorthand php tags..

<?

?>

Use:

<?php

?>

Just minor :)

Also, it's not really ideal to use shorthand php tags..

<?

?>

Use:

<?php

?>

Just minor :)

Thanks for the advice!

Below the reply box there should be a message that says: 'Mark this thread as solved'

To give reputation: By someones username that you found their post to be helpful/interesting click on the up arrow and enter your message

:)!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.