Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Updating multiple database fields with one form
Old 06-09-2010, 09:40 AM Updating multiple database fields with one form
Junior Talker

Posts: 1
Trades: 0
Hi there,

I'm working on something akin to the following mockup and need a wee bit of help with some of the coding:

Here

The form is for a music content aggregation website, and the idea of the form is that the user adds a new release or album or whatever, then the form is displayed with space for the number of tracks they have selected (this bit is working ok)

The bit I'm having trouble with currently is the post functionality of the form. At present tracks are being added one by one in separate forms to the DB, but we want to have it so that the one form takes in all the information displayed there (see link) and assigns the values to different fields and different tracks within the same album. We were hoping that
once the data is input it can be saved, and also finalised (whereby it would no longer be editable).

I've attached the actual code I'm working on at the moment... At present the code isn't pulling values from the database for existing albums, and it isn't updating them either, but the iteration for the form printing is working ok.

I'm looking for any general advice here, and I'm not too hot on mySQL so any help / polite pointing out my stupidity would be greatly appreciated! Thanks!



<? include("includes/header.php") ?>
<!-- DIV NAVIGATION -->
<td align=right><a href="/secure/addtrack.php">add track&nbsp;</a></td>
<? include("includes/header2.php") ?>
<? include("includes/navigation.php") ?>
<!-- END DIV NAVIGATION -->



<style type="text/css">


.style3 {color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; }
.style5 {color: #000000}

.opacity {
background-color: red;
opacity:0.3;

filter:alpha(opacity=30);
}

.strongtext {
color: white;
opacity:1;

filter:alpha(opacity=100);
}

.foccus{
color:blue;
}

.blurr{
color:green;
background-color:"blue";
}

</style>
</head>

<body background="james.jpg">
<style type="text/css">
<!--

body {
color:#CC0000;
font-size: 10px
}

.style1 {
color:#ffffff;
font-size: 11px
font-family:Arial, Helvetica, sans-serif
}

input, select {
border: 0px solid #000;
background-color: transparent;
color: #000000;
font-size: 9px;
}



select {
border: 0px solid #999999;
shadow-color: #999999;
background-color: white;
color: #000000;
font-size: 9px;
}



input.button {
border: 1px solid #666666;
background-color: transparent;
color: #ffffff;
font-size: 9px;
}

input.button:active {
border: 1px solid #999999;
background-color: black;
color: #ffffff;
font-size: 9px;
}

label {
font-weight: bold;
font-size: 14px;
color: #ffffff;
}

.submit {
border: 1px solid #333;
background-color: #862222;
font-family: Courier New, Courier New, Courier, monospace;
color: #fff;
}
fieldset {
border:0px solid #333;
}
-->

a {
text-decoration: none;
}
input.button {
border: 1px solid #8A0808;
background-color: transparent;
color: #8A0808;
font-size: 9px;
}
input.button:hover {
border: 1px solid #3B0B0B;
background-color: #F2F2F2;
color: #3B0B0B;
font-size: 9px;
}

</style>


<?
//$albumid = 2138;
$albumid = $_POST['albumid'];
if($albumid == ""){
//$albumid = 2138;
$albumid = $_GET['albumid'];
}

$trackid = $_POST['trackid'];

$tracknumber = $_POST['tracknum'];

$addtrack = $_GET['addtrack'];
if ($addtrack == 1){

$composer = $_POST['composer'];
$duration = $_POST['duration'];
$title = $_POST['title'];
$isrc = $_POST['isrc'];
$track_year = $_POST['track_year'];
$genre = $_POST['genre'];
$arranger = $_POST['arranger'];
$lyricist = $_POST['lyricist'];
$explicit_lyrics = $_POST['explicit_lyrics'];
$publisher = $_POST['publisher'];

$badattempt = false;

if (strlen($composer) < 2){
$badinfo = "Please enter a composer <br />";
$badattempt = true;
}
if (strlen($duration) != 5){
$badinfo = "Please enter the duration in the format (MM:SS), for example 03:48 for a song that is 3 minutes and 48 seconds long. <br /.";
$badattempt = true;
}
if (strlen($title) < 1){
$badinfo = "Please enter a track title. <br />";
$badattempt = true;
}
if (strlen($isrc) > 1){
if (strlen($isrc) != 12){
$badinfo = "Please enter ISRC correctly it should be 12 characters with no dashes i.e. GBAAA0700000. <br />";
$badattempt = true;
}
}

if ($badattempt == false){
$duration = str_replace(".", ":", $duration);

$query = "INSERT INTO `track` SET `title`='".$title."', `year`='".$track_year."', `duration`='".$duration."', `isrc`='".$isrc."', `composer`='".$composer."', `arranger`='".$arranger."', `lyricist`='".$lyricist."', `explicit_lyrics`='".$explicit_lyrics."', `band_id`= '".$_SESSION['userid']."', `genre_id`='".$genre."', `copyright`='".$publisher."' WHERE track_id = '".$trackid."'";
$result = mysql_query($query)
or die ( "error: ".mysql_error() );

$linkchoice = 3;
$query3 = "select title from track where album_id = " .$albumid;
$result3 = mysql_query($query3);

while($row = mysql_fetch_array($result3)){
if ($row['title'] == ''){
$linkchoice = 2;
}
}
if ($linkchoice == 2){
$number = $number++;
redirect_url("addtrack_test.php?albumid=".$albumid );
} else {
redirect_url("content_test.php?albumid=".$albumid. "&f=1");
}
}
}
?>


<!-- DIV LEFT
<div class="left">
<br />
<b>Releases</b>
<br /><br />
<?
if (isset($albumid)){
$album = $albumid;
} else{
$album = get_default_albumid();
}

if (!isset($trackid)){
echo $trackid;
$trackid = get_default_trackid($album);
}

$publisher = "'Copyright Control'";
get_albums("content_test.php");
?>
<form action="addalbum_test.php" method="post">
<input type="submit" value="Add New Release">
</form>
</div>
END DIV LEFT -->


<!-- DIV left£¬right -->
<div class="content">
<?
$query1 = "select track_id, title, track_number from track where album_id = " .$albumid. " order by track_number ASC";
$result1 = mysql_query($query1);
$number = mysql_num_rows($result1);
?>
<b>There are <?echo $number?> tracks in <i><?get_album_name($album)?></i>:</b>
<br /><br /></u>
<a href ="content_test.php?albumid=<?php print $albumid?>"><font size="1" style="text-decoration: none;">< back to album info</font></a><br />

<ul>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="2">
<tr>

<td><font size=1>#</td>
<td><font size=1>Title</td>
<td><font size=1>Duration</font></td>
<td><font size=1>Year</td>
<td><font size=1>Composer</td>

<td><font size=1>Explicit Lyrics</td>
<td><font size=1>Publisher</td>
<td><font size=1>ISRC</td>
<td><font size=1>Genre</td>
</font>
</tr>
<form action="addtrack_test.php?addtrack=1" method="post">


<?
while($row = mysql_fetch_array($result1)){
if($row['track_number'] != $tracknumber){
if(strlen($row['title']) < 1){
?>

<tr>
<input type="hidden" name="albumid" value=<? echo $albumid ?>>
<input type="hidden" name="trackid" value=<? echo $trackid ?>>

<td><? echo $row['track_number'] ?></td>

<td><input type="text" size="30" maxlength="255" name="title" value="<? echo $title ?>"></td>

<td><input type="text" size="18" maxlength="5" name="duration" class="iMask" id="duration"
value="<? echo $duration ?>"></td>

<td><? echo get_trackyears() ?></td>

<td><input type="text" size="18" maxlength="255" name="composer" value="<? echo $composer ?>"></td>

<td><? echo get_track_explicitlyrics($trackid) ?></td>

<td><input type="text" size="18" maxlength="255" name="publisher" value="<? echo $publisher ?>"></td>

<td><input type="text" size="18" maxlength="255" name="isrc" value="<? echo $isrc ?>"></td>

<td colspan='2'><? echo get_track_genre($trackid) ?></td>

</tr>


<?
} else if (strlen($row['title']) >= 1) {
?>
<td><font size="1"><? echo $row['track_number'] ?></td>

<td><input type="text" size="30" maxlength="255" name="title" value="<? echo $title ?>"></td>

<td><input type="text" size="8" maxlength="5" name="duration" class="iMask" id="duration"
value="<? echo $duration ?>"></td>

<td><? echo get_trackyears() ?></td>

<td><input type="text" size="18" maxlength="255" name="composer" value="<? echo $composer ?>"></td>

<td><? echo get_track_explicitlyrics($trackid) ?></td>

<td><input type="text" size="18" maxlength="255" name="publisher" value="<? echo $publisher ?>"></td>

<td><input type="text" size="18" maxlength="255" name="isrc" value="<? echo $isrc ?>"></td>

<td colspan='2'><? echo get_track_genre($trackid) ?></td>

</tr>
<?
}
}
}
?>
</ul>
<input type="submit" class="button" value="Submit">
</form>
</table>


<?
if ($badattempt == true){
echo "<b style=\"color: #000000\">* ".$badinfo."</b><br />";
}
?>

<p align="left">
<p align="left"><font size="1"><i>(Fields marked with an&nbsp;*&nbsp;are required)</font></I></p>






<!-- END DIV RIGHT -->

</div>
<!-- END DIV CONTENT -->

<? include("includes/footer.php") ?>
flyingbumhawk is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-09-2010, 11:43 AM Re: Updating multiple database fields with one form
SnapCount80's Avatar
Experienced Talker

Posts: 48
Name: Andrew
Location: Fort Wayne, IN
Trades: 0
Your link is broken.
Also, it is recommended that you use code tags when displaying code.

I believe you can achieve what you are looking for by storing the form data as arrays on the form page. Then on the php page, loop through the arrays and store the data to a new database field with each pass. Follow?

Partial Example:
HTML Code:
<input name="composer[]" type="text">
PHP Code:
//Open your Database

$arraysize sizeof($_POST["composer"]);
$i[] = array();
$i=0;
do
{
  
$composer $_POST["composer"][$i];
  
//Insert data into database
  
$i++;
}
while (
$i<=$arraysize 1); 
__________________

Please login or register to view this content. Registration is FREE

SnapCount80 is offline
Reply With Quote
View Public Profile Visit SnapCount80's homepage!
 
Reply     « Reply to Updating multiple database fields with one form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19118 seconds with 12 queries