Solved

How to inline edit a MySQL table

Posted on 2013-06-23
21
559 Views
Last Modified: 2013-10-02
Hello Everyone,

I have setup a MySQL database that I use as a changelog, and I was wondering if there is any way to edit the table on a php page instead of having to go into PHPMyAdmin. Thanks!
0
Comment
Question by:Harrison Walker
  • 7
  • 5
  • 5
  • +1
21 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39270020
As long as the php page has the queries on the backend to acquire the data and process a form with updates, it is just an ordinary operation.

PHPmyadmin is just a web interface to the mysql API.

Cd&
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39270029
Yes.  The general design is to SELECT the contents of the table you want to edit, and render the column names into the NAME= attributes of HTML form input tags.  You would also render the contents into the VALUE= attributes of the input tags.  When the form is submitted, the old (or new) names and values will be in the $POST array.  From this you would construct a query to INSERT or UPDATE the table.  Lather, rinse, repeat.
0
 

Author Comment

by:Harrison Walker
ID: 39270032
Thanks for the quick response! Sorry I wasn't clear, but I'm looking for some form of PHP code to use that will allow me to do inline editing on a page.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39270041
What's wrong with using phpMyAdmin?  From a functional perspective, you'll just be duplicating its abilities, minus a lot of the broader capabilities.

Are you new to PHP?  If so, this article may be able to help with some of the "deep background" and good learning resources.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

Also, there is this ;-)
http://www.ee-stuff.com/Newsletter-old/061913newsletter.htm
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39270044
Edit what?  If you are updating the database then there are three steps.

Acquire the original date from the db and put it in a form on a page.
Apply whatever changes are necessary and return the form to the server
Update the database.

What additional option do you think exists?

Cd&
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39270045
What do you mean by 'inline editing'?  If you mean like editing a text file, that can't happen with a MySQL table because it is not organized 'inline' like that.  No SQL tables are like that.
0
 

Author Comment

by:Harrison Walker
ID: 39270049
Yes I am a newbie when it comes to PHP, and when I mean inline editing I'm talking about having an "edit" button at the end of each row that would allow me to edit that row. The reason why I don't want to use PHPMyAdmin is because both me and my dad are using this and it would be much more convenient. Thanks!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39270061
I keep thinking I should write an article about this... But maybe you can beat me to it.

If you want to post the CREATE TABLE statements, we might be able to help you get started.  Don't be in too much of a rush -- there are a lot of moving parts!

You will need to understand about how PHP processes HTML forms.  On the PHP.net web site they have an introductory tutorial.  See especially the part about Dealing With Forms.
http://php.net/tut.php

You will need to understand client/server protocols.  This article can help with that part of things.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

You will need to understand how the MySQL data base works.  This article can help with that part of it.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39270063
How does having two people use it affect what you want?

Since you would have to duplicate some of the code in phpMyAdmin, I'm not sure where the 'more convenient' part comes into it.  You can write fairly simple code to edit a single table.  But it stops being simple when you want to edit 'any' table because you have to get not only the data but the table structure and several other things to make it 'generic'.  And then you have to create the dynamic displays and forms to edit the data.

There are quite a few examples on the web for editing a single table.  I don't want to recommend anything since I don't know what you are familiar with.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39270093
AND... It still comes down to three steps whether you edit a row at a time in a table structure with buttons on the rows.

So for some strange reason related to more than one person has to have access you want to reinvent the wheel, and perhaps even get the wheel round, and you are prepared to maintain the wheel to keep up with cross-version changes to mysql; changes in the database; and changes in requirements.  Yes it makes perfect sense to not use a proven available method, when you can spend a substantial amount of time getting some duplication of the functionality to work.

Cd&
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:Harrison Walker
ID: 39270200
People seem to be confused, so I am going to explain it as best as I can. I want to view a SINGLE table's data and be able to edit a row by clicking an "edit" button or link on the end of the row, so that I can edit THAT ROW's data in the database. I want to do this instead of PHPMyAdmin because it takes time to sign into PHPMyAdmin and navigate to the editor. Hope this clears things up
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39270241
Please create and post the SSCCE so we can get a clear understanding of what you want, thanks. ~Ray
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39270377
No, we're not confused.  We've these things many times, many ways.  Now we're trying to figure out which one you're talking about.  I'm also curious where this is going to be hosted if it isn't going to require a login to keep the creepies out.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39271318
I think we understand what you want to do.  It's one of the "PHP 101" exercises I give my students at the end of the first week of class.  It's not hard at all, but it has several moving parts that require a level of understanding and integration.  To help you get started with PHP and MySQL, please read this article, then go back and read the articles I recommended earlier.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

After reading the articles, please create the SSCCE that will show us where you're having trouble with your code.  Once we see your starting point, it will be easy for us to help you.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39271797
???? If I am doing a lot of direct editing using phpmyadmin, I just keep it in an open tab.  Click the tab, there is the table I am working with, click on the field I want to edit, make the change. Done... go back to another tab... ???

Even with older versions of phpmyadmin where I have to click inline edit first there is no delay, I get instant access and instant update.

Cd&
0
 

Author Comment

by:Harrison Walker
ID: 39295287
As for a starting point, I have a php page that displays the data in the table, and I would like to be able to edit on this page as well: (note that I didn't create this code; I found an example online and modified it)
<?php
$con=mysqli_connect("192.168.0.9","plugins","","changelog");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM log");

echo "<table border='1'>
<tr>
<th>Who Did It?</th>
<th>When Was It Done?</th>
<th>What Site Was It Done On?</th>
<th>What Was Done?</th>
<th>What Pages Were Involved?</th>
<th>Who Tested It?</th>
<th>GA Annotation?</th>

</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['who'] . "</td>";
  echo "<td>" . $row['date'] . "</td>";
  echo "<td>" . $row['site'] . "</td>";
  echo "<td>" . $row['activity'] . "</td>";
  echo "<td>" . $row['pages_involved'] . "</td>";
  echo "<td>" . $row['tested_by'] . "</td>";
  echo "<td>" . $row['GA_annotation'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysqli_close($con);
?>

Open in new window

0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39295322
Editing requires you to get the info from the database and put it in a form on a page.  That form must submit to a PHP page that checks the data and does an UPDATE to the right row in the database.  That sounds pretty simple but there are a lot of details to getting it done right.  It can be done all on one page but so far you just have the 'getting the data' part.
0
 

Author Comment

by:Harrison Walker
ID: 39297212
That's exactly what I am looking for.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39297807
Almost any good book on PHP will teach you how to do this.  It's not rocket science, but it's a process with a lot of moving parts.  Sort of like saying, "How do I bake an apple pie?"  We can't answer that in the back-and-forth forum for technical Q&A that is Experts-Exchange -- it would just take too long to lead you through all of the details.  And besides, you would need time to try things out and see what works best for you.  So the best help we can give you is to show you some good learning resources.  I would start with this book.
http://www.amazon.com/PHP-MySQL-Web-Development-Edition/dp/0321833899

Another good one is from SitePoint.  It uses PDO.  Ignore the hokey title - it's really well written.
http://www.sitepoint.com/books/phpmysql5/

If I find myself with time on my hands, I may write an article about this question.  Don't wait for it (it may take me a few days) but instead dig into one of those books and you'll be years ahead by the time you finish it!
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39298535
I need to find a book on round things so I can invent a wheel. ;^)

Cd&
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39298570
@COBOLdinosaur: Or, "I want to build a car, but I don't know what all that metal stuff is under the hood."

@hdw632: We're not picking on you and there is no harm in ignorance - we were all ignorant and new to this stuff once. It just takes a while to learn enough of the fundamentals to use the PHP language effectively.  The same is true of human languages.  If you've never spoken Italian, you can certainly learn some Italian in a few weeks of immersive study.  But if you want to write Italian poetry, you need to be a little more patient with yourself, gathering knowledge and building up a vocabulary of words and phrases.  The same is true of programming languages.  That's why we're pointing you in the direction of learning resources (books online courses, etc).  And you will be much less of a newbie in just a few months of study.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now