PHP/mySQL newbie, handcoding an app, stupid Q's

software development

#1

Hey folks,

I may possibly have taken leave of my senses here. I’m trying to help someone out with an unfinished web site (original designer vanished months ago). I don’t know a great deal about PHP or mySQL, though I know a helluva lot more than I did a few days ago.

Anyway, what I’m trying to finish/create is an interface that that can, for example, add news items to a database and a corresponding page that would display them (that part is done and I used it to learn how to add things in other areas), and also be able to edit existing items.

This is where everything’s going all wonky on me. I read some tutorials, and I coded this page that would theoretically list all the news items and allow you to click on a link to either edit or delete an item.

I’ve debugged the 768 typos I created and gotten a vaguely reasonable-looking page, but unfortunately I’ve created a sort of stealth ninja instead of a functional edit page. I’ve done something terribly wrong, and clicking an edit link actually deletes the item’s content field from the database table.

Now, I do not expect you nice folks to debug my code, but I’m having a hard time finding a tutorial specific to this sort of thing and I’m hoping for suggestions as to where I can teach myself how to do it the right way: I need to be able to pull the info out of the database, populate a WYSIWYG editor with it (I haven’t even incorporated that into the prototype edit page yet, just the add page), and then be able to submit the changes, preferably without deleting the info from the table which it’s doing right now.

Web-based tutorials would be most accessible for me but book suggestions are welcome too–I’ve pulled up a list from at my library’s site but I don’t really know what’s good.

(The text of the page I’ve got, in case anyone is feeling adventurous and wants to look at it, is here: http://daisywreath.net/temp/edit.txt )

Any pointers would be much appreciated!


#2

Updating information in a database is a bit like adding it in the first place. Normally, I create new records by submitting a form. An almost identical form can be prepopulated from the database when doing an update. In effect, I prefer to update all the values in a given database row at the same time, even if the values are not changing (with the exception being the unique ID, of course).


Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#3

From the example you provided, the values you are trying to update haven’t been set to anything - which means that if the update works (which it appears is happening) the title and content fields will get set to an empty (blank) string.

What you are going to require is the ability to pass more values (besides the news id) either through the URL (as is being done with the id) or through a form or some other means.

To do it with the URL, you would need something like:


$_SERVER[‘PHP_SELF’] . ‘?updatenews=’ . $id . ‘&title=’.$title.’&content=’.$content …

But be aware that this is likely to break in a big way if title or contents contain quotes.

If you just want to test that the script is actually doing something, in the ‘edit’ section, set
$title = ‘this is my title’;
$content = ‘this is my content’;

and you will see that the the database update is likely working. But it’s going to take a bit more code to make a useful page.

There are all kinds of books about php and mysql. Most any of them will cover the basics and show better ways to do this. Don’t worry about what’s good at this point. Pick any of them and use it to get started.


#4

I teach PHP and MySQL at a college in Pennsylvania. I am using PHP 5: Your visual blueprint blah blah blah… (stupid long book title), because it covers all the stuff you need for PHP and MySQL interaction without bogging you down in too many details.


Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#5

WHAT?! You’re recommending a CHEEP book? You’re obviously not a REAL college teacher.

Nothing else to add here. When I started PHP, there weren’t any books out. :slight_smile:
(well, there was ONE and it sucked)
And PHP5 OO design was second nature to me from my experiences in C and Java. Didn’t need a book to pick up on PHP5. www.php.net was all that was needed for me.


yerba# rm -rf /etc
yerba#


#6

Funny you should say that. I had a battle with the powers that be over that book. The college wanted to make me work with PHP 5 / MySQL Programming for the Absolute Beginner, mainly because they have an agreement with Course Technology; however, that book (along with most from that publisher) is nine kinds of crap.

I agree that the PHP website is more than sufficient for anyone learning PHP; however, I needed something that taught server-side scripting in general, rather than a syntax reference.


Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#7

D’oh! That makes perfect sense now.

Thanks for the input! I’m working on getting it running properly now. This is all kinda new for me–I’ve never done any kind of programming whatsoever apart from learning BASIC many years ago in school, and most of what I’ve done with web development so far has been limited to writing HTML and working with CMS stuff where other people already did the hard part. Definitely a learning experience :slight_smile:

Have sent for some books from the library–Simon, thanks for the suggestion!


#8

Hi
http://www.sitepoint.com is a very good source.

Johan van Zyl