Jump to content

Updating records through the use of textbox and button inside a do while


iamjp

Recommended Posts

 

 

I am 3rd yr college student and enrolled to a subject web programming and right now i am developing a web based tabulation for scoring contestants. i am having a trouble regarding on how to update a record(score) in database when the judge is giving a score to the contestant using a textbox and a button .. the problem is that it didnt read the value from an inputed textbox :

btw the textbox and the button was inside a do while loop so everytime a new contestant was added the image will be retrieved and another textbox and button will be placed..(to sum up, every contestant has a button and textbox for inputing the score) HERE IS THE CODE..



--------> Do while for retrieving image and textboxes
do{
$count++;
echo "<td style='color:#C90;font-weight:bold;font-size:12px;' >";
echo "<div id = 'hover'>";
echo "<img src = 'images/" . $result['imagename'] . "' height='300px;' width='300px;' class='img'>";
echo '<br/>';
echo $result['Name'];
echo '<br/>';
echo $result['course'];
echo '<br/>';
echo $result['branch'];
$ID =  $result['ID']; 
echo $result['ID'];


echo '<div class = "hover">';
echo "<form method='post' style='position:relative; bottom:-120px; right:-50px;'>";
echo "<table>";
echo "<tr>";
echo "<td>";
echo "SCORE";
echo "</td>";
echo "<td>";
echo '<input type="text" name="txtscore" style="height:30px; width:50px; background-color:#923227; box-shadow:1px 1px #FFF; color:#C90;font-weight:bold; font-size:16px;"/>';
echo "</td>";
echo "<td>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
echo "<a href = 'fasttrackscw.php?id=".$ID."'>";
echo "<input type='submit' name='btn1'>";
echo "</a>";
echo '</div>';
echo "</div>";
echo "</td>";
$result=mysql_fetch_assoc($query);


if($count >= $max){
//reset counter
$count = 0;
//end and restart
 echo "</tr><tr>";




}


}


while($result);


--------> Query for updating
if(isset($_POST['btn'])){


@$id  =$_GET['id'];
$sql = "update tblfastracks set casualwear = '$_POST[txtscore]' where contestantid = '$id'";
mysql_query($sql,$connection);
}

Edited by mac_gyver
code tags please
Link to comment
Share on other sites

Change these lines

echo "</form>";
echo "<a href = 'fasttrackscw.php?id=".$ID."'>";
echo "<input type='submit' name='btn1'>";
echo "</a>";

to

echo "<input type='hidden' name='id' value='$ID'>";
echo "<input type='submit' name='btn'>";
echo "</form>";

so the id and txtscore are both POSTed in the form data when the submit button ("btn" by the way) is clicked

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.