Solved

Mysql database update

Posted on 2006-06-29
1
288 Views
Last Modified: 2012-05-05
We would like the records in the MYSQL database to automatically be grabbed and inputted into the Text fields after the login page so that they show from each row of info, one at a time.  Then there has to be a way to scroll through the existing database entries with either a forward or back button.

Lastly we have the update feature working for our records in the MYSQL database but after we add all of the variables to the script and have an array hold on to them the updates stop working...the error  log says a premature end of script headers, how is this fixed.    
0
Comment
Question by:kukukevin2
1 Comment
 
LVL 8

Accepted Solution

by:
RWJDCom earned 500 total points
ID: 17014286
Well, I use a whole MySQL function set for all of my queries and what I do is the following...

   $db_host = "localhost";
   $db_login = "db_user";
   $db_passwd = "db_password";
   $db_name = "db_name";

   $connection = mysql_connect($db_host, $db_login, $db_passwd);
   mysql_select_db($db_name);

   $dbh[con] = $connection;

   function database_mysql_query(&$dbh, $query)
   {
      $dbh[ok] = 0;
      $dbh[result] = 0;
      $dbh[error] = "None";
      $dbh[query] = $query;

      $result = @mysql_query($query, $dbh[con]);
      if ($result)
      {
         $dbh[result] = $result;
         $dbh[ok] = 1;
         $dbh[error] = "None";
      }
      else
      {
         $dbh[result] = 0;
         $dbh[ok] = 0;
         $dbh[error] = mysql_error();
      }
   }

   function database_mysql_fetchrow(&$dbh)
   {
      $result = @mysql_fetch_array($dbh[result]);
      return $result;
   }

   function database_mysql_insertid(&$dbh)
   {
      $id = mysql_insert_id();
      return $id;
   }

   function database_mysql_nresults(&$dbh)
   {
      $total = mysql_num_rows($dbh[result]);
      return $total;
   }

   function GetInfo(&$dbh, $login)
   {
      if (!$login)
         return false;

      $query = "SELECT * FROM users WHERE login = "$login";
      database_mysql_query($dbh, $query);

      if ($dbh[ok])
         return database_mysql_fetchrow($dbh);
      return false;
   }

   $vars_for_form = GetInfo($dbh, $login);

?>
<input type="text" name="first_name" value="<?=$vars_for_form[first_name]; ?>">

All of the fields from the database will be in the $vars_for_form array so if you have first_name, last_name, etc... in your DB fields you would just use $vars_for_form[first_name], $vars_for_form[last_name], etc... to put them into the form.

I hope this helps you.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to dynamically set the form action using jQuery.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question