Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't update table using HTML, PHP and mySQL

Status
Not open for further replies.

RPGguy

Programmer
Jul 27, 2001
73
US
Thanks to all for your help. Going from 20 years of RPG to this is quite a shock. I found nothing in the FAQ so here goes:

I've 2 fields on my page:
<input type=&quot;text&quot; name=&quot;name&quot; value=&quot;<? echo $line2 [Name]; ?>&quot; size=&quot;33&quot; tabindex=&quot;2&quot; ></td>

<input type=&quot;text&quot; name=&quot;contact&quot; value=&quot;<? echo $line2[Contact]; ?>&quot; size=&quot;33&quot; tabindex=&quot;3&quot;></td>

I select the record from my database and populate the firlds. The user modifies the data then presses the Update button:
<input type=button value=&quot;Update Customer&quot; onClick=updCust>

I have the updCust function defined as follows:
<?
function updCust()
{
$link = mysql_connect(&quot;localhost&quot;, &quot;***&quot;, &quot;*****&quot;);
mysql_select_db(&quot;******&quot;);

$query = &quot;UPDATE tblCust SET Name='$name',Contact='$contact' where Cust ='$key'&quot;;
$result = mysql_query($query);

$line = mysql_fetch_array($result);
}
?>


I don't get any errors but the data does not get updated?!?

All help is greatly appreciated.

Scott
 
where do you have the keyfield on your page , I don't see that you pass that one?? I always add it as an hidden form field
Code:
<input type=&quot;hidden&quot; name=&quot;key&quot; value=&quot;<? echo $line2 [key]; ?>&quot; size=&quot;33&quot;></td>

 
I'm not sure I understand. I pass the key to the file as a parameter in the URL (?cust=A000132). I can retrieve the record and populate the form with no problem. I just can't get it to update.

I read on some site that you can't do a 'SELECT *' to get the data and then update only certain fields. It said you had to select the fields individually but I haven't read that elsewhere.

Thanks,
Scott
 
Maybe a variable scope thing. Instead of referring to it as $key, try $_POST['key']. If that's not exactly it, I'd still bet the answer lies in that general direction.

----
JBR
 
Does it work if you hit refresh? If so you the web page is not instructing the browser to update so it is using it's cache.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top