...

View Full Version : Error Compiling with Forms



Kungfu_Jesus
03-31-2007, 06:42 AM
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/mothman/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>

Nightfire
03-31-2007, 02:53 PM
Missing . after $url



$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
tags to colour the code on here. Indenting your code seriously makes it easier to read too, you should try it

Kungfu_Jesus
04-04-2007, 05:20 PM
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/mothman/mapsubmit.php

And here is the updated 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>

iLLin
04-04-2007, 05:25 PM
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!

aedrin
04-04-2007, 06:11 PM
While we're fixing 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:



$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....';
}

CFMaBiSmAd
04-04-2007, 06:49 PM
For your upload problem, the form tag -

<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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum