Even though LAMP is the most familiar compination we can try with other databases too in PHP. Here is a sample for connecting to SQLServer from PHP.
<?php
$myServer = "ServerName";
$myUser = "UserName";
$myPass = "Password";
$myDB = "DBName";
$dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Connection Failed");
$selected = mssql_select_db($myDB, $dbhandle) or die("Couldn't open the db");
$query = "SELECT postid, postname, time";
$query .= "FROM Revolution-of-web";
$query .= "WHERE label='PHP'";
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["postid"] . $row["postname"] . $row["time"] . "</li>";
}
mssql_close($dbhandle);
?>
Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts
Thursday, November 12, 2009
Sending mails by PHP.
Most of the time people are struggling with mailing concept of PHP.
Here is an example to achieve this.
<form action="sendmail.php3" method="POST">
<input type="text" size="22" name="subject" value="MailContent">
< form action="sendmail.php3" method="POST">
< input type="text" size="22" name="subject" value="MailContent">
<?
$to = "Senderemail@revolution-of-web.blogspot.com";
$from_header = "From: $from";
if($contents != "")
{
mail($to, $subject, $contents, $from_header);
header("Location: $HTTP_REFERER");
}
else
{
print("<HTML><BODY>Error, no comments were submitted!");
print("</BODY></HTML>");
}
?>
Here header("Location: $HTTP_REFERER"); will redirect back to the same url that visitor has came from.
It can be modified, incase if you wish to show any other url as follows.
header("Location: mailsucceed.html");
Sending HTML Email: Content-Type: text/html needs to be mentioned in case if you require to send a html email.
Here is an example to achieve this.
<form action="sendmail.php3" method="POST">
<input type="text" size="22" name="subject" value="MailContent">
< form action="sendmail.php3" method="POST">
< input type="text" size="22" name="subject" value="MailContent">
<?
$to = "Senderemail@revolution-of-web.blogspot.com";
$from_header = "From: $from";
if($contents != "")
{
mail($to, $subject, $contents, $from_header);
header("Location: $HTTP_REFERER");
}
else
{
print("<HTML><BODY>Error, no comments were submitted!");
print("</BODY></HTML>");
}
?>
Here header("Location: $HTTP_REFERER"); will redirect back to the same url that visitor has came from.
It can be modified, incase if you wish to show any other url as follows.
header("Location: mailsucceed.html");
Sending HTML Email: Content-Type: text/html needs to be mentioned in case if you require to send a html email.
Subscribe to:
Posts (Atom)
...
Obstacles are those frightful things you see when you take your eyes off your goal.------> by Henry Ford