I have to fix my company’s website since the web guy quit. I’m a machinist and barely know some python/c++. I don’t really know php. Quick rundown:
There is an admin page to create entries in Shows and Articles.
Articles pages works correctly.
Shows page is virtually identical in code (fields are different), but will not update.
The if/elseif/else works correctly taking me back to where I need to be after hitting the ‘Submit’ button, but the list is not updated.
in the editArticle.php
[php]<?php if ( $results['article']->id ) { ?>
// User has posted the article edit form: save the new article
$article = new Article;
$article->storeFormValues( $_POST );
$article->insert();
header( "Location: articles.php?action=articles&status=changesSaved" );
} elseif ( isset( $_POST[‘cancel’] ) ) {
// User has cancelled their edits: return to the article list
header( "Location: articles.php" );
} else {
// User has not posted the article edit form yet: display the form
$results['article'] = new Article;
require( TEMPLATE_PATH . "/articles/editArticle.php" );
}
}[/php]
editShows.php
[php]<?php if ( $results['show']->id ) { ?>
// User has posted the shows edit form: save the new show
$show = new Show;
$show->storeFormValues( $_POST );
$show->insert();
header( "Location: shows.php?action=shows&status=changesSaved" );
} elseif ( isset( $_POST[‘cancel’] ) ) {
// User has cancelled their edits: return to the shows list
header( "Location: shows.php" );
} else {
// User has not posted the show edit form yet: display the form
$results['show'] = new Show;
require( TEMPLATE_PATH . "/shows/editShow.php" );
}
}[/php]
Am I looking in the wrong area? Will attach all files if necessary, they aren’t too big. Please help me, I’m going crazy. Thank you.
You should probably be looking for a function called “editShow”, after that, the database interaction looks to be in a class called “Show”. There is most likely going to be a method (function) inside that class called “update”.
If that isn’t the case, and the editing is being handled by the newShow function (bad coding practices, as functions should do what they say they are doing), you are probably looking at changing a few words. We will await your reply, before diving into that one. Posting the contents of the class “Show” method (function) “insert” would also go along way on solving your current situation.
This is all based off of the naming conventions of the scripts you have provided. Good Hunting.
// User has posted the shows edit form: save the new show
$show = new Show;
$show->storeFormValues( $_POST );
$show->insert();
header( "Location: shows.php?action=shows&status=changesSaved" );
} elseif ( isset( $_POST[‘cancel’] ) ) {
// User has cancelled their edits: return to the shows list
header( "Location: shows.php" );
} else {
// User has not posted the show edit form yet: display the form
$results['show'] = new Show;
require( TEMPLATE_PATH . "/shows/editShow.php" );
// User has posted the show edit form: save the show changes
if ( !$show = Show::getById( (int)$_POST['id'] ) ) {
header( "Location: shows.php?action=shows&error=showNotFound" );
return;
}
$show->storeFormValues( $_POST );
$show->update();
header( "Location: shows.php?action=shows&status=changesSaved" );
} elseif ( isset( $_POST[‘cancel’] ) ) {
// User has cancelled their edits: return to the show list
header( "Location: shows.php" );
} else {
// User has not posted the show edit form yet: display the form
$results['show'] = Show::getById( (int)$_GET['id'] );
require( TEMPLATE_PATH . "/shows/editShow.php" );
<?php include "templates/include/head.php" ?>
<?php include "templates/include/footer.php" ?>
[/php]
It does have the editShow with update(). I can successfully edit an entry. I’ve been at this for about 8 hrs total now and want to smash this computer.
Just in case it’s here - listShows.php[php]
<?php include "templates/include/head.php" ?>
<?php include "templates/include/header.php" ?>
Title
Date
City
State
<tr>
<td class="clickable new" colspan="4" onclick="location='shows.php?action=new'">
Add new show
</td>
</tr>
Shows page is virtually identical in code (fields are different), [b]but will not update.[/b]
The if/elseif/else works correctly taking me back to where I need to be after hitting the 'Submit' button, but the list is not updated.
Then you stated in your second post:
[b] I can successfully edit an entry[/b]. I've been at this for about 8 hrs total now and want to smash this computer.
So, I’m not real sure where you are stuck, I thought you couldn’t edit the entry. So, we need to back up a little bit.
What exactly is the issue. Cannot add new show? You need to check the SQL query in the Show::insert() method to make sure it is built correctly. You can echo that to the page and then copy/paste it into the database console, or exit() (php function) on error, trigger_error() (php function) to capture the error in your error log (depends on php settings). This will tell you if the query is failing. There should already be check in place for that, but some coders are lazy (most are at some point in time, me included).
You can trace updates with the same strategy, only looking at the method Show::update().
I don’t know how to do any of that. But, there is some try and catch stuff. No errors on error.log.
I’m looking at the class files now, but as I stated in OP, this is beyond me. We can just shut this one down, I don’t think it’ll get resolved.