Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorjsaul
    • CommentTimeMar 16th 2007
     permalink

    why do I always get errors saying I have undefined variables when I use more or less any php script ?

    I Know php works on my server.



    example error.....



    Notice: Undefined variable: userfile in /home/fhlinux172/w/waringcollins.com/user/htdocs/files.php on line 2


    I get similar errors from 'any' script with variables in it


    Any ideas anyone ?

    • CommentAuthorlatinomigs
    • CommentTimeMar 16th 2007
     permalink
    example code?
    • CommentAuthorvarland
    • CommentTimeMar 16th 2007
     permalink
    It looks like you may not be including the required "$" in your variable names.
    • CommentAuthorMatt
    • CommentTimeMar 16th 2007
     permalink
    Yeah, we can't help without example code. Is this code you wrote? Also, a good habit is first using the function isset to see if you have the variable existing before you use it.
    • CommentAuthorjsaul
    • CommentTimeMar 19th 2007 edited
     permalink
    Hey,

    Im using pre-made scripts at the minute, they all seem to have the variables declared properly.

    here is the error I get for the scripting on the following url...

    Notice: Undefined index: submitform in /home/fhlinux172/w/waringcollins.com/user/htdocs/mailform.php on line 60

    link to form

    Thanks for your input so-far...


    Saul
    • CommentAuthorlatinomigs
    • CommentTimeMar 19th 2007
     permalink
    Actually, we need to look at the PHP source code you're using, not the error. Can you put the code up?
    • CommentAuthorjsaul
    • CommentTimeMar 19th 2007 edited
     permalink
    Oh right, the php is inline on the page I linked to but you cant see it can you ??

    Ok,


    <html>
    <head>
    <title>PHP Contact Form</title>

    <?php
    // COPYRIGHT/LIABILITY NOTICE
    // Copyright © 2002 Kali (http://www.xentrik.net)
    // Last modified 04/05/2004

    // Kali's Contact Form may be used and modified free of charge as long as this
    // copyright notice and the comments above remain intact. By using this code
    // you agree to indemnify Kali from any liability that might arise from its use.

    // Selling the code for this program without prior written consent is not permitted.
    // Permission must be obtained before redistributing this software. In all cases the
    // copyright and header information must remain intact.

    // MODIFY THE FOLLOWING SECTION

    // your name
    $recipientname = "Jonathan Saul";

    // your email
    $recipientemail = "jon_saul@waringcollins.com";

    // subject of the email sent to you
    $subject = "Online-Form Response for $recipientname";

    // send an autoresponse to the user?
    $autoresponse = "no";

    // subject of autoresponse
    $autosubject = "Thank you for your mail!";

    // autoresponse message
    $automessage = "This is an auto response to let you know that we've successfully received your email sent through our email form. Thanks! We'll get back to you shortly.";

    // thankyou displayed after the user clicks "submit"
    $thanks = "Thank you for contacting us.<br>We will get back to you as soon as possible.<br>";

    // END OF NECESSARY MODIFICATIONS

    ?>

    <style type="text/css"><!--
    td,body,input,textarea {
    font-size:12px;
    font-family:Verdana,Arial,Helvetica,sans-serif;
    color:#000000}
    --></style>
    </head>
    <body>

    <table width="100%" height="100%"><tr>
    <td valign="top"><font face="Verdana,Arial,Helvetica" size="2">

    <?php
    if($_POST['submitform']) {

    $Name = $HTTP_POST_VARS['Name'];
    $Email = $HTTP_POST_VARS['Email'];
    $Comments = $HTTP_POST_VARS['Comments'];

    // check required fields
    $dcheck = explode(",",$require);
    while(list($check) = each($dcheck)) {
    if(!$$dcheck[$check]) {
    $error .= "Missing $dcheck[$check]<br>";
    }
    }

    // check email address
    if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $Email))){
    $error .= "Invalid email address<br>";}

    // display errors
    if($error) {
    ?>

    <b>Error</b><br>
    <?php echo $error; ?><br>
    <a href="#" onClick="history.go(-1)">try again</a>


    <?php
    }
    else
    {

    $browser = $HTTP_USER_AGENT;
    $ip = $REMOTE_ADDR;

    // format message
    $message = "Online-Form Response for $recipientname:

    Name: $Name
    Email: $Email

    Comments: $Comments

    -----------------------------

    Browser: $browser
    User IP: $ip";

    // send mail and print success message
    mail($recipientemail,"$subject","$message","From: $Name <$Email>");

    if($autoresponse == "yes") {
    $autosubject = stripslashes($autosubject);
    $automessage = stripslashes($automessage);
    mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
    }

    echo "$thanks";
    }
    }
    else {
    ?>

    <form name="contactform" action="<?php echo $PHP_SELF; ?>" method="post">
    <input type="hidden" name="require" value="Name,Email,Comments">
    <table><tr>
    <td colspan="2" align="center"><b>Contact Me!</b><p></td>
    </tr><tr>
    <td valign="top" align="right">Name:</td>
    <td valign="top"><input name="Name" size="25"></td>
    </tr><tr>
    <td valign="top" align="right">E-mail:</td>
    <td valign="top"><input name="Email" size="25"></td>
    </tr><tr>
    <td valign="top" align="right">Comments:</td>
    <td valign="top"><textarea name="Comments" rows="5" cols="35"></textarea></td>
    </tr><tr>
    <td colspan="2" align="center"><input type="submit" value="Submit" name="submitform">
    <input type="reset" value="Reset" name="reset"></td>
    </tr></table>
    <br>

    </form>
    <?php } ?>
    </font><p></td>
    </tr><tr>
    <td valign="bottom"><font face="Verdana" size="1">Mailform Copyright © 2002 <a href="http://www.xentrik.net/">Kali's Web Shoppe</a>.</font></td>
    </tr></table>

    </body>
    </html>


    Sorry, thanks for looking
    • CommentAuthorlatinomigs
    • CommentTimeMar 19th 2007
     permalink
    Well, there seems to be a part of your code that explodes a $require string variable by comma... That looks to be the hidden input object in your HTML named "require"... You are getting the other input objects by using $HTTP_POST_VARS, but not the require one... So try adding: $require = $HTTP_POST_VARS['require']; before the "//check required fields comment".
  1.  permalink
    You should also consider changing $HTTP_POST_VARS[] to $_POST[] as the former whilst available, is deprecated in the latest versions of PHP (see http://us3.php.net/manual/en/language.variables.predefined.php).
Add your comments
    Username Password
  • Format comments as (Help)