Jump to content

files upload to temp folder but not databse


Recommended Posts

<!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=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$hostname='xxx';
$username='xxx';
$password='xxx';
$dbname='xxx;
$usertable=xxx;


$myconn=mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');

if ((($_FILES["file"]["type"] =="image/gif")
|| ($_FILES["file"]["type"] =="image/jpeg")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"]< 200000))
{
if ($_FILES["file"]["error"] >0)
{
	echo "Return Code: " . $_FILES["file"]["error"] . "<br/>";
}
else
{
	if (file_exists("uploads/" . $_FILES["file"]["name"]))
	{
		echo "File already exists. Choose another name.";
	}
		else
		{
			move_uploaded_file($_FILES["file"]["tmp_name"],"uploads/" . $_FILES["file"]["name"]);
		}
}
}
else
{
echo "Invalid file";
}
$path="uploads/" . $_FILES["file"]["name"];
$desc=$_POST["desc"];
if (!myconn)
{
die ('Could not connect: ' . $mysql_error());
} 
$db_selected=mysql_select_db('xxx',$myconn);
if (!$db_selected) {
    die ('Can\'t use xxxx : ' . mysql_error());
} 
  mysql_query("INSERT INTO partners (desc,photopath,state) VALUES ('$desc','$path','$state')");
  mysql_close($myconn);
?>
</body>
</html>

ran it and received this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc,photopath,state) VALUES ('james','uploads/Screen shot 2011-04-28 at 9.19.37' at line 1

here in the upload form;

</style>
</head>


<body>
<div id="wrapper"><h1></h1><div id="Photos">
<form id="form1" name= "form1" method="POST" action="photo_table.php" enctype="multipart/form-data">
<table width="50%"  cellpapdding="5"
cellspacing="0"  bgcolor="#999999">
<tr>
<th height="37" colspan="2" bgcolor="" scope="row"><span class="style1"><h2>Photo Upload</h2></span></th>
    </tr>
    
    <tr>
    <th bordercolor="" scope="row"><div align="right" class="style1"><h1>Photo</h1></div></th>
    <td bgcolor="#FFFFFF"><label>
    <input name="file" type="file"/>
    </label></td>
    </tr>
    <tr>
    <th bordercolor="999999" scope="row"><div align="right" class="style1"><h3>Name(first and last)</h3></div></th>
    <td bgcolor="#FFFFFF"><label>
    <input name="desc" type="text"/>
    </label></td>
    </tr>
    
    <tr>
    <th bordercolor="" scope="row"><div align="right" class="style1"><h3>State</h3></div></th>
    <td bgcolor="#FFFFFF"><label>
    <input name="state" type="text"/>
    </label></td>
    </tr>
    
    
    <tr>
    <th bgcolor="))" scope="row"> </th>
    <td bgcolor=""><label>
  
    <input type="submit" value="submit"/>
    <input type= "reset" value="Reset" name="reset" />
    </label></td>
    </tr>
    </table>
    <input type="hidden" name="NM_insert" value="form1" />
    </form>
    </div></div></div>
</body>
</html>


`desc` is a MySQL reserved word, and as such you should either change the name of the field, or enclose desc in `backticks` whenever it is used as a reference to a field/table/database name. Note that `backticks` are not the same as 'single quotes' . . .

nevermind. fugix you were right about the state var and I just missed one "desc". Changed it to name and works like a charm. Thanks both. Next I want to put a comment system on each file that is uploaded so you may hear from me in a little bit.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.