Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error Compiling with Forms

    I'm having a problem getting this program to compile. I can't find where the error is, but the URL is here.

    http://allamericananimestudios.com/m.../mapsubmit.php

    And here is the code:
    <!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=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <form id="form1" name="form1" method="post" action="">
    <p><label>Location Name
    <input type="text" name="name" />
    </label></p>
    <label>Location Latitude
    <input type="text" name="lat" />
    </label>
    <label>Location Longitude
    <input type="text" name="lon" />
    </label>
    <p><br />
    Don't know the latitude and longitude? Enter the address at <a href="http://geocoder.us">Geocoder.us</a>.
    <label>
    </p>
    <p>Description
    <textarea name="desc"></textarea>
    </p>
    <p><label>URL
    <input name="url" type="text" value="http://" />
    </label>
    <p>
    <label>Category
    <select name="select">
    <option value="2">Mothman</option>
    <option value="1">Museum</option>
    <option value="3">Historical</option>
    <option value="4">Town</option>
    </select>
    <br />
    <br />
    </label>
    <input type="file" name="imagefile"><br />
    <p>
    <input type="submit" name="Submit" value="Submit">
    <?
    if(isset( $Submit ))
    {
    //If the Submitbutton was pressed do:

    copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name'])
    or die ("Could not copy");

    if ($_FILES['imagefile']['type'] == "image/gif"){

    echo "";
    echo "Name: ".$_FILES['imagefile']['name']."";
    echo "Size: ".$_FILES['imagefile']['size']."";
    echo "Type: ".$_FILES['imagefile']['type']."";
    echo "Copy Done....";
    }
    if ($_FILES['imagefile']['type'] == "image/jpg"){

    echo "";
    echo "Name: ".$_FILES['imagefile']['name']."";
    echo "Size: ".$_FILES['imagefile']['size']."";
    echo "Type: ".$_FILES['imagefile']['type']."";
    echo "Copy Done....";
    }
    if ($_FILES['imagefile']['type'] == "image/png"){

    echo "";
    echo "Name: ".$_FILES['imagefile']['name']."";
    echo "Size: ".$_FILES['imagefile']['size']."";
    echo "Type: ".$_FILES['imagefile']['type']."";
    echo "Copy Done....";
    }
    else {
    echo "<br><br>";
    echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
    }
    }
    //repeat input
    echo "Name: " . $name . "<br>";
    echo "Lat: " . $lat . "";
    echo "lon: " . $lon . "<br>";
    echo "Description: " . $desc . "<br>";
    echo "URL: " . $url . "<br>";
    //open connection to database
    $desc = addslashes($desc);
    $link = mysql_connect("xxxxx:xxxxxx", "xxxxxx", "xxxxx")
    or die("Could not connect: " . mysql_error());
    msql_select_db("mothmap",$link)
    or die("Can\'t use mothmap: " . mysql_error());
    //insert values into subfinder table
    $sql = "INSERT INTO mapdraft ";
    $sql = $sql . "VALUES('','" . $lat . "','".$lon."','".$desc."','".$url"','".$select."','".$_FILES['imagefile']['name']."','".$name."')";
    $result = mysql_query($sql,$link);
    if($result)
    {
    echo "<p>Due to an error (" . mysql_error() . ")<br>, your entry could " . "not be loaded into the database."
    . "Please return to <a href=\"index.php\">Home</a>,";
    }
    ?>

    </form>
    </body>
    </html>

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Missing . after $url

    PHP Code:
    $sql $sql "VALUES('','" $lat "','".$lon."','".$desc."','".$url."','".$select."','".$_FILES['imagefile']['name']."','".$name."')"
    If you used an editor with colour highlighting, you'd find that straight away. Plus next time please use the [php][/php] tags to colour the code on here. Indenting your code seriously makes it easier to read too, you should try it

  • #3
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. It will compile now.

    I'm still having a bit of a problem. The image upload function is not working. Also the php function seems to run whenever the page loads as well as when the button is pressed.

    The page is running over here: http://allamericananimestudios.com/m.../mapsubmit.php

    And here is the updated code:
    PHP Code:
    <!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=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <form id="form1" name="form1" method="post" action="">
    <p><label>Location Name
        <input type="text" name="name"  />
        </label></p>
        <label>Location Latitude
      <input type="text" name="lat" />
      </label>
      <label>Location Longitude
      <input type="text" name="lon" />
      </label>
      <p><br />
        Don't know the latitude and longitude? Enter the address at <a href="http://geocoder.us">Geocoder.us</a>. 
        <label>
      </p>
      <p>Description
        <textarea name="desc"></textarea>
      </p>
        <p><label>URL
        <input name="url" type="text" value="http://" />
        </label>
        <p>
          <label>Category
          <select name="select">
            <option value="2">Mothman</option>
            <option value="1">Museum</option>
            <option value="3">Historical</option>
            <option value="4">Town</option>
          </select>
          <br />
          <br />
          </label>
          <input type="file" name="imagefile"><br />
      <p>
         <input type="submit" name="Submit" value="Submit"> 
        <?
    if(isset( $Submit ))
    {
    //If the Submitbutton was pressed do:

        
    copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) 
        or die (
    "Could not copy"); 

    if (
    $_FILES['imagefile']['type'] == "image/gif"){

      echo 
    ""
            echo 
    "Name: ".$_FILES['imagefile']['name'].""
            echo 
    "Size: ".$_FILES['imagefile']['size'].""
            echo 
    "Type: ".$_FILES['imagefile']['type'].""
            echo 
    "Copy Done...."
            } 
    if (
    $_FILES['imagefile']['type'] == "image/jpg"){

      echo 
    ""
            echo 
    "Name: ".$_FILES['imagefile']['name'].""
            echo 
    "Size: ".$_FILES['imagefile']['size'].""
            echo 
    "Type: ".$_FILES['imagefile']['type'].""
            echo 
    "Copy Done...."
            } 
    if (
    $_FILES['imagefile']['type'] == "image/png"){

      echo 
    ""
            echo 
    "Name: ".$_FILES['imagefile']['name'].""
            echo 
    "Size: ".$_FILES['imagefile']['size'].""
            echo 
    "Type: ".$_FILES['imagefile']['type'].""
            echo 
    "Copy Done...."
            } 
                    else {
                echo 
    "<br><br>";
                echo 
    "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
            }
    }
    //repeat input
    echo "Name: " $name "<br>";
    echo 
    "Lat: " $lat "";
    echo 
    "lon: " $lon "<br>";
    echo 
    "Description: " $desc "<br>";
    echo 
    "URL: " $url "<br>";
    //open connection to database
    $desc addslashes($desc);
    $link mysql_connect("xxxxxxxx:xxxxx""xxxxxx""xxxxxxx")
    or die(
    "Could not connect: " mysql_error());
    mysql_select_db("mothmap",$link)
    or die(
    "Can\'t use mothmap: " mysql_error());
    //insert values into subfinder table
    $sql "INSERT INTO mapdraft ";
    $sql $sql "VALUES('','" $lat "','".$lon."','".$desc."','".$url."','".$select."','".$_FILES['imagefile']['name']."','".$name."')";
    $result mysql_query($sql,$link);
    if(
    $result)
    {
    echo 
    "<p>Due to an error (" mysql_error() . ")<br>, your entry could " "not be loaded into the database."
    "Please return to <a href=\"index.php\">Home</a>,";
    }
    ?>
             
           </form>
    </body>
    </html>
    Last edited by Kungfu_Jesus; 04-04-2007 at 04:25 PM.

  • #4
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    A suggestion would be to code all your post, get methods correctly with superglobals. Your server must have globals on if $name is working for you. If you were to ever transfer hosts to another shared host and they will not turn on register globals, all of your code will not work.

    Superglobals are:
    $_POST
    $_GET
    $_REQUEST // to retrieve both.

    So you should set it up like this:
    $name = $_POST['name'];

    Just some friendly advice And besides its good coding practice!

  • #5
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    While we're fixing code.

    PHP Code:
    if ($_FILES['imagefile']['type'] == "image/gif"){

    echo 
    "";
    echo 
    "Name: ".$_FILES['imagefile']['name']."";
    echo 
    "Size: ".$_FILES['imagefile']['size']."";
    echo 
    "Type: ".$_FILES['imagefile']['type']."";
    echo 
    "Copy Done....";
    }
    if (
    $_FILES['imagefile']['type'] == "image/jpg"){

    echo 
    "";
    echo 
    "Name: ".$_FILES['imagefile']['name']."";
    echo 
    "Size: ".$_FILES['imagefile']['size']."";
    echo 
    "Type: ".$_FILES['imagefile']['type']."";
    echo 
    "Copy Done....";
    }
    ... 
    Could be:

    PHP Code:
    $ok_types = array('image/gif''image/jpg''image/png');

    if (
    in_array($_FILES['imagefile']['type'], $ok_types) {
        echo 
    'Name: '.$_FILES['imagefile']['name'];
        echo 
    'Size: '.$_FILES['imagefile']['size'];
        echo 
    'Type: '.$_FILES['imagefile']['type'];
        echo 
    'Copy Done....';


  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,036
    Thanks
    2
    Thanked 316 Times in 308 Posts
    For your upload problem, the form tag -
    Code:
    <form id="form1" name="form1" method="post" action="">
    does not have the proper enctype. See the PHP manual under uploading for the correct information - http://www.php.net/manual/en/features.file-upload.php
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •