Go Premium for a chance to win a PS4. Enter to Win


Mysql database update

Posted on 2006-06-29
Medium Priority
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.    
Question by:kukukevin2
1 Comment

Accepted Solution

RWJDCom earned 2000 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);

   $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";
         $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.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

916 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