Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP Postcard Fatal errors (won't show HTML links)
Old 08-23-2010, 01:02 PM PHP Postcard Fatal errors (won't show HTML links)
Novice Talker

Posts: 8
Name: Chris
Trades: 0
hi,
I'm stuck on my micropostcard script. I basically get two error messages:
Notice: Undefined index: (does not like my postcard URL even though it is 100% correct!!!)

Notice: Undefined variables (which i don't understand)

PHP Code:
<?php
// CHANGE PARAMETERS HERE BEGIN
$senderName  " Holidays From Home "// Eg.: John's Postcards
$senderEmail "chris01@voluntary.awardspace.co.uk";  // Eg.: john@postcard.com
// Change only if you have problems with urls
$postcardURL "http://".$_SERVER["voluntary.awardspace.co.uk"].$_SERVER["Postcard.php"];
//$postcardURL = 'http://www.voluntary.awardspace.co.uk/Postcard.php';
// CHANGE PARAMETERS HERE END
$result 0;
$msg "";
$msg1 "";
$pic "";
function 
displayPhotos()
{
 global 
$pic;
 
$columns 5;
 
$act 0;
 
$act1 0;
 
// Open the actual directory
 
if($handle opendir("thumbs"))
 {
  
// Read all file from the actual directory
  
while($file readdir($handle))
  {
   if(!
is_dir($file))
   {
    if(isset(
$pic[1]))
    {
     if(
$pic[1] == $act1){$sel "checked";}
     else{
$sel "unchecked";}
     }
    if(
$act == 0){echo "<tr>";}
    echo 
"<td align='center'><img src='thumbs/$file' alt='postcard'/><br/><input type='radio' name='selimg' value='$file,$act1$sel/></td>";
    
$act++;
    
$act1++;
    if(
$act == $columns){$act 0;echo "</tr>";}
    
       }
    }
  echo 
"</tr>";
  }    
 }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
 <title>Micro Postcard</title>
 <link href= "style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main">
<div class="style1" id="caption">
<div align="left" class="style1"></div>
</div>
   <?php //makes sure form is correctly filled in 
 
if(!empty($_POST["submit"]))
 {
  if(empty(
$_POST["selimg"])){$msg "Please select an image from above!";$result 3;}
  else{
$pic explode(",",$_POST["selimg"]);}
  if(empty(
$_POST["email"]) && empty($result)){$msg1 "You must enter an email address!";$result 3;}
  
$secCode = empty($_POST["secCode"]) ? "" strtolower($_POST["secCode"]);
  if(
$secCode == $_SESSION["securityCode"] && $result != 3)
  {
   
$filename date("YmdGis");
   
$f fopen("messages/".$filename.".txt","w+");
   
fwrite($f,$pic[0]."\n");
   
fwrite($f,$_POST['email']."\n");
   
fwrite($f,stripslashes($_POST["message"])."\n");
   
fclose($f);
   
// Compose the mail
   
$from "From: $senderName <$senderEmail>\r\n";
   
$replay "Reply-To: $senderEmail\r\n";    
   
$params "MIME-Version: 1.0\r\n";
   
$params .= "Content-type: text/plain; charset=iso-8859-1\r\n";
   
$mailtext "You have just received a Virtual Postcard!\r\n\r\n
                You can pick up your postcard at the following web address:\r\n
                
$postcardURL?show=$filename\r\n\r\n
                We hope you enjoy your postcard, and if you do, please take a moment to send a few yourself!\r\n\r\n
                Regards,\r\n
                Holidays From Home\r\n
                
$postcardURL";
   
// Send email
   
@mail($_POST["email"],"You've received a postcard",$mailtext,$from.$replay.$params);
   echo 
"<center>
          Your postcard was sent successfully!<br /><br />
          <img src='images/
$pic[0]' alt='postcard' /><br /><br /><br />".stripslashes($_POST["message"]).
        
"</center>";
   
$result 1;
   
   }
  else{if(
$result != 3){$result 2;}}
  }
 if(!empty(
$_GET["show"]))
 {
  
$file $_GET["show"];
  
$content file("messages/$file.txt");
  
$pic $content[0];
  unset(
$content[0]);
  unset(
$content[1]);
  foreach(
$content as $value){$main .= $value;}
  echo 
"<center>
         Your postcard!<br /><br />
         <img src='images/
$pic' alt='postcard' /><br /><br /><br />$main
        </center>"
;
  }
 if((empty(
$result) || $result == || $result == 3) && empty($_GET["show"]))
 {
  echo 
"<form action='#' method='post'>
         <table align='center'>"
;
         
displayPhotos();
  echo  
"</table>
         <div style='color:#f00;font-size:16px;'>
$msg</div>        
         <h2>Fill in the Form and then click on Send Card!!</h2>
         <table width='100%'>
          <tr><td>Send to (email address):</td><td><div style='color:#f00;font-size:16px;'>
$msg1</div><input type='text' name='email' size='30' value='".$_POST["email"]."' /></td></tr>
          <tr><td>Message:</td><td><textarea name='message' rows='10' cols='40'>"
.stripslashes($_POST["message"])."</textarea></td></tr>
          <tr><td colspan='2'>"
.($result == "<p style='color:#f00;font-size:16px;'>Sorry the security code is invalid! Please try it again!</span></p>" "&nbsp;")."</tr>
          <tr>
           <td>Security code: <input class='text' name='secCode' type='text' size='10' />
           </td><td><img src='securityCode.php' alt='security code' border='1' /></td>
          </tr>
          <tr><td colspan='2'>&nbsp;</tr>
          <tr><td colspan='2' align='left'><input type='submit' value='Send card!' name='submit'/></td></tr>
         </table>
        </form>"
;
  }
?>
Here is the link: http://voluntary.awardspace.co.uk/Postcard.php

Any help would be much appreciated I am completely lost on this script.
norwichchris is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-23-2010, 01:46 PM Re: PHP Postcard Fatal errors (won't show HTML links)
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
These are not fatal errors they are notices. Notices can be useful, but a script can function perfectly while still generating notices.

Undefined index occurs when you attempt to access an index of an array that has not been set. Undefined variable occurs when you try to reference a variable that has not been set. Often this occurs when a variable is declared in a control flow statement (if statement for example) and then referenced outside of that statement. For example:

PHP Code:
$foo false;
if(
$foo)
     
$bar 5;

echo 
$bar
If you can post the lines where these notices occur I, or someone else, can probably point out what is causing them.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-23-2010, 02:16 PM Re: PHP Postcard Fatal errors (won't show HTML links)
Novice Talker

Posts: 8
Name: Chris
Trades: 0
ok,
Here is the first one for line 25 where i input my Hostname and script name.

(Line 25) Undefined Index

$postcardURL = "http://".$_SERVER["voluntary.awardspace.co.uk"].$_SERVER["Postcard.php"];

(Line 52) Undefined Variable. As i understand it one of my variables is wrong or should be an array.

echo "<td align='center'><img src='thumbs/$file' alt='postcard'/><br/><input type='radio' name='selimg' value='$file,$act1' $sel/></td>";

Please any help would be much appreciated i am really stuck on this

Last edited by norwichchris; 08-23-2010 at 02:18 PM..
norwichchris is offline
Reply With Quote
View Public Profile
 
Old 08-23-2010, 02:50 PM Re: PHP Postcard Fatal errors (won't show HTML links)
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
PHP Code:
$postcardURL "http://".$_SERVER["voluntary.awardspace.co.uk"].$_SERVER["Postcard.php"]; 
I think what you're going for is:
PHP Code:
$postcardURL "http://".$_SERVER['HOST'].$_SERVER['SCRIPT_NAME']; 
You should take a look at the documentation for $_SERVER: http://php.net/manual/en/reserved.variables.server.php

PHP Code:
echo "<td align='center'><img src='thumbs/$file' alt='postcard'/><br/><input type='radio' name='selimg' value='$file,$act1$sel/></td>"
Looking at your code, it looks like in the case that $pic[1] is not set, $sel is never declared. There is no harm in leaving this as it is (just make sure notices are off in the production environment). Alternatively you can just initialize $sel to the empty string after the line $act1 = 0;
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-23-2010, 03:37 PM Re: PHP Postcard Fatal errors (won't show HTML links)
Novice Talker

Posts: 8
Name: Chris
Trades: 0
I'm not sure what you mean about production environment so i have just added $sel = 0; to the code: I have two more error messages here:

(Line 135)
<tr><td>Send to (email address):</td><td><div style='color:#f00;font-size:16px;'>$msg1</div><input type='text' name='email' size='30' value='".$_POST["email"]."' /></td></tr>

and Line 136

<tr><td>Message:</td><td><textarea name='message' rows='10' cols='40'>".stripslashes($_POST["message"])."</textarea></td></tr>

They are the ones I am the most confused over
norwichchris is offline
Reply With Quote
View Public Profile
 
Old 08-23-2010, 03:42 PM Re: PHP Postcard Fatal errors (won't show HTML links)
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
By production environment I mean the live site. There is no reason why users should see PHP error messages.

What are the error messages?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-23-2010, 03:55 PM Re: PHP Postcard Fatal errors (won't show HTML links)
Novice Talker

Posts: 8
Name: Chris
Trades: 0
Either i get
Notice: Undefined indexs or undefined variables

I have no idea how to fix these at all.

I did choose to add a show errors code as it was not sending out any postcards or claiming the URL did not exist in order to fix the problem.
norwichchris is offline
Reply With Quote
View Public Profile
 
Old 08-23-2010, 04:06 PM Re: PHP Postcard Fatal errors (won't show HTML links)
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Can you post the actual error messages and the corresponding lines. You're referencing variables and indexing arrays all over the place and I don't know which ones are causing problems.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-23-2010, 06:49 PM Re: PHP Postcard Fatal errors (won't show HTML links)
Novice Talker

Posts: 8
Name: Chris
Trades: 0
The Two error messages are:

Notice: Undefined index: email in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 134


Notice: Undefined index: message in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 135

I'm not exactly sure what the problem so i researched online and used PHP error reporting code to find the errors as my Postcard did not work at all and wanted to know why.

When i did alter the $postcardURL to my hostname and script name. It did send the card.

But It refused to open the URL so I concluded something must be wrong with my code:

Here are the two lines as mentioned in the error messages:

Line 134:

PHP Code:
<tr><td>Send to (email address):</td><td><div style='color:#f00;font-size:16px;'>$msg1</div><input type='text' name='email' size='30' value='".$_POST["email"]."' /></td></tr
Line 135:
PHP Code:
<tr><td>Message:</td><td><textarea name='message' rows='10' cols='40'>".stripslashes($_POST["message"])."</textarea></td></tr

Last edited by norwichchris; 08-23-2010 at 06:51 PM..
norwichchris is offline
Reply With Quote
View Public Profile
 
Old 08-23-2010, 07:14 PM Re: PHP Postcard Fatal errors (won't show HTML links)
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Neither of those notices will prevent your script from running normally. Basically what's happening is the script is trying to populate the value attribute of the email field in the case that the user has already submitted their email. In the case that the user has not yet submitted their email the script generates a notice because $_POST['email'] is not set.

There is nothing that prevents you from using unset variables; they are assigned the value null. However, if you want to avoid the notice you can check if the variable is set first:
PHP Code:
$email = (isset($_POST['email'])) ? $_POST['email'] : ''
The same thing applies to $_POST['message']:

PHP Code:
$message = (isset($_POST['message'])) ? $_POST['message'] : ''
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-23-2010, 07:21 PM Re: PHP Postcard Fatal errors (won't show HTML links)
Novice Talker

Posts: 8
Name: Chris
Trades: 0
Honestly I don't understand why it isn't working.
However when I post the script to my Servers webmail folder it works.

But if I send it another email address it refuses to open the HTML. or nothing happens
norwichchris is offline
Reply With Quote
View Public Profile
 
Old 08-24-2010, 08:09 AM Re: PHP Postcard Fatal errors (won't show HTML links)
Novice Talker

Posts: 8
Name: Chris
Trades: 0
Here is my PHP.ini settings:

[PHP]
PHP Code:

engine 
On

short_open_tag 
On

asp_tags 
Off

precision    
=  12

y2k_compliance 
On

output_buffering 
Off

zlib
.output_compression Off

implicit_flush 
Off

unserialize_callback_func
=

serialize_precision 100

allow_call_time_pass_reference 
On

safe_mode 
Off

safe_mode_gid 
Off

safe_mode_include_dir 
=        

safe_mode_exec_dir =

safe_mode_allowed_env_vars PHP_

safe_mode_protected_env_vars 
LD_LIBRARY_PATH

disable_functions 
=

disable_classes =

expose_php Off

error_reporting  
=  E_ALL & ~E_NOTICE

display_errors 
Off

display_startup_errors 
Off

log_errors 
On

log_errors_max_len 
1024

ignore_repeated_errors 
Off

ignore_repeated_source 
Off

report_memleaks 
On

track_errors 
Off

variables_order 
"EGPFCS"

register_globals Off

register_argc_argv 
On

post_max_size 
10M

memory_limit 
32M

gpc_order 
"GPC"

magic_quotes_gpc Off

magic_quotes_runtime 
Off    

magic_quotes_sybase 
Off

auto_prepend_file 
=

auto_append_file =

default_mimetype "text/html"

user_dir =

enable_dl On

file_uploads 
On

upload_tmp_dir 
= /tmp

upload_max_filesize 
10M

allow_url_fopen 
On

default_socket_timeout 
60

[Syslog]

define_syslog_variables  Off

[mail function]

sendmail_from php@mail10.awardspace.com

sendmail_path 
= /usr/sbin/sendmail -oi -t

[Java]

[
SQL]
sql.safe_mode Off

[ODBC]

[
MySQL]
mysql.allow_persistent On

mysql
.max_persistent = -1

mysql
.max_links = -1

mysql
.default_port =

mysql.default_socket =

mysql.default_host =

mysql.default_user =

mysql.default_password =

mysql.connect_timeout 60

mysql
.trace_mode Off

[PostgresSQL]
pgsql.allow_persistent On

pgsql
.auto_reset_persistent Off 

pgsql
.max_persistent = -1

pgsql
.max_links = -1

pgsql
.ignore_notice 0

pgsql
.log_notice 0

[Sybase]

sybase.min_error_severity 10

[bcmath]
bcmath.scale 0

[Session]
session.save_handler files

session
.save_path = /tmp

session
.use_cookies 1

session
.name sid

session
.auto_start 0

session
.cookie_lifetime 0

session
.cookie_path = /

session.cookie_domain =

session.serialize_handler php

session
.gc_divisor     100

session
.gc_maxlifetime 1440

session
.bug_compat_42 1
session
.bug_compat_warn 1

session
.referer_check =

session.entropy_length 0

session
.entropy_file =

session.cache_limiter nocache

session
.cache_expire 180

session
.use_trans_sid 1

url_rewriter
.tags "a=href,area=href,frame=src,input=src,form=,fieldset="

apc.optimization 3
apc
.slam_defense 60

;extension=mysql.so
;extension=pgsql.so
extension
=apc.so
extension
=fileinfo.so
;extension=gd.so

Uncomment the line below to enable Ioncube Loader:
;
zend_extension = /usr/local/ioncube/ioncube_loader_lin_5.2.so

Uncomment the 4 lines below to enable Zend Optimizer:
;
zend_extension_manager.optimizer=/usr/local/Zend_php5/lib/Optimizer-3.3.3
;zend_optimizer.version=3.3.3
;zend_extension=/usr/local/Zend_php5/lib/ZendExtensionManager.so
;zend_optimizer.optimization_level=15 
I have only limited knowledge of the PHP.ini but I believe that I have to edit the Mail-Function.
norwichchris is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Postcard Fatal errors (won't show HTML links)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36786 seconds with 12 queries