martin5211 37 Posting Whiz in Training

Use String message = request.getParameter("message"); on the servlet to extract each input field value, the following snippet will do the rest:

import java.io.IOException;
import java.util.Properties;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.*;
import javax.mail.internet.*;

public class ContactServlet extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
		
		String email = request.getParameter("email");
		String subject = request.getParameter("subject");
		String message = request.getParameter("message");
		
		if(!message.equals(null)){
			Properties props = new Properties();
	        	Session session = Session.getDefaultInstance(props, null);
			
		try {
	                Message m = new MimeMessage(session);
	                m.setFrom(new InternetAddress(email, "user"));
	                m.addRecipient(Message.RecipientType.TO, new InternetAddress("dest@example.com", "me"));
	                m.setSubject(subject);
	                m.setText(message);
	                Transport.send(m);

	        } catch (AddressException e) {
	        	e.printStackTrace();
	        } catch (javax.mail.MessagingException e) {
		        e.printStackTrace();
		}
	        
		RequestDispatcher view = request.getRequestDispatcher("success.jsp");
			
		view.forward(request, response);

		}
	}

}
martin5211 37 Posting Whiz in Training

java.lang.Exception: Port 8083 already in use.

Seems to be that maybe there is another instance running on the server.

martin5211 37 Posting Whiz in Training

Add a hidden field and modify the value from Javascript. Then you can extract the values using request.getParameter()

martin5211 37 Posting Whiz in Training

Your external IP is not accessible from intranet, it is a common issue. If you did the right steps, try to access to your wan address from an outside location.

martin5211 37 Posting Whiz in Training

Thank you. It's ok now using the dot notation.

martin5211 37 Posting Whiz in Training

Hello everybody,

I worked long hours this evening trying to unthread the whole thing and still not working... I don't know why. The page display the results using normal code in JSP (no jstl tags). When using jstl tags the page results in blank screen, no posts. Here is the code:

index.jsp (jstl not working)

<%@ page import="bean.PostBean"%>
<%@ page import="model.Posts" %>
<%@ page import="java.util.*" %>
<jsp:useBean id="Posts" class="model.Posts" scope="page" />
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Report Results (NIOSH)</title>
</head>
<body>
<% ArrayList<PostBean> posts = new ArrayList<PostBean>(Posts.getPosts()); %>
<% //System.out.println(posts); %>
    <c:forEach var="post" items="${posts}">
   		<h2>${post.title}</h2>
   		<p>${post.text}</p>
    </c:forEach>   
</body>
</html>

index.jsp (works)

<%@ page import="bean.PostBean"%>
<%@ page import="model.Posts" %>
<%@ page import="java.util.*" %>
<jsp:useBean id="Posts" class="model.Posts" scope="page" />
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Report Results (NIOSH)</title>
</head>
<body>
<%
ArrayList<PostBean> posts = Posts.getPosts();
%>
	<%for(int i=0; i < posts.size(); i++)
		{
		PostBean post = new PostBean();
		post = (PostBean) posts.get(i);
		%>
		<h2><%= post.getTitle() %></h2>
		<p><%= post.getText() %></p>
	<%}%>
</body>
</html>

Posts.java

import java.sql.Statement;
import java.util.ArrayList;

import bean.PostBean;

public class Posts {

	public ArrayList<PostBean> getPosts() throws Exception{
		ArrayList<PostBean> list = new ArrayList<PostBean>();
		
		String driver = "com.mysql.jdbc.Driver";
		String user = "root";
		String password = "xx";
		
		Class.forName(driver);
		Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dcaminoa", user, password);
		
		Statement select = (Statement) conn.createStatement();
		
		ResultSet result = select.executeQuery("select * from posts");
		
		while(result.next())
		{
			PostBean post = new PostBean();
			post.setId(result.getInt("id"));
			post.setTitle(result.getString("title"));
			post.setText(result.getString("text"));
			list.add(post);
		}
		result.close();
		conn.close(); …
martin5211 37 Posting Whiz in Training

It's a common mistake that everyone makes. Other issue that could happen are related with thread safety when using attributes, could get the exact same symptoms.

martin5211 37 Posting Whiz in Training

This is an simple approach to dispatch a value to index.jsp

index.html:

<html>
<body>
<h1 align="center">Select Person</h1>
<form method="POST" action="Person.do">
<select name="person" size="1">
<option value="a@example.com">Fred</option>
</select>
<br><br>
<center><input type="Submit"></center>
</form>
</body></html>

result.jsp:

<p>
<%
  // request email from servlet
  String email = (String)request.getAttribute("email");

  // print email 
  out.println("<br>"+email);
%>
</p>

Person.java:

package com.example;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Person extends HttpServlet
{
	public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
	{
		String p = request.getParameter("person");

		// display email stored in web.xml
		PrintWriter out = response.getWriter();
		request.setAttribute("email", p);
		
		RequestDispatcher view = request.getRequestDispatcher("result.jsp");
		view.forward(request, response);
	}
}

web.xml (stored inside WEB-INF):

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Person Servlet Example</display-name>
  <servlet>
    <servlet-name>Person</servlet-name>
    <servlet-class>com.example.Person</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Person</servlet-name>
    <url-pattern>/Person.do</url-pattern>
  </servlet-mapping>
</web-app>
martin5211 37 Posting Whiz in Training

Code for JavaBean:

package com.example;

public class Person {
	public String name;
	
	public void setName(String name){
		this.name = name;
	}
	
	public String getName(){
		return this.name;
	}

}

result.jsp

<jsp:useBean id="person" type="com.example.Person" class="com.example.Person" scope="session">
  <jsp:setProperty name="person" property="name" value="Fred" />
</jsp:useBean>
Person: <jsp:getProperty property="name" name="person"/>

result2.jsp

<jsp:useBean id="person" type="com.example.Person" class="com.example.Person" scope="session">
</jsp:useBean>
Person: <jsp:getProperty property="name" name="person"/>

Don't forget to use session scope for your javabeans.

martin5211 37 Posting Whiz in Training

You could use a non-enterprise JavaBean, then use <jsp:setProperty> and <jsp:getProperty>

martin5211 37 Posting Whiz in Training

Have you tried accBalance as instance or class variable?

martin5211 37 Posting Whiz in Training

For Java Swing projects I suggest to use SQLite. Mysql for web. Everything you need is the MySQL Connector/J to start.

martin5211 37 Posting Whiz in Training

hii
hey i want to add 20 images in one pdf .and then send it via email as a attachment using php.
can anybody pl help me?

Where the code says "generate a simple PDF", below AddPage() method, use the following code:

$pdf->Image('logo-1.gif',10,8,25)

to add an image. Where the first and second number sets position and the last parameter is for the size.

martin5211 37 Posting Whiz in Training

My error, that line is correct. The error is hard to find.

martin5211 37 Posting Whiz in Training

Take a look at line 72, one parenthesis is missing.

martin5211 37 Posting Whiz in Training

This code segment seems to be fine. This error doesn't show the line number? Try to find the last things you've worked, the syntax error is there.

martin5211 37 Posting Whiz in Training

The issue seems to be located on RecursiveDirectoryIterator or ZipArchive classes. An alternative solution would be to use exec("zip -r ...")

martin5211 37 Posting Whiz in Training

This example will show an alert after the end.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>    
<div id="ytapiplayer">
  You need Flash player 8+ and JavaScript enabled to view this video.
</div>

<script type="text/javascript">
 
    var params = { allowScriptAccess: "always" };
    var atts = { id: "myytplayer" };
    swfobject.embedSWF("http://www.youtube.com/v/App5FjQMpdA?enablejsapi=1&playerapiid=ytplayer", 
                       "ytapiplayer", "425", "356", "8", null, null, params, atts);

function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById("myytplayer");
  ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}

function onytplayerStateChange(newState) {
	if(newState == 0){
   		alert("Player is stopped");
	}
}

</script>
martin5211 37 Posting Whiz in Training

With player.getPlayerState() will return 0 is end. The complete Youtube API is located in this page:

http://code.google.com/apis/youtube/js_api_reference.html#Playback_status

martin5211 37 Posting Whiz in Training

Try this code if it works:

for($i=0; $i < count($structure); $i++) {
  $a = $structure[$i]['email'];
  $b = $structure[$i]['name']; 
  echo "Field = $a / Value = $b<br>\n";
  // at this point I need the following:
  // $a should = "email"
  // $b should = "text"
}

The code above is wrong. Just, I understand what has to be the result.
Is more easier if you extract the elements of the array using FOREACH instead of FOR.

foreach($structure as $arr) {
	foreach($arr as $key=>$value) {
	  $a = $key;
	  $b = $value; 
	  echo "Field = $a / Value = $b<br>\n";
	  // at this point I need the following:
	  // $a should = "email"
	  // $b should = "text"
	}
}

The problem is, you use string tags for index instead of numbers. For that reason the original code doesn't work.

martin5211 37 Posting Whiz in Training
echo empty($row['ProductPrice']) ? "FREE" : $row['ProductPrice'];
	echo "</td><td>"
martin5211 37 Posting Whiz in Training

$value is an array or a simple variable like 'text'? If that's variable, the resultant code should be:

for($i=0; $i<$cntFields; $i++) {
    $a = $structure[$i];
    $b = $structure[$i];
    echo "Field = $a / Value = $b<br>\n";
    // at this point I need the following:
    // $a should = "email"
    // $b should = "text"
  }
martin5211 37 Posting Whiz in Training

This conditional, if $row is null or empty, the text "free" will always be displayed.

martin5211 37 Posting Whiz in Training

Every user session generates environment variables on the server (ip address, browser type, etc). With these variables $_SESSION and $_SERVER you can distinguish between each user.

martin5211 37 Posting Whiz in Training

Would be nice to know what type of error appears on your friend's computer. Since ISP DNS is not involved, the problem seems more like wrong ip address.

martin5211 37 Posting Whiz in Training

The code segment seems correct. Are you tried with empty() instead of is_null()?

martin5211 37 Posting Whiz in Training

The result will be displayed into an array:

preg_match_all("/([\s]*)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*([ ]+|)@([ ]+|)([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,}))([\s]*)/i", $syntax, $matches);

echo "<pre>";
print_r($matches);
martin5211 37 Posting Whiz in Training

If you have NTFS (Windows) partitions on that disk, all partitions will be displayed as read-only. Things you need, install NTFS-3G.

martin5211 37 Posting Whiz in Training

Could you explain more what you're looking? To block a virtual host, it's possible to use $_SERVER into a condition then header() to redirect to a blank page. But if you're looking to block a site in your computer, all you need is to edit the hosts file.

martin5211 37 Posting Whiz in Training

You need PEAR installed first to execute `pecl install` command.
I suggest to follow this guide:

http://php.net/manual/en/install.pecl.php

Also this guide can help too:

http://freestylesystems.co.uk/blog/installng-pecl-uploadprogress-extension-drupal-filefield-module

martin5211 37 Posting Whiz in Training

Is this what you're looking?

SELECT * 
FROM 
`teams_types` 
JOIN  `teams` ON teams_types.team = teams.id
JOIN `product_types` ON teams_types.product_type = product_types.id
martin5211 37 Posting Whiz in Training

I think Zend Framework wins using LiveDocx component: http://www.phplivedocx.org/downloads/

Antiword would be an alternative, it's a UNIX app, can be executed from PHP using exec()

<?php
exec('/usr/local/bin/antiword /opt/lampp/htdocs/example.doc', $output);
?>
martin5211 37 Posting Whiz in Training

If you want a copy in your Sent folder you'll need to set up the SMTP authentication with your Yahoo account, only sending messages through Yahoo interface or smtp server will make you able to track sent messages.

The default mail() function lacks some features like SMTP server configuration passing a parameter through this function, to do this, I recommend to use a more functional and advanced class like PHPMailer or Swift Mailer, both are easy to configure and use. On the snippet code, only would be necessary to replace the mail() function call.

martin5211 37 Posting Whiz in Training

FPDF is a class that provides a useful way to deal with PDF documents using dynamic content. Sometimes, according to a special circumstance, also would be valuable to send directly the PDF as attachment e.g. send an invoice automatically after processing a payment.

In this example we use a html message and FPDF / mail() techniques.

martin5211 37 Posting Whiz in Training

The jQuery questions should be made on JavaScript / DHTML / AJAX forum.

From Drupal perspective, some jQuery plugins could not work with the jQuery bundle included on Drupal core (the jQuery distribution included maybe is too old). To fix this issue, there is a module to update the jQuery distribution: http://drupal.org/project/jquery_update

Looking at your code, use comments into OnBefore() line to test the cycle plugin alone. title isn't a defined object. Try to use a jQuery selector instead.

martin5211 37 Posting Whiz in Training

Use CURL or fsockopen() to get the result from Google, then simplexml_load_string()

$zip = 10001;
$url = "http://news.google.com/news?pz=1&ned=us&hl=en&q=".$zip."&output=rss";

$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$result = curl_exec($ch);
curl_close($ch);

$rss = simplexml_load_string($result);
martin5211 37 Posting Whiz in Training

I can tell you why double posting in the same thread occurs. It happens to me all the time. But I usually edit the duplicate to say something else.

When you go to post, sometimes you never get the reply back from DaniWeb. The browser either times out or sits there indefinitely waiting for a failed advertisement to load. If you then use Refresh to get the new version of the page, it posts the same post again.

It happens me usually with Youtube, javascript doesn't refresh sometimes. What I called 'double posting' is when you want to add more information and edit option expired, using Quick Reply will create another post instead of concatenate the last one.

I like the new login system on this website, as well another changes made, saves one or more pages loaded.

martin5211 37 Posting Whiz in Training
martin5211 37 Posting Whiz in Training

Do you have activated the permissions for create and edit content types on User Management / Access Control ?

Take a look if is enabled all CCK field types in modules.

martin5211 37 Posting Whiz in Training

I'm using mainly one check... subtracting 18 years to 2009 would be 1991, so any user should have a born date below 1991 to access www.example.com. That conditional isn't dynamic, to adjust the code would be:

$min_year = date('Y', time());
$min_year = $min_year - 18;    // Change this (minimum age)

if($year < $min_year){
   ...

But, I prefer to use 19 years on the first condition, due to I want to make a more refined checking for users whose born date is near to the year limit. In that case, I use strtotime() to discount years and generate a timestamp, then I compare the user timestamp (date to seconds from 1970) with the subtracted timestamp obtained from today.

You cannot use only strtotime() to check age because only will work with a date above 1970. For that reason, two checks.

Also, if you want to adjust the minimal age, change the value inside strtotime()

martin5211 37 Posting Whiz in Training
<?php

$msg = null;

if ((is_numeric($_POST['month']) && !empty($_POST['month'])) &&
	(is_numeric($_POST['day']) && !empty($_POST['day'])) &&
	(is_numeric($_POST['year']) && !empty($_POST['year']))
){

$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];

if ($year < 1990){

	// redirects to new location
	header('Location: http://www.example.com/');
}else{

	$user_timestamp = mktime(0, 0, 0, $month, $day, $year);
	$legal_timestamp = strtotime('-18 years');
	if($user_timestamp < $legal_timestamp){
		// redirects to new location
		header('Location: http://www.example.com/');
	}else{
		$msg = "Underage not allowed to access content";
	}
}

}
?>
<div style="float:center; margin-left:30px;">
<?php if (!empty($msg)): ?>
	<div style="float:center; width:300px; color:red; border:1px solid red"><?php echo $msg; ?></div>
<?php else: ?>
<form name="myform" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
     <select style="float:center; margin-right:5px;" name="month">
		<option value="MM">MM</option>
		<option value="01">01</option>
		<option value="02">02</option>
		<option value="03">03</option>
		<option value="04">04</option>
		<option value="05">05</option>
		<option value="06">06</option>
		<option value="07">07</option>
		<option value="08">08</option>
		<option value="09">09</option>
		<option value="10">10</option>
		<option value="11">11</option>
		<option value="12">12</option>
	</select>
	<select style="float:center; margin-right:5px;" name="day">
		<option value="DD">DD</option>
		<option value="01">01</option>
		<option value="02">02</option>
		<option value="03">03</option>
		<option value="04">04</option>
		<option value="05">05</option>
		<option value="06">06</option>
		<option value="07">07</option>
		<option value="08">08</option>
		<option value="09">09</option>
		<option value="10">10</option>
		<option value="11">11</option>
		<option value="12">12</option>
		<option value="13">13</option>
		<option value="14">14</option>
		<option value="15">15</option>
		<option value="16">16</option>
		<option value="17">17</option>
		<option value="18">18</option>
		<option value="19">19</option>
		<option value="20">20</option>
		<option value="21">21</option>
		<option value="22">22</option>
		<option value="23">23</option>
		<option value="24">24</option>
		<option value="25">25</option>
		<option value="26">26</option>
		<option value="27">27</option>
		<option value="28">28</option>
		<option value="29">29</option>
		<option value="30">30</option>
		<option value="31">31</option>
     </select>
	<select style="float:center;" name="year">
		<option value="YYYY">YYYY</option>
		<option value="2009">2009</option>
		<option value="2008">2008</option>
		<option value="2007">2007</option>
		<option value="2006">2006</option>
		<option value="2005">2005</option>
		<option value="2004">2004</option>
		<option value="2003">2003</option>
		<option value="2002">2002</option>
		<option value="2001">2001</option>
		<option value="2000">2000</option>
		<option value="1999">1999</option>
		<option value="1998">1998</option>
		<option value="1997">1997</option>
		<option value="1996">1996</option>
		<option value="1995">1995</option>
		<option value="1994">1994</option>
		<option value="1993">1993</option>
		<option value="1992">1992</option>
		<option value="1991">1991</option>
		<option value="1990">1990</option>
		<option value="1989">1989</option> …
martin5211 37 Posting Whiz in Training

That is not intended for a 'perfect' system, it's only a disclaimer. If you want to bypass it, it's your problem, you're violating the law. Look the little legend on every drug, that doesn't avoid to swallow a pill by a minor.

martin5211 37 Posting Whiz in Training

I know, but it isn't pretty for the user to each time select his day of birth, then the month and thereafter the year ...

I agree with you, it is not pretty but several sites use this method of control with drop down lists and even input fields. I think more for legal purposes.

martin5211 37 Posting Whiz in Training

That's doable with simple conditionals. The most important field is year. We assume if is not > 1991 or 91. You wan to check boundaries, also use strtotime('-18 years')

martin5211 37 Posting Whiz in Training

Look at the *third* code example:

http://www.lotsofcode.com/php/validation.htm

is_numeric() is a common form to avoid characters from alphabet on age field.

martin5211 37 Posting Whiz in Training

If the page only shows the code that's because the PHP interpreter isn't running. Look at your httpd.conf (Apache configuration file) and look if the line that says 'LoadModule php5_module' isn't commented with # sign.

Also, look for 'Listen' should say 'Listen 80' so you can put simply http://localhost/ on the browser. If the server is running on another port instance e.g. the line shows 'Listen 8080', put on the browser http://localhost:8080/. This is a more uncommon issue.

If that doesn't make any change, maybe the PHP module isn't installed. I suggest to use a pre-configured package software with Apache/PHP/MySQL like xampp or mamp.

Make a new file on the root folder of your web server, 'test.php'. Add on the content:

<?php
echo phpinfo();
?>

Then on the browser access to http://localhost/test.php
It should display the PHP version and installed modules.

Well this is to manage sort of troubles with PHP, I haven't seen the previous page and the year :D

martin5211 37 Posting Whiz in Training

That's correct. There is better methods to show the code in a more readable way e.g. using sprintf() like in PHP.net mysql_real_escape_string() reference, curly braces on variables, doing escaping before SQL query $user=mysql_real_escape_string($_POST['user']); .

martin5211 37 Posting Whiz in Training

Strings, values (except numeric) in SQL must be enclosed into quotes. Quotes delimit the string content, avoiding being confused by the interpreter, due to a string can contain spaces and non-alphanumeric characters.

You started the SQL sentence with double quotes , it's important to end it with the same quotes. After the sentence I use dots to concatenate (join) variables results and add another portion of text (like the a single quote to end the string).

If that code is a login script, I suggest to use mysql_real_escape_string() on the SQL query variables to avoid a common vulnerability called MySQL injection. This function will convert the quotes that can be used on username field so the user cannot rewrite the SQL query.

More details:

http://php.net/mysql_real_escape_string

martin5211 37 Posting Whiz in Training

Enclose strings between quotes:

$query = "SELECT * FROM $table WHERE Username='".$user."' AND Password='".$pass."'";
martin5211 37 Posting Whiz in Training

A sort of balance must exist because we're talking about an online community. If a member feels uncomfortable, obviously would leave. That may not concern however remote it may be, new users will come like a cascade does :) But, even great sites like Facebook are changing that line of thinking of merely "I do what I want". Sites that doesn't meet with standard values or doesn't grow in terms of flexibility, will decline to make room more comfortable communities... or even similar sites.

This popup can be the most annoying for someone, my case, I don't reset cookies and fortunately cookies doesn't expire so fast, everything is fine. Despite of that, I remember such advertisement wasn't well received the first time I logged in days ago. I had to register mandatory (long time ago) to several websites only to see a worthless posts (or dead links).

So, time will say if a site policy really works for you, hope for the best sake in the world. However, these suggestions are not crazy ideas. A dictatorship would be a heck of a lot easier, there's no question about it. (George W. Bush).

P.S. I want to add, that little change in the popup logic is really great!

P.P.S. We must become the change we want to see. (Gandhi)