Saturday, 12 April 2014

Code latest

mycontroller.php


<?php
class Mycontroller extends CI_controller
{

public function main()
{
$this->load->helper('form');
$this->load->helper('url');
$this->load->view('first_project');

if($this->input->post('sub'))
{
$this->load->model('mymodel');
$this->mymodel->data_insert();
}

}



public function list_users()
{

$this->load->helper('url');
$this->load->model('mymodel');
$data['query']=$this->mymodel->fetch_users();
$this->load->view('list_users',$data);



}


public function edit_users($edit_id)
{

$this->load->helper('form');
$this->load->helper('url');
$this->load->model('mymodel');

$query = $this->mymodel->get($edit_id);
$data['fid']['value'] = $query['user_id'];
$data['fuser']['value'] = $query['user_name'];
$data['fpass']['value'] = $query['user_pass'];
$this->load->view('edit_project',$data);


if($this->input->post('update'))
{
$this->mymodel->data_update();
}


}


}

?>



____________________________________________________


mymodel.php





<?php
class Mymodel extends CI_Model
{



  function data_insert()
  {
      $this->load->database();
      $data = array(
              'user_name'=>$this->input->post('name'),
              'user_pass'=>$this->input->post('pass'),
              );
      $this->db->insert('tbl_user',$data);
 }



  function fetch_users()
  {
      $this->load->database();
      $query=$this->db->get('tbl_user');
      return $query->result();

  }


  function get($id)
  {
      $this->load->database();
      $query=$this->db->get_where('tbl_user',array('user_id'=>$id));
      return $query->row_array();

  }



 

}
?>


____________________________________________________________


first_project.php


<html>
<body>
<h1>MyFirst Form</h1>

<?php echo form_open('mycontroller/main'); ?>
<?php echo "Name"; ?>:
<?php echo form_input('name'); ?>
</br>
<?php echo "Password"; ?>:
<?php echo form_password('pass'); ?>
</br>
<?php echo form_submit('sub','Submit!');  ?>
<?php echo form_close(); ?>
</br>
<?php echo anchor("mycontroller/list_users","List of Users");?>

</body>

</html>


___________________________________________________________________


list_users.php




<html>
<body>
<h1>List of Users</h1>

<?php
echo "<table border='1'>";
echo "<tr>";
echo "<td>";
echo "Id";
echo "</td>";
echo "<td>";
echo "Name";
echo "</td>";
echo "<td>";
echo "Password";
echo "</td>";
echo "<td>";
echo "Edit";
echo "</td>";
echo "<td>";
echo "Delete";
echo "</td>";
echo "</tr>";
foreach ($query as $row)
{
echo "<tr>";
echo "<td>";
echo $row->user_id;
echo "</td>";
echo "<td>";
echo $row->user_name;
echo "</td>";
echo "<td>";
echo $row->user_pass;
echo "</td>";
echo "<td>";
echo anchor('mycontroller/edit_users/'.$row->user_id,'Edit');
echo "</td>";
echo "<td>";
echo "Delete";
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>







<?php echo anchor("mycontroller/main","Back");?>




</body>

</html>




_______________________________________________________


edit_project.php



<html>
<body>
<h1>MyFirst Form</h1>

<?php echo form_open('mycontroller/main'); ?>
<?php echo "Id"; ?>:
<?php echo form_input('id',$fid['value']); ?>
</br>
<?php echo "Name"; ?>:
<?php echo form_input('name',$fuser['value']); ?>
</br>
<?php echo "Password"; ?>:
<?php echo form_input('pass',$fpass['value']); ?>
</br>
<?php echo form_submit('update','Update!');  ?>
<?php echo form_close(); ?>
</br>
<?php echo anchor("mycontroller/list_users","List of Users");?>

</body>

</html>



___________________________________________________

Friday, 11 April 2014

My First Code igniter

firstproject.php {VIEW}


<html>
<body>
<h1>MyFirst Form</h1>

<?php echo form_open('mycontroller/main'); ?>
<?php echo "Name"; ?>:
<?php echo form_input('name'); ?>
</br>
<?php echo "Password"; ?>:
<?php echo form_password('pass'); ?>
</br>
<?php echo form_submit('sub','Submit!');  ?>
<?php echo form_close(); ?>
</br>
<?php echo anchor("mycontroller/list_users","List of Users");?>

</body>

</html>

____________________________________________________________________________
listusers.php {VIEW}


<html>
<body>
<h1>List of Users</h1>

<?php

foreach ($query as $row)
{
echo $row->user_id;
echo $row->user_name;
echo $row->user_pass;
echo "<br>";
}

?>







<?php echo anchor("mycontroller/main","Back");?>




</body>

</html>

_____________________________________________________________

mycontroller.php {CONTROLLER}


<?php
class Mycontroller extends CI_controller
{

public function main()
{
$this->load->helper('form');
$this->load->helper('url');
$this->load->view('first_project');

if($this->input->post('sub'))
{
$this->load->model('mymodel');
$this->mymodel->data_insert();
}

}



public function list_users()
{

$this->load->helper('url');
$this->load->model('mymodel');
$data['query']=$this->mymodel->fetch_users();
$this->load->view('list_users',$data);



}


}

?>


_________________________________________________________________


mymodel.php {Model}


<?php
class Mymodel extends CI_Model
{



  function data_insert()
  {
      $this->load->database();
      $data = array(
              'user_name'=>$this->input->post('name'),
              'user_pass'=>$this->input->post('pass'),
              );
      $this->db->insert('tbl_user',$data);
}



  function fetch_users()
  {
      $this->load->database();
      $query=$this->db->get('tbl_user');
      return $query->result();
 
  }


}


______________________________________

Friday, 14 February 2014

Mail Function

index.php




$mymail='vintechnosys@gmail.com';
sendmailtoclient($email,$mymail);
sendmailtoadmin($mymail,$email,$name,$subject,$message);


_________________________________________________________________________



function.php


<?php

function sendmailtoclient($toclient,$fromadmin)
{
$client=$toclient;
$subject="WELCOME TO VIN Technosys";
$message="Your enquiry has been received by us...We will contact you shortly<br>THANK YOU.";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <'.$fromadmin.'>' . "\r\n";
mail($client,$subject,$message,$headers);
echo"MESSAGE SENT";
}
function sendmailtoadmin($toadmin,$fromclient,$nam,$sub,$msg)
{

$toadmin=$toadmin;
$subject=$sub;
$message="ONE USER (".$nam.") with mailid(".$fromclient.") has enquired you as (".$msg.")";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <'.$fromclient.'>' . "\r\n";
mail($toadmin,$subject,$message,$headers);

}

?>

Tuesday, 11 February 2014

Form Validation


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>



</head>

<body>

<?php
include("connect.php");
function test_input($data)
{
$data=trim($data);
$data=stripslashes($data);
$data=htmlspecialchars($data);
return $data;
}

$nameErr=$emailErr=$phoneErr="";
$myname=$myemail=$myphone="";

if($_SERVER['REQUEST_METHOD']=='POST')
{
$flag=1;
if(empty($_POST['name']))
{

$nameErr="* Name is required";
}
else
{
$myname=test_input($_POST['name']);
if(!preg_match("/^[a-zA-Z]*$/",$myname))
{
$flag=0;
$nameErr="* Only letters and white space";
}

}


if(empty($_POST['email']))
{

$emailErr="* email is required";
}
else
{
$myemail=test_input($_POST['email']);
if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$myemail))
{
$flag=0;
$emailErr="* Invalid email id";
}
}


if(empty($_POST['phone']))
{

$phoneErr="* Phone is required";
}
else
{
$myphone=test_input($_POST['phone']);
}
if(($flag==1)&& ($myname!="")&& ($myemail!="")&& ($myphone!=""))
{
$query=mysql_query("INSERT INTO myself VALUES ('','$myname','$myemail','$myphone')");
}


}

?>
<form method="post">
Name:<input name="name" type="text" /><?php echo $nameErr;?><br />
Email:<input name="email" type="text" /><?php echo $emailErr;?><br />
Phone:<input type="text" name="phone" /><?php echo $phoneErr;?><br />
<input type="submit" value="check" name="sub" />

</form>

</body>
</html>

Image Update


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$id=$_GET['edit_id'];
include("connection/connect.php");
$sql=mysql_query("SELECT * FROM img_up WHERE up_id=$id");
$fetch=mysql_fetch_array($sql);
$name=$fetch['up_name'];
$oldimg=$fetch['up_image'];
echo $oldimg;
?>
<form method="post" enctype="multipart/form-data">
Name:<input type="text" name="name" value="<?php echo $name ;?>" />
Image:<input type="file" name="photo" />
<input type="submit" value="update" name="sub" />
</form>
<?php
include("connection/connect.php");
if(isset($_POST['sub']))
{
$q_name=$_POST['name'];
$q_image=$_FILES['photo'];
if(!empty($q_image['name']))
{
$folder='images/';
unlink($folder.$oldimg);
/*-------Check point for photo--------------*/
if($q_image['type']="images/jpeg"||$q_image['type']="images/jpg"||$q_image['type']="images/png"&&($q_image['size']<1000000))
{
/*create folder for image upload*/



/*Checking whether image name already availiable in the folder*/
if(file_exists($folder.$q_image['name']))
{
$ran_num=rand(0000,9999);
$now_name=$ran_num.$q_image['name'];
}
else
{
$now_name=$q_image['name'];
}
/*Moving the image to the created folder with the unique name*/
move_uploaded_file($q_image['tmp_name'],$folder.$now_name);
}

$upquery=mysql_query("UPDATE img_up SET up_name='$q_name',up_image='$now_name' WHERE up_id=$id");
}
else
{
echo "pls select image";
$upnquery=mysql_query("UPDATE img_up SET up_name='$q_name' WHERE up_id=$id");
}
}
?>
</body>
</html>

Image Upload


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>


<body>

<!-----------FORM--------------------------->


<form method="post" enctype="multipart/form-data">
Name <input type="text" name="name" /><br />
Image <input type="file" name="photo" /><br />
<input type="submit" name="sub"  value="upload"/><br />
</form>
<!------------Getting values fron form------>
<?php
            include("connection/connect.php");
            if(isset($_POST['sub']))
            {
$q_name=$_POST['name'];
$q_image=$_FILES['photo'];
/*-------Check point for photo--------------*/
if($q_image['type']="images/jpeg"||$q_image['type']="images/jpg"||$q_image['type']="images/png"&&($q_image['size']<1000000))
{
/*create folder for image upload*/
$folder='images/';
/*Checking whether image name already availiable in the folder*/
if(file_exists($folder.$q_image['name']))
{
$ran_num=rand(0000,9999);
$now_name=$ran_num.$q_image['name'];
}
else
{
$now_name=$q_image['name'];
}
/*Moving the image to the created folder with the unique name*/
move_uploaded_file($q_image['tmp_name'],$folder.$now_name);
}
$upquery=mysql_query("INSERT INTO img_up VALUES ('','$q_name','$now_name')");

}


?>
<form method="post">
id:<input type="text" name="myimg" /><br />
<input type="submit"  name="showit"/>
</form>
<?php
include("connection/connect.php");
if(isset($_POST['showit']))
{
$myid=$_POST['myimg'];
$fetch=mysql_query("SELECT * FROM img_up WHERE up_id='$myid'");
$fetchimage=mysql_fetch_array($fetch);

?>
<img src="images/<?php echo $fetchimage['up_image']; ?>" width="132" height="99">
<?php
}
?>
   
    <a href="list_images.php">list</a>
 



</body>
</html>