Solved

Mysql database update

Posted on 2006-06-29
1
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to dynamically set the form action using jQuery.

695 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