GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Oct-2003, 17:55
mjfmn mjfmn is offline
New Member
 
Join Date: Oct 2003
Posts: 3
mjfmn is an unknown quantity at this point

Automate a data change php form


Hi, thanks in advance for reading this! I inherited the responsiblity for maintaining my non-profit's MySql flat file with multiple tables, administered by me directly with Putty (it's hosted elsewhere), and all the users access the data via php on our website. Here's my conundrum: for situations when data on a table needed to be changed, the previous administrator created a "delete" php form, and then the user had to re-enter the entire data. Let's say it was to our "news" section. The fields are author, date, subject and article. There is another field, "id", an auto-incrementing integer that is the primary key, but it is hidden. If someone screws up a name in the "article" field and doesn't notice it until after it's posted, they have to delete the record and re-enter it all again. I'd like to figure out a way to display the news articles, maybe just by "id" and "subject", let the user choose which one to change, bring up all the data for that record, let them change anything they want to, and then click a button to update the record. I'm just figuring out MySQL & php scripts right now, and I know for sure how to display the data all at once for everything. But is what I'm asking for even possible?

I'm not looking for a free ride, altho if someone has the inclination to just show me the code I need I wouldn't argue ! I will greatly appreciate being directed to sample scripts of what I'm trying to do and I'll try and figure it out for myself. I figure, the worse that will happen is I won't get it figured and they'll just keep operating like they currently are.

Thanks so much! By the way, you can view some of the user-end php scripts at www.flightsimnetwork.com - click on the "Captain's Lounge NOTAMS" for a look at the news section.
  #2  
Old 20-Oct-2003, 08:05
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
I suck at coding php and have little clue about mysql... But, can you just use phpmyadmin or a program similar to that to admin the databases?
__________________
Mr. Bob's Web Design - Tirelessly looking for ways to enhance the customer base of your business.
  #3  
Old 20-Oct-2003, 08:33
mjfmn mjfmn is offline
New Member
 
Join Date: Oct 2003
Posts: 3
mjfmn is an unknown quantity at this point
BobbyDouglas, thanks for the response. Looking at the admin program, I don't think it fits my needs. I want regular users who post to be able to correct it as needed, and I don't want them to have the rights that the admin program would give them.

Thanks anyway!

Mike
  #4  
Old 20-Oct-2003, 09:20
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Hello mjfmn,

What you're asking for is quite simple to do actually (but if you're just starting out with PHP and MySQL almost everything can seem daunting at first). Nevermind, we're here to help when we can...

If I understand your question; you're looking for some examples on how to easily edit a certain table in a MySQL database?

Here's a quick example... a fictitious web page filenamed - news-edit.php; reply if you have any specific questions figuring out the sample code:
PHP Code:

<?php
// FILENAME: NEWS-EDIT.PHP

// the connection to the MySQL database in a custom function
// let's say this function also takes care of 'selecting the db' to use etc.
// returning the 'MySQL link identifier'
$conn = my_mysql_conn();

// ALL THE REQUIRED CUSTOM FUNCTIONS HERE
/////////////////////////////////////////
// I will just code one sample here... you try to figure out the rest!
function list_all_articles()
{
  $sql = 'SELECT `id`, `subject`
         FROM `articles`
         WHERE `author`='.$_COOKIE['authorid'].'
         ORDER BY `subject`';
  $result = mysql_query( $sql, $GLOBALS['conn'] );
  while( $row=mysql_fetch_assoc($result) )
  {
    echo '<p><a href="'.$_SERVER['PHP_SELF'].'?aid='.$row['id'].'" title="click to edit">'.$row['subject']."</a></p>\r\n";
  }
  // a word of caution here, of course a lot of error checking,
  // user input validation etc. were NOT included in this brief example
}
/////////////////////////////////////////



// this page does nearly everything... so we usually try to figure out
// what's happening based on the SUPER GLOBAL variables that are either set / or not.

// first we check if the user is submitting a form, i.e. edited data
if( isset($_POST['article']) )
{
  update_the_record();
}
// no, that was NOT it, perhaps the user is selecting an article to edit?
elseif( isset($_GET['aid']) )
{
  get_record_by_id_and_display_it_in_a_form();
}
// looks like no SUPER GLOBAL var was set, so just list all the articles off
// the db/table...
else
{
  list_all_articles();
}

?>


Or... you could just pay someone to set this up for you...
  #5  
Old 20-Oct-2003, 09:37
mjfmn mjfmn is offline
New Member
 
Join Date: Oct 2003
Posts: 3
mjfmn is an unknown quantity at this point
Jds, thanks! Hey, if we weren't non-profit I'd definitely consider paying someone! I have to admit, I enjoy learning php and mysql - it's not exactly HARD, just a new language. I'm great with basic "show the data" forms or "enter the data" forms (how hard is that, right?), but as I get deeper into this it gets more complicated. And since my full-time job doesn't allow me the time to actually sit and learn the stuff, I have to do it on my off time.

What you gave me is great - a starting point to working on my own code. Thanks a lot!

Mike
 
 

Recent GIDBlogFirst week of IA training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
All the big PHP script collections that matter jrobbio MySQL / PHP Forum 5 06-Jun-2003 16:14

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:38.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.