20
Jul

Easy Mysql insert with PHP

Let’s see how to cut short code to insert or update mysql queries just with few lines of code.The key to making this happen is to name your html form elements with the same names as your column names.


<form name="myform" method="post" action="insert.php">

Name:<input type="text" name="name" />

Comment:<textarea cols="42" rows="8" name="comment"></textarea>

<input type="submit" value="Send" />

</form>

Observe that there is no name provided for the submit button.Now on to the PHP code.


<?php

$keys = "";

$vals = "";

foreach($_POST as $key=>$val) {

$keys .= "`".$key."`,";

$vals .="'".$val."',";

}

//Remove the last comma, else SQL will fail

$keys = substr($keys,0,-1);

$vals = substr($vals,0,-1);

$sql = "insert into table_name ($keys) values ($vals)";

mysql_query($sql);

?>
20
Jul

Simplest Php Image Gallery


<script type="text/javascript">
function changeimg(e){
var a = document.getElementById('img');
a.src = e;
}
</script>

<div align="center">

<img src="images/1.jpg" id="img" width="400" height="400" />

</div>

<br /><br /><br />

<?php
$filenames = glob('images/*');
foreach ($filenames as $filename){

echo '<div style="text-align:center;float:left;"><a href="#" onmouseover="changeimg(\''.$filename.'\');"><img src="'.$filename.'" width="100" height="100" style="border:1px solid #333;padding:20px; margin:10px;" /></a><br />'.basename(substr($filename,0,-4)).'<br /></div>';
}
?>
18
Jul

Adonis - The Making Part 1

A simple yet powerful framework to offer flexible and rapid web development.

The Development is still ongoing, it is based on MVC architechture based on ADOdb database abstraction layer. Ext Js has been chosen as native support for ajax and layout management as it is flexible and can be used with adapters to go with protoype, Jquery or Yui.

The latest SVN code can be checked out from http://adonis.googlecode.com/svn/trunk

Please contact us if you would like to participate in development

18
Jul

Easy way of making a random password with php


<?php

echo substr( md5 ( rand( 0, 99999999 ) ) );

?>

Simple eh!!