Skip to main content
Known Participant
July 30, 2009
Question

I want to update, not overwrite my database!

  • July 30, 2009
  • 2 replies
  • 1435 views

Morning all,

In Dreamweaver CS4 - I've managed to insert data from my Repeating Region using Dynamic Checkboxes and Text Fields into my MySql database (thanks again to www.DwFAQ.info) , but when I go to insert another/new record, the checkboxes are already selected and the text from the previous entry is showing in the text fields.

Obviously the dynamic fields are reading the data that is already in the database, but how do I send the data from the form to the database, then clear the form for the next use?

I want to update my database with football player stats, and display the running total of games played, goals scored etc on another page, so I need to update the database each time I input data, not overwrite the previous entry.

Should I be looking at the Dynamic input from Dreamweaver, or the MySql data/functions side of things?

Any help or general pointers would be much appreciated!

Many Thanks

Andy

This topic has been closed for replies.

2 replies

Participating Frequently
July 30, 2009

If you are inserting new rows, then use the insert form behavior. If you are updating exising rows, use the update behavior. If you are doing a combination, then you must hand code this.

info261Author
Known Participant
July 30, 2009

I don't need to insert any more rows, all the rows and columns etc for the database are set up fine. The column with the player names will stay as it is, but I need to update the games played/red card/yellow card etc with checkboxes and the goals scored with text fields.

I can insert data from dreamweaver into the mysql database ok, but when I go into the form again to update it (ie add another match played, another 4 goals scored), then the data that is already in the database is there, so some of the checkboxes are already ticked, and the previous goals scored are already in the text entry field.

How do I 'clear' the form for the next use, and have dreamweaver/mysql update the database? I need to add 2 goals to the previous 3 that were scored in the match before, not replace the 2 goals with 3

Is this to do my the mysql functions etc, or dreamweaver? Can anyone help please?!

info261Author
Known Participant
July 31, 2009

And so we are clear on this, are you actually using Dreamweavers server behaviors for insert and update, or coding by hand?


Hi Bregent,

Yeah, I'm using Dreamweaver for all the insert/update features. Coding's not my stong point really, but then again neither is Dreamweaver at the moment!

Thanks for all your help, I think I was just approaching the setting up of the databases the wrong way. I'll let you know how I get on

Andy

July 30, 2009

hello,

I think this will do the job

first you need to know how many goals player has in database, then you add to existent the new posted value and update your database.

I'm no expert, so this may be wrong, ok?

$sql = "SELECT ID, goals_scored FROM database_table WHERE player_name LIKE '".$_get['player']."'";

$result=mysql_query($sql) or die("Error!: " . mysql_error()." : ".$sql);
if (mysql_num_rows($result) == 1) {
        while($row = mysql_fetch_assoc($result)) {

               $n_goals = $row['goals_scored'];

               $new_score = $n_goals + $_get['goals'];

               $sql = "UPDATE database_table SET goals_scored = '".$new_score."' WHERE player_id = '$player'";

          }

}

info261Author
Known Participant
July 30, 2009

Thanks for this, I'll try and look into it later.

Do you know if this will stop the goals total from the previous entry showing up in the 'Enter Goals' field in the new form? The problem I'm having is getting the form to show up empty when I go in to add/update the new details

Cheers

Andy