Jump to content


Problem with Function

  • Please log in to reply
2 replies to this topic

#1 genista

  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 17 August 2006 - 03:08 PM

Hi all,

I have the following script for a user to update their details:

$id = $_SESSION['username']; 
$query = "select * from suppliers where username='$id'"; 

    //now we pass the query to the database  
    $result=mysql_query($query, $link) or die("MySQL query $query failed.  Error if any: ".mysql_error()); 

    //get the first (and only) row from the result  
    $row = mysql_fetch_array($result, MYSQL_ASSOC);  

if(empty($messages)) { 
    updateuser ($username=$row['username'],  


I then have html below that:

<form name="form1" method="post" action="<?=$_SERVER["PHP_SELF"]?>" onSubmit="return check()">  
    <?php echo $username; ?>  
  <p>First Name:  
    <input type="text" name="first_name" value="<?php echo $first_name; ?>">  
   <p>Last Name:  
    <input type="text" name="last_name" size="10" value="<?php echo $last_name; ?>">  
  <p>Address Line 1:  
    <input type="text" name="address_line1" size="10" value="<?php echo $address_line1; ?>">  
  <p>Address Line 2:  
    <input type="text" name="address_line2" size="10" value="<?php echo $address_line2; ?>">  
    <input type="text" name="town" size="10" value="<?php echo $town; ?>">  
etc, etc  

The problem is that the html is not being populated with the data and is not posting either, I have simply copied the function from a newuser function when a user signs up, the function as it is in the functions file looks like so:

function updateuser ($password, $username, $first_name, $last_name, $address_line1, $address_line2, $town, $county, $postcode, $daytime_phone, $mobile_phone, $email_address) { 

 global $link; 

$query="UPDATE suppliers SET password='$password', username='$username', first_name='$first_name', last_name='$last_name',  address_line1='$address_line1', address_line2='$address_line2', town='$town' , county='$county', postcode='$postcode', daytime_phone='$daytime_phone', mobile_phone='$mobile_phone', email_address='$email_address' where username= '$username'"; 

$result=mysql_query($query, $link) or die("Died inserting login info into db.  Error returned if any: ".mysql_error()); 

 return true; 
} //  

Any help would be much appreciated as I am really stuck.



#2 ToonMariner

  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 17 August 2006 - 03:10 PM

is $messages empty? if not then yoru form won't be popluated
follow me on twitter @PHPsycho

#3 genista

  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 17 August 2006 - 03:27 PM

Not sure if this is what you mean, but I just added:

//Check if $message is set, and output it if it is:

Still no joy though

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users