php - Give unique value for submit button -
in table each , every row has cell submit button.
here code
<?php # init mysql connection mysql_connect("localhost", "root", "") or die(mysql_error()) ; mysql_select_db("selfie") or die(mysql_error()) ; # prepare select query $selectsql = 'select * `image_upload` inner join user_table on image_upload.user_id=user_table.user_id flag="0" order timestamp desc'; # execute select query if( !( $selectres = mysql_query( $selectsql ) ) ){ echo 'retrieval of data database failed - #'.mysql_errno().': '.mysql_error(); }else{ ?> <table border="2"> <thead id="head"> <tr> <th id="head">user name</th> <th>category</th> <th>description</th> <th>image</th> <th>location</th> <th>status</th> </tr> </thead> <tbody> <?php if (isset($_get['submit'])) { $mobile = $_get['dmobile']; $query = mysql_query("update image_upload set flag='$mobile' " ); } if (isset($_get['submit'])) { header("location: imagemanagement.php"); } if( mysql_num_rows( $selectres )==0 ){ echo '<tr><td colspan="4">no rows returned</td></tr>'; }else{ while( $row = mysql_fetch_assoc( $selectres ) ){ echo "<tr> <td>{$row['user_name']}</td> <td>{$row['category']}</td> <td>{$row['description']}</td> <td ><img src='uploads/".$row['image']."'width=300px height=200px></td> <td>{$row['location']}</td> <td><form class=\"form\" method=\"get\"><label></label><br/> <input class=\"input\" type=\"text\" name=\"dmobile\" value=\" {$row['flag']}\" /> <br> <input class=\"submit\" type=\"submit\" name=\"submit\" value=\"update\" /> </form></td> </tr>\n"; } } ?> </tbody> </table> <?php
in here when changes , click on submit button of 1 row each , every rows updated. how can give unique value each , every submit button.
comment answer, since op said works.
op: "it's work. thank much.... :) – lanka"
add form:
<input type=\"hidden\" name=\"the_id\" value=\"{$row['id']}\" />
then add:
$theid = $_post['the_id'];
then,
$query = mysql_query("update image_upload set flag='$mobile' id = '$theid' " );
you may need play around bit, in hidden input is.
this based on having "id" column of course.
n.b.:
- you should validate user input (even if it's hidden field)
use mysqli
prepared statements, or pdo prepared statements, they're safer.
as stands, using deprecated mysql library, leaves open sql injection.
Comments
Post a Comment