Hi people i got a table called users and fields like username, password and occupation and my site uses cookies and i was wondering what is the code to update the occupation part for that user?
| SitePoint Sponsor |




Hi people i got a table called users and fields like username, password and occupation and my site uses cookies and i was wondering what is the code to update the occupation part for that user?




Ok this is the code i got now:
when i fill it our it says it was updated then ichecked in hppmyadmin and wasnt updated at all
oc.php file:
Ocpro.php file:<?
include "theme.php";
?>
<form name="form1" method="post" action="ocpro.php">
Occupation: <input type="text" name="occupation"><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="reset" value="Reset Form">
</form>
<?
include "theme.php";
include "db_check.php";
$occupation = $_POST['occupation'];
$username = $_POST['username'];
$sql = "UPDATE users SET occupation='$occupation' WHERE username='$username'";
if (!sql)
{
die ('unable to update users occupation: ' . mysql_error());
}
else
{
echo 'Users occupation updated';
}
?>





Your form script isn't passing the username to the Ocpro.php file !!
Therefore you query is returning no results
A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming




i dont understand what code do i put it seems alright to me





Your query is saying '.....WHERE username = $username'
your php script is setting $username to equal $_POST['username']
But your form isn't sending any data with the name 'username'
Now do you see where the problem is ?
A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming




how would i fix it what would the code be?




anyone?



He said add the username in the form:
<?
include "theme.php";
?>
<form name="form1" method="post" action="ocpro.php">
Occupation: <input type="text" name="occupation"><br>
Username: <input type="text" name="username"><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="reset" value="Reset Form">
</form>





Well I would guess that username would be stored in a variable by the time you get to the form, in which case I'd make it a hidden field and assign it to the variable $username.Originally Posted by chiphunt1
<?php
echo '<input type="hidden" name="username" value="' . $username . '">';
?>
Of course that will only work assuming you have defined the user in the variable $username berore getting to your form
A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
Bookmarks