Warning: Constant ABSPATH already defined in /home/raypasto/www/www/wordpress/wp-config.php on line 26

Warning: Cannot modify header information - headers already sent by (output started at /home/raypasto/www/www/wordpress/wp-config.php:26) in /home/raypasto/www/www/wordpress/wp-includes/feed-rss2.php on line 8
database – Dr. Ray Pastore's Instructional Technology Blog https://raypastore.com/wordpress Thu, 17 Nov 2011 13:04:47 +0000 en-US hourly 1 https://wordpress.org/?v=5.7.15 166124113 PHP Contact Mail Form https://raypastore.com/wordpress/2011/11/php-contact-mail-form/ https://raypastore.com/wordpress/2011/11/php-contact-mail-form/#respond Thu, 17 Nov 2011 13:04:47 +0000 https://raypastore.com/wordpress/?p=554 I know I have another of these posted on my blog however that one assumes that php global settings is OFF and many servers have it set to ON. So here is one that should work regardless of your server settings. To see an example of this working, just click on the contact page of my website in the links above.

Code:

<html>

<body>

<?php

//if submit button pressed

if(isset($_POST[‘submit’])){

//sending to my email
$name = $_POST[‘name’];
$email = $_POST[’email’];
$comments = $_POST[‘comments’];
$subject = $_POST[‘subject’];
$sql = “‘$name’, ‘$email’, ‘$comments'”;
$em = “‘$subject'”;
mail(‘enterYourEmailAddressHere’, $em, $sql);

echo(“<p>You message has been sent!” . “</p>”);
}
?>

<form name=”form1″ id=”form1″ method=”post” action=”<?=$PHP_SELF?>”>
<p align=”left”><strong>Name:</strong>
<input type=”text” name=”name” />
</p>
<p align=”left”>&nbsp;</p>
<p align=”left”><strong>Email:</strong>
<input type=”text” name=”email” />
</p>
<p align=”left”>&nbsp;</p>
<p align=”left”><strong>Subject:</strong>
<input type=”text” name=”subject” />
</p>
<p align=”left”>&nbsp;</p>
<p align=”left”><strong>Message:</strong>
<textarea name=”comments” cols=”60″ rows=”3″></textarea>
</p>
<p align=”left”>
<input name=”submit” type=”submit” id=”submit” value=”submit” />
<input type=”reset” name=”Submit2″ value=”Reset” />
</p>
</form>

</body>

</html>

]]>
https://raypastore.com/wordpress/2011/11/php-contact-mail-form/feed/ 0 554
Creating a login page with PHP https://raypastore.com/wordpress/2011/10/creating-a-login-page-with-php/ https://raypastore.com/wordpress/2011/10/creating-a-login-page-with-php/#respond Sat, 29 Oct 2011 12:07:57 +0000 https://raypastore.com/wordpress/?p=372 After toying around with many scripts, I have finally gotten a login script to work. (Note this code was taken from several different websites and modified to work for myself and my students). So here are the directions to create a login/password page to protect your webpages.

1. You need to create a table in a database that includes the columns: username and password. This is the first step and I am assuming you have done this.

2. Create a form in html. Here is my form code. I call this page “login.html”

<html>
<body>
<form action=”login.php” method=”post”>
<p>username
<input type=”text” name=”username” id=”username”>
</p>
<p>password
<input type=”password” name=”password” id=”password”>
</p>
<p>
<input type=”submit”>
</p>
</form>
</body>
</html>

3. Next I create a login script that tests if the login is correct or not. If correct, it logs the user in. I call this page “login.php”. Please note that the 4 words in ALL caps need to be changed to match your information.

<?php

mysql_connect(“SERVERPATHUSUALLYLOCALHOST”, “YOURUSERNAME”,
“YOURPASSWORD”);
mysql_select_db(“YOURDATABASENAME”);

$myusername=$_POST[‘username’];
$mypassword=$_POST[‘password’];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$mysql = “SELECT * FROM members WHERE username=’$myusername’ and password=’$mypassword’ “;

$result = mysql_query($mysql) or die(“cannot execute query”);

$count = mysql_num_rows($result);

if($count==1)
{
session_register(‘username’);
header(“location:home.php”); // put your home page neme here
}

else
echo “login fail – please click here to <a href=\”login.html\”>login</a>”;

?>

4. Next I create a welcome page once they have logged in. I call this “home.php”

<?php
session_start();
if(!$_SESSION[‘username’]) {
header(“location:login.php”);
}
?>

<!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>
<p>congrats you have logged in</p>
<p><a href=”test.php”>Check out test page both logged in and out</a></p>
<p><a href=”logout.php”>logout </a></p>
</body>
</html>

5. I then create a test page so you can play around with this once uploaded online. I call this “test.php”

<?php
session_start();
if(!$_SESSION[‘username’]) {
header(“location:login.php”);
}

?>

<?php
echo “you logged in as “.$username;
?>

<!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>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>This is a test page so that you can see what happens on pages when users are logged in or out.</p>
<p>&nbsp;</p>
<p><a href=”logout.php”>logout</a></p>
</body>
</html>

6. Finally I create a logout page. This logs the user out. I call this “logout.php”

<?php
session_start();
session_destroy();
echo “successfuly logout”;
?>
<!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>
<p>you have logged out</p>
<p>&nbsp;</p>
<p> <a href=”loginform.html”>log back in </a></p>
<p>visit <a href=”test.php”>test </a>page – you should not have access now and should be redirected to login screen.</p>
</body>
</html>

7. Now for every page on your site that you want to be pass protected, put this script at the very top. This script will check if the user is logged in. If logged in they can access the page. Otherwise they will be directed to the login/register page:

<?php
session_start();
if(!$_SESSION[‘username’]) {
header(“location:login.php”);
}
?>

8. You will probably need to create a form that lets people register but that is for another tutorial.

]]>
https://raypastore.com/wordpress/2011/10/creating-a-login-page-with-php/feed/ 0 372
Create a database using ICDSOFT https://raypastore.com/wordpress/2011/10/create-a-database-using-icdsoft/ https://raypastore.com/wordpress/2011/10/create-a-database-using-icdsoft/#respond Thu, 06 Oct 2011 14:21:19 +0000 https://raypastore.com/wordpress/?p=341 [youtube=http://www.youtube.com/watch?v=8I8jzuEAzCg]

]]>
https://raypastore.com/wordpress/2011/10/create-a-database-using-icdsoft/feed/ 0 341
php: Contact Page https://raypastore.com/wordpress/2010/04/php-contact-page/ https://raypastore.com/wordpress/2010/04/php-contact-page/#respond Wed, 21 Apr 2010 19:45:20 +0000 https://raypastore.com/wordpress/?p=212 for those of you interested in creating a contact page with a form (fields and submit button) that goes directly to your email, check this out. You simply need to copy and paste this code into the body of your html. You also need to put your email address in the part that says ‘YourEmailAddressHere’ and need to save the page as something like: contact.php, not something like contact.html. And thats it. Very easy to do.

<form name=”form1″ id=”form1″ method=”post” action=”<?=$PHP_SELF?>”>
<p>Name:
<input type=”text” name=”name” />
</p>
<p>&nbsp;</p>
<p>Email:
<input type=”text” name=”email” />
</p>
<p>&nbsp;</p>
<p>Subject:
<input type=”text” name=”subject” />
</p>
<p>&nbsp;</p>
<p>Message:
<textarea name=”comments” cols=”40″></textarea>
</p>
<p>&nbsp;</p>
<p>
<input name=”submitentry” type=”submit” value=”SUBMIT” />
<input type=”reset” name=”Submit2″ value=”Reset” />
</p>
</form>
<p>
<?php
if ($submitentry == “SUBMIT”){
$sql = “‘$name’, ‘$email’, ‘$comments'”;
$em = “‘$subject'”;
mail(‘YourEmailAddressHere’, $em, $sql);
echo(“<p>Your message has been sent!” . “</p>”);
}
?></p>

]]>
https://raypastore.com/wordpress/2010/04/php-contact-page/feed/ 0 212