Archive

Archive for the ‘php’ Category

ODBC Viewer

February 28th, 2007 ^Lestat No comments

I had recently been peeking into a SQL database via Microsoft Access. I got quite used to browsing all the tables and fields, seeing their data types, and visually seeing their relationships. I’ve just began a project that connects to a proprietary(aged) database that uses ODBC to connect to it. Access would not allow me to view this the same (At least I couldn’t figure it out).

After a quick search I found a freeware application called passportODBC(You can download from other locations/ sites). It does require some information from you to register it. Some basic info like your name, and email and a phone number.

passportODBC

It’s not as fast as access and SQL server 2005, but I’m suspecting a lot of that has to do that it is ODBC. It’s really quite simple to use. Choose your data source, enter some credentials and go. You can view tables, all the fields, and the field attributes.

ODBC, programming, database

Update 2/28/07 1:20PM
Embassy Software offers the download direct from their site.

Update 5/16/07
I found a more simple tool for viewing via ODBC. You can compose queries and the likes. It’s much more simple to use (for me anyways) ODBC View can be downloaded from sliksoftware.co.nz

Categories: Computing, Programming, php Tags:

REGEX Library

March 9th, 2006 ^Lestat 2 comments

I was working up a form and needed to come up with an email regex. I know by now I probably should have my own regex library, or even be able to write my own – but I haven’t exercised my regex skills enough. Often time doesn’t allow an extensive learning period when your already half way through creating a form!

I came across this great regex library at regexlib.com. It’s searchable, offers on the fly tests of user contibuted regular expresssions, rss feeds of recently added patterns, and contains a Cheat Sheet for regex reference.

Of course, programmer beware. Be careful copying and pasting code. And definately test that code before you implement it.

regex, php

Categories: Programming, php, php Snippets Tags:

php: syntax woes

January 3rd, 2006 ^Lestat No comments

Today I fought what I thought was some kind of permissions error. I was learning how to create a database table in mySQL with php.

After 3 hours I figured out my error was due to syntax.
“AUTO-INCREMENT” is not the same as “AUTO_INCREMENT”

I looked over that line at least a thousand times thinking – thats right.

When you are trouble shooting code:
Break down the elements.
Print out the variables print_r();
Put in escape messages while you are creating:

if($this_is_true){
  print("Its all good<br />");
} else {
  print("Houston, we've got a problem");
}

or print all the elements getting $_POSTED:

print_r($_POST);

or print all the elements in an array:

print_r($myArray);

…it only takes a few seconds to code that temporarily in to your code to help find problems.

Categories: Programming, php Tags:

php: Dynamically fill a select box

December 30th, 2005 ^Lestat 1 comment

One way to fill a select box with array elements.

<html>
<head>
<title>Select Box</title>
</head>
<body>

< ?php
$myArray = array('cat' , 'dog' , 'mouse' , 'cow');
?>

<select name="myselect">
<option value=""></option> // Sets blank entry *optional*
< ?php
foreach($myArray as $value){ // Loop through each element
  print("<option value=\"$value\">$value<option>");
}
?>
</option></select>

</body>
</html>

php, select, drop down

Categories: Programming, php Tags:

php: Save browsed page as $var and send using phpMailer

December 28th, 2005 ^Lestat 3 comments

You can store an entire page as if it were opened in a browser, including all dynamic
data. Here’s how…

(Please use caution copying/pasting. Quotes can be a problem with the current plugin)
For this example we are going to build a form and the results using phpMailer in an html format:

form.php
results.php
preview.php
sendmail.php

form.php:

< ?php
//Start a session
session_start();
header("Cache-control: private"); // IE 6 Fix.
?>

<html>
<head>
<title>Form</title>
</head>
<body>

<form method="POST" action="preview.php">
First Name: <input type="text" name="fName" value="<?php print("$_SESSION[fName]"); ?/>" />
<br />
Last Name: <input type="text" name="lName"value="<?php print("$_SESSION[lName]"); ?/>" />
<input type="submit" name="submitButton"  value="submit" />
</form>

</body>
</html>

preview.php:

< ?php
//Start a session
session_start();
header("Cache-control: private"); // IE 6 Fix.
?>

<html>
<head>
<title>Your Results</title>
</head>
<body>

< ?php
include("results.php");
?>

</body>
</html>

results.php:

< ?php
//Start a session
session_start();
header("Cache-control: private"); // IE 6 Fix.
?>

<html>
<head>
<title></title>
<style type="text/css">
.firstname{
  font: 12px verdana green;
}

.lastname{
  font: 14px arial red;
}
</style>
</head>
<body>

< ?php print("<p class=\"firstname\">Hello $fName"); ?>
< ?php print("<p class=\"lastname\">Your last name is $fName"); ?>

</body>
</html>

And now the sendmail.php and gathering the output in a $var:

< ?php
//Start a session
session_start();
header("Cache-control: private"); // IE 6 Fix.

// call the mail class
require("class.phpmailer.php");
$mail = new PHPMailer();

// Set mail headers & connection
$mail->IsSMTP(); // tell phpMailer were using smtp
$mail->Host = "smtp.server.com"; // SMTP server
$mail->SMTPAuth =true; // turn on smtp auth
$mail->Username = "mail@domain.com"; //smtp username
$mail->Password = "password"; //smtp password
$mail->From = "user@domain.com";
$mail->FromName = "$fName";
$mail->AddAddress("fromAddress@domain.com"); // From address

$mail->Subject = "Form Results";
$mail->IsHTML(true); // tell phpMailer we're sending html email

// *** Grab Output Of HTML File as if it were opened in browser ***
ob_start();
include("results.php");
$htmlbody = ob_get_contents(); // adding output to the variable
ob_end_clean();

// *** Set the htmlbody variable in the email ***
$mail->Body = "$htmlbody";

// return results
if(!$mail->Send()){
	print("Mail was NOT sent<br />");
	print("Mailer Error: " . $mail->ErrorInfo );
} else {
	print("Thank you. Your mail was sent.");
?>

The following code is what grabs the output as if it were opened in a browser. The mail form was just an example. I’m sure there are other uses for this.

// *** Grab Output Of HTML File as if it were opened in browser ***
ob_start();
include("results.php");
$htmlbody = ob_get_contents(); // adding output to the variable
ob_end_clean();

Comments? Suggestions? See errors that should be changed? Feel free to comment.

phpMailer, php html email, php email, php get contents, php form data

Categories: Computing, Programming, php Tags: