Update row record with predefined value using PHP and MySQL -


i'm trying update specific record within row predefined valued using php , mysql. not want use "input" new value defined in code.

table students

 id     name     grade     1      dave     b       update< hyperlink update.php  2      mark     c       update  3      john     e       update  4      thomas   d       update 

upon click on "update" want grade value of specific row change constant value"a", in every case. lets clicked on update within rows id "1" , "2".

desired result:

 id     name     grade     1      dave           update  2      mark           update  3      john     e       update  4      thomas   d       update  

i know how using input fields insert data myself , submit. need change data upon click on update.

this how display data:

  while ($row=mysql_fetch_array($result)){     echo ("<tr><td>$row[id]</td>");     echo ("<td>$row[name]</td>");     echo ("<td>$row[grade]</td>");     echo ("<td><center><a href=\"udapte.php?id=$row[id]\">update</a></center></td></tr>"); 

update.php

// connect server , select databse.  $order = "update students        set grade='a'        id='id'"; mysql_query($order); 

i know mysql_* not safest way it. once working modify php use pdo.thanks help

pass id of record update href of link.

1st, create links php in page.php. rhose links call same page, additional parameters within url.
code supposes records stored in array $rows...

foreach ($rows $row) {      $h = $row['name'] . ', grade: ' . $row['grade'];     $h.= ' <a href="page.php?do=update&id=' . $row['id'] . '">change grade</a>';     echo $h . '<br />';  } 

then, in page.php quite @ beginning:

if (isset($_get['do']) && $_get['do'] == 'update'] && isset($_get['id])) {    // enter update code here   // pls use mysqli_ or pdo instead of deprecated mysql_!  } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -