http://www.dougtreadwell.com/articles/mysql-shortcuts.php
<?php

function mysql_insert($table, $input, $columns) {
foreach ( $columns as $column ) {
$values[]  = ‘”‘ . $input[$column] . ‘”‘;
}
$columns = implode(‘, ‘, $columns);
$values  = implode(‘, ‘, $values);
echo ‘insert into ‘ . $table . ‘ ( ‘ . $columns . ‘ )
values ( ‘ . $values . ‘ )’;

mysql_query(‘insert into ‘ . $table . ‘ ( ‘ . $columns . ‘ )
values ( ‘ . $values . ‘ )’);
}

function mysql_insert2($table, $input) {

$show = mysql_query(“show columns from $table  where ‘Key’ != ‘PRI'”);

while ( $column = mysql_fetch_assoc($show) ) {
if ( isset($input[$column[‘Field’]]) ) {
$columns[] = $column[‘Field’];
$values[]  = ‘”‘ . $input[$column[‘Field’]] . ‘”‘;
}
}
$columns = implode(‘, ‘, $columns);
$values  = implode(‘, ‘, $values);
echo ‘insert into ‘ . $table . ‘ ( ‘ . $columns . ‘ ) values ( ‘
. $values . ‘ )’;
mysql_query(‘insert into ‘ . $table . ‘ ( ‘ . $columns . ‘ ) values ( ‘
. $values . ‘ )’);
}

function mysql_update($table, $input) {
$show = mysql_query(‘show columns from ‘ . $table);
while ( $column = mysql_fetch_assoc($show) ) {
if ( $column[‘Key’] != ‘PRI’
&& isset($input[$column[‘Field’]]) ) {
$updates[] = $column[‘Field’] . ‘ = “‘
. $_POST[$column[‘Field’]] . ‘”‘;
} else if ($column[‘Key’] == ‘PRI’ ) {
$primary_key = $column[‘Field’];
}
}

$updates = implode(‘, ‘, $updates);
mysql_query(“update  $table  set  $updates  where  $primary_key  = $input[$primary_key] “);

}

function mysql_select($table, $key) {

if($key != ‘all’)
{

$show = mysql_query(“show columns from $table  where ‘Key’ != ‘PRI'”);
$primary_key_column = mysql_fetch_assoc($show);

$primary_key = $primary_key_column[‘Field’];

$record = mysql_query(‘select * from ‘ . $table . ‘ where ‘ .     $primary_key . ‘ = “‘ . $key . ‘”‘);
}
else
{
$record = mysql_query(‘select * from ‘ . $table );
}

return $record;
}

function mysql_delete($table, $key) {
$show = mysql_query(“show columns from $table  where ‘Key’ != ‘PRI'”);
$primary_key_column = mysql_fetch_assoc($show);
$primary_key = $primary_key_column[‘Field’];
mysql_query(‘delete from ‘ . $table . ‘ where ‘ .     $primary_key . ‘ = “‘ . $key . ‘”‘);
}

$conn = mysql_connect(“localhost”,”root”,”root”);
$db = mysql_select_db(‘test’);
$table = ‘course’;
$data=mysql_delete($table, ‘8’);
print_r($data);

?>
<form method=”post” action=””>
<table>
<TR>
<TD>NAME</TD>
<TD><input type=”text” name = “name” /></TD>
</TR>

<TR>
<TD>PASSWORD</TD>
<TD><input type=”password” name = “password” /></TD>
</TR>
<TR>
<TD>MOBILE NO</TD>
<TD><input type=”text” name = “mno” /></TD>
</TR>
<TR>
<TD colspan=2>
<input type=”submit” name = “save” value=”save” /></TD>
<input type=”hidden” name =”id” value = “5”/>
</TR>

</table>
</form>

Advertisements