Get Number of rows
$result = mysql_query($query)or die(mysql_error());
$res = mysql_fetch_array($result);
$num_rows = mysql_num_rows($result);
Last Inserted ID
$cart = mysql_query( "SELECT LAST_INSERT_ID() inse" );
while($row = mysql_fetch_array($cart)) {
$cartid = $row["inse"];
}
Add New Row Dynamically
Send Mail
NOTE: Please download the attached PHPMailer rar file and put in root folder of the project
$email1='phpmailer/class.phpmailer.php';
require_once($email1);
$mail = new PHPMailer();
$mail->IsSMTP();
//GMAIL config
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the server
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "username@gmail.com"; // GMAIL username
$mail->Password = "password";
//End Gmail
$mail->From = "";
$mail->FromName = "E-Crime Investigation";
$mail->Subject = "E-Crime Investigation - Criminal Registration";
$message = "E-Crime Investigation - Criminal Registered successfully. <br/> Criminal Name: " . $cname;
$mail->MsgHTML($message);
// $to=$result['email'];
$mail->AddAddress("To Address","noreply-GEOCMS");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send())
{
echo '<script>alert("Criminal Not Registered");window.location.replace("criminalslist.php");</script>';
}
Godaddy If server issue use the below
$email1='phpmailer/class.phpmailer.php';
require_once($email1);
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Mailer = "smtp";
$mail->Host = "relay-hosting.secureserver.net;smtpout.secureserver.net";
$mail->From = "admin@ezhyd.co.in";
$mail->FromName = "admin";
$mail->AddAddress("info@jsnsoft.com", "JSNSoft");
$mail->Subject = "Subject";
$mail->Body = "<b>Body</b><br/>test";
$mail->IsHTML(true);
if(!$mail->Send())
{
print "not sent";
} else {
print "Message Sent";
}
Send SMS Code
$user = "user";
$password = "password";
$api_id = "api";
$baseurl ="http://api.clickatell.com";
$msg="Your visa is expiring pls contact administration department for immediate action";
$text = @urlencode($msg);
$to = $_POST['contact'];
// auth call
$url = "$baseurl/http/auth?user=$user&password=$password&api_id=$api_id";
// do auth call
$ret = @file($url);
// split our response. return string is on first line of the data returned
$sess = @split(":",$ret[0]);
if ($sess[0] == "OK")
{
$sess_id = trim($sess[1]); // remove any whitespace
$url = "$baseurl/http/sendmsg?session_id=$sess_id&to=$to&text=$text";
// do sendmsg call
$ret = @file($url);
$send = @split(":",$ret[0]);
if ($send[0] == "ID")
$msg = "success message ID: ". $send[1];
else
$msg = "send message failed".$ret[0];
}
else
{
//echo "Authentication failure: ". $ret[0];
// exit();
}
CURL with Get Parameters
$url = "http://www.siegsms.com/SendingSms.aspx";
$params = array('userid'=>'userid', 'pass'=>'pass', 'phone'=>$_SESSION["Phone"],'msg'=>$msgUser,'title'=>'TITLES');
$url .= '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$data = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status == 200) {
print "Pass";
}
Important SharePointInternalURLs
DropDown
Showing Values
$rs=mysql_query("select * from categories");
<select id="Category" name="Category" >
<?php while($dt = mysql_fetch_assoc($rs))
{
echo '<option value='.$dt['CT_NAME'].'>'.$dt['CT_NAME'].'</option>';
}?>
</select>
Shwoing Values Selected value
$rs=mysql_query("select CT_NAME from categories");
$sql1="select * from movies where ID = '".$_REQUEST['PID']."'";
$rs1 = mysql_query($sql1);
$result1 = mysql_fetch_array($rs1);
<select id="Category" name="Category" >
<?php while($dt = mysql_fetch_assoc($rs))
{
$sel = ($result1['Category'] == $dt['CT_NAME'])?'selected':'';
echo '<option value='.$dt['CT_NAME'].' '.$sel.'>'.$dt['CT_NAME'].'</option>';
}?>
</select>
Calendar
Find the below attachment :calendar.rar
Date Difference
$date1 = $_REQUEST['from'];
$date2 = $_REQUEST['to'];
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24))+1;
File Upload
<?php
if(isset($_POST['btnSubmit'])){
$target="RESUMES/";
$target.=$_FILES['upldResume']['name'];
move_uploaded_file($_FILES['upldResume']['tmp_name'],$target);
}
?>
<!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>
<script type="text/javascript">
function checkform(){
var varUpldResume = document.getElementById('upldResume');
if(varUpldResume.value != "")
{
var ext = varUpldResume.value.substring(varUpldResume.value.lastIndexOf(".") + 1);
//alert(ext);
if(ext.toLowerCase() != "doc" && ext.toLowerCase() != "docx")
{
alert('Please Upload .doc or .docx files only');
return false;
}
}
else
{
alert('Please Upload Updated Resume');
return false;
}
}
</script>
</head>
<body>
//Do not forgot to add enctype="multipart/form-data" to the form
<form name="Cosmo9Form" id="Cosmo9Form" enctype="multipart/form-data" action="" method="post" onsubmit="return checkform();">
Upload Resume :<input name="upldResume" type="file" />
<input type="submit" id="btnSubmit" name="btnSubmit" value="Submit" />
</form>
</body>
</html>
Code For Twitter Search API
<!--API Search tweets starts-->
<div style="height:300px;overflow:auto;width:680px;padding:0px 0px 0px 2px;">
<?php
// Date function (this could be included in a seperate script to keep it clean)
function date_diff($d1, $d2){
$d1 = (is_string($d1) ? strtotime($d1) : $d1);
$d2 = (is_string($d2) ? strtotime($d2) : $d2);
$diff_secs = abs($d1 - $d2);
$base_year = min(date("Y", $d1), date("Y", $d2));
$diff = mktime(0, 0, $diff_secs, 1, 1, $base_year);
$diffArray = array(
"years" => date("Y", $diff) - $base_year,
"months_total" => (date("Y", $diff) - $base_year) * 12 + date("n", $diff) - 1,
"months" => date("n", $diff) - 1,
"days_total" => floor($diff_secs / (3600 * 24)),
"days" => date("j", $diff) - 1,
"hours_total" => floor($diff_secs / 3600),
"hours" => date("G", $diff),
"minutes_total" => floor($diff_secs / 60),
"minutes" => (int) date("i", $diff),
"seconds_total" => $diff_secs,
"seconds" => (int) date("s", $diff)
);
if($diffArray['days'] > 0){
if($diffArray['days'] == 1){
$days = '1 day';
}else{
$days = $diffArray['days'] . ' days';
}
return $days . ' and ' . $diffArray['hours'] . ' hours ago';
}else if($diffArray['hours'] > 0){
if($diffArray['hours'] == 1){
$hours = '1 hour';
}else{
$hours = $diffArray['hours'] . ' hours';
}
return $hours . ' and ' . $diffArray['minutes'] . ' minutes ago';
}else if($diffArray['minutes'] > 0){
if($diffArray['minutes'] == 1){
$minutes = '1 minute';
}else{
$minutes = $diffArray['minutes'] . ' minutes';
}
return $minutes . ' and ' . $diffArray['seconds'] . ' seconds ago';
}else{
return 'Less than a minute ago';
}
}
// Work out the Date plus 8 hours
// get the current timestamp into an array
$timestamp = time();
$date_time_array = getdate($timestamp);
$hours = $date_time_array['hours'];
$minutes = $date_time_array['minutes'];
$seconds = $date_time_array['seconds'];
$month = $date_time_array['mon'];
$day = $date_time_array['mday'];
$year = $date_time_array['year'];
// use mktime to recreate the unix timestamp
// adding 19 hours to $hours
$timestamp = mktime($hours + 0,$minutes,$seconds,$month,$day,$year);
$theDate = strftime('%Y-%m-%d %H:%M:%S',$timestamp);
// END DATE FUNCTION
//Search API Script
$q=$_GET['q'];
if($_GET['q']==''){
$q = 'want+iphone+computer+-iPad';}
$search = "http://search.twitter.com/search.atom?q=".$q."";
$tw = curl_init();
curl_setopt($tw, CURLOPT_URL, $search);
curl_setopt($tw, CURLOPT_RETURNTRANSFER, TRUE);
$twi = curl_exec($tw);
$search_res = new SimpleXMLElement($twi);
/*echo "<h3>Twitter search results for '".$q."'</h3>";*/
## Echo the Search Data
foreach ($search_res->entry as $twit1) {
$description = $twit1->content;
$description = preg_replace("#(^|[\n ])@([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://www.twitter.com/\\2\" >@\\2</a>'", $description);
$description = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise", "'\\1<a href=\"\\2\" >\\2</a>'", $description);
$description = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://\\2\" >\\2</a>'", $description);
$retweet = strip_tags($description);
$date = strtotime($twit1->updated);
$dayMonth = date('d M', $date);
$year = date('y', $date);
$message = $row['content'];
$datediff = date_diff($theDate, $date);
?>
<script src="../ajaxtabs/Test.js" type="text/javascript" language="javascript"></script>
<?php
echo "<img src='' /><table >
<tr>
<td><div onclick='thi();'>ddddd</div><div class='user'><a href=\"",$twit1->author->uri,"\" target=\"_blank\"><img border=\"0\" width=\"48\" class=\"twitter_thumb\" src=\"",$twit1->link[1]->attributes()->href,"\" title=\"", $twit1->author->name, "\" /></a></div></td><td><div class='text'>".$description."<div class='description'>From: ", $twit1->author->name,"</div><strong>".$datediff."</strong></div></td></tr></table>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ";
}
curl_close($tw);
?>
<br />
</div>
<!--API Search tweets ends-->
To get the current pageURL
<form action="Login.php" method="post" name="frm1">