phprockers-logo

Insert query in mysql with php

0 comments
The syntax for inserting values into tables,

INSERT INTO
    table_name (`col1`, `col2`, `col3`,.....)
    VALUES ('val1', 'val2', 'val3',.....);    

<?php

$con = mysql_connect('localhost', 'root','');
mysql_select_db('dbname', $con) or die(mysql_error());

$query = "INSERT INTO table_name (`sno`, `name`, `marks`, `rank`,`post_of_date`) VALUES ('3', 'PHP Developer', '521', '36',now())";    
$ok = mysql_query($query);

if($ok)
echo "Inserted successfully";
else
echo "Data's are not inserted in to table";

?>



sno name marks rank post_of_date
1 Ram 407 3 09-04-2001
2 krishnan 397 3 09-04-2001
3 PHP Developer 521 36 27-03-2012

Show the content or text when mouse over the link

0 comments

<style type="text/css">
<!--
.box {
background-color: #F4F4F4;
border: 1px solid #CCC;
height: 150px;
width: 225px;
padding: 5px;
display:none;
position:absolute;
}


-->
</style>
<script type="text/javascript" language="JavaScript">
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
if(self.pageYOffset) {
rX = self.pageXOffset;
rY = self.pageYOffset;
}
else if(document.documentElement && document.documentElement.scrollTop) {
rX = document.documentElement.scrollLeft;
rY = document.documentElement.scrollTop;
}
else if(document.body) {
rX = document.body.scrollLeft;
rY = document.body.scrollTop;
}

How to delete checked checkbox rows in php?

0 comments
<?php
if($_REQUEST['btndelete'] != '')
{
    if(!empty($_REQUEST['checkboxstatus'])) {
        $checked_values = $_REQUEST['checkboxstatus'];
        foreach($checked_values as $val) {
            $sqldel = "delete from subscribe where id = '$val'";
            $resdel = mysql_query($sqldel);
            if($resdel)
                $error_log = 1;
            else
                $error_log = 2;
        }
    }
}

How to send the email in php?

0 comments
Easily send the email in php, you have to follow some steps
<?php
    $mail_to = "phprockers.blogspot@gmail.com";
    $mail_subject = "Introducing New concept in PHP";
    $body_content = "Hi <br/> We are introducing new method in php as well as we are teaching php clearly. Please click here and watch <a href='http://phprockers.blogspot.in/'>php tutorial</a>";
    if(mail($mail_to, $mail_subject, $body_content)){
        echo "Email sent successfully";
    } else {
        echo "Email sending problem. Please try again.";
    }
?>

How to send the email with attachment in php?

0 comments
Very simple to send the email with attachment with php validation.

First we have to write html form for upload the attchement.

<form name="uploadRes" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF'];" >
<input type="file" name="resume" id="resume" />
<input type="submit" name="res-submit" id="res-submit" value="Send Resume"  />
</form>

Validation for attaching the file. Here we have to find the file type, then send the email to particular function.

if($_REQUEST['res-submit'] != '') {
    if(!empty($_FILES)) {
        function getExt($file) {
            $dot = strrpos($file, '.') + 1;
            return substr($file, $dot);
        }


How to integrate "xing" share button in your site?

1 comments

Steps:
1.Select The button layout as you want display in your site.
2.Provide the Url for which you are going to display the xing share count.(This is optional)
3.Select the language.
4.Copy the code in the textarea and paste it in your page.
Thats it. The All new Xing share button will be displayed in your site.

How to get the post tags by category name in wordpress?

0 comments
Paste this code wherever you want to get post tags for specific category name in wordpress.

<?php

$cat_name = "Test Cat";
query_posts('category_name='.$cat_name); //give the your category name here.

if (have_posts()) : while (have_posts()) : the_post();
$postTags = get_the_tags();
    if ($postTags) {
        foreach($postTags as $tag) {
            $all_tags[] = $tag -> name;
        }
    }
endwhile; endif;

if(!empty($all_tags)) {
    $unique_tags = array_unique($all_tags); //Removes the duplicates tags in the all_tags_arr array.
    echo '<pre>'.print_r($unique_tags, true).'</pre>';
} else {
    echo "No post tags are available for ".$cat_name." - category";
}

?>