Jump to content

Parse error: syntax error, unexpected '=' in my script


colcar

Recommended Posts

Hi,

 

Can anyone help me I am receiving this error, when I try to load the script in my browser:

 

Parse error: syntax error, unexpected '=' in C:\Inetpub\wwwroot\newphoto.php on line 76

 

<?php
$db_host = 'localhost'; // don't forget to change 
$db_user = 'root'; 
$db_pwd = 'colum';
$database = 'colum';
$table = 'trailer';// use the same name as SQL table
$password = 'kinefad';// simple upload restriction,// to disallow uploading to everyone
if (!mysql_connect($db_host, $db_user, $db_pwd))    
die("Can't connect to database");
if (!mysql_select_db($database))    
die("Can't select database");
// This function makes usage of// $_GET, $_POST, etc... variables
// completly safe in SQL queries
function sql_safe($s){    
if (get_magic_quotes_gpc())        
	$s = stripslashes($s);    
return mysql_real_escape_string($s);
}
// If user pressed submit in one of the forms
if ($_SERVER['REQUEST_METHOD'] == 'POST'){   

if(isset($_POST['Submit']))  
{ 	//reads the name of the file the user submitted for uploading 

// cleaning title field    
//$title = trim(sql_safe($_POST['title']));  
$model = trim(sql_safe($_POST['model']));
$year = trim(sql_safe($_POST['year']));
$price = trim(sql_safe($_POST['price']));
$location = trim(sql_safe($_POST['location']));
$path = './images/';
$title = trim(sql_safe($_FILES['photo']['filename']));

if ($title == '') // if title is not set 

	$title = '(empty title)';// use (empty title) string    

if ($_POST['password'] != $password)  // cheking passwors        

	$msg = 'Error: wrong upload password';    

else    
{        
	if (isset($_FILES['photo']))        
	{                       
		if (!isset($msg)) // If there was no error            
		{                
			// Preparing data to be used in MySQL query                
			mysql_query("INSERT INTO {$table} SET 	

title='$title',model='$model',year='$year',price='$price',location='$location',path='$path'");                
			$msg = 'Success: image uploaded';            
		}        
	}        
elseif (isset($_GET['title']))      // isset(..title) needed     
	$msg = 'Error: file not loaded';
		// to make sure we've using                                            
		// upload form, not form                                            
		// for deletion           
if (isset($_POST['del'])) // If used selected some photo to delete        
{                         // in 'uploaded images form';            
	$id = intval($_POST['del']);            
	mysql_query("DELETE FROM {$table} WHERE id=$id");            
	$msg = 'Photo deleted';        
}    
}
}
?>
<html><head>
<title>Administration Page</title>
</head>
<body>
<?php
if (isset($msg)) // this is special section for                 
	// outputing message
{
?>
<p style="font-weight: bold;"><?php=$msg?>
<br>
<a href="<?php=$PHP_SELF?>">reload page</a>
<!-- I've added reloading link, because     
refreshing POST queries is not good idea -->
</p>
<?php
}
?>
<h1>Administration Page
</h1>
<h2>Uploaded images:</h2>
<form action="<?php=$PHP_SELF?>" method="post">
<!-- This form is used for image deletion -->

</form>
<h2>Upload new image:</h2>
<form action="<?php=$PHP_SELF?>" method="POST" enctype="multipart/form-data">
//<label for="title">Title:</label><br>
//<input type="text" name="title" id="title" size="64"><br><br>
<label for="model">Model:</label><br>
<input type="text" name="model" id="model" size="64"><br><br>
<label for="year">Year:</label><br>
<input type="text" name="year" id="year" size="64"><br><br>
<label for="price">Price:</label><br>
<input type="text" name="price" id="price" size="64"><br><br>
<label for="location">Location:</label><br>
<input type="text" name="location" id="location" size="64"><br><br>
<label for="photo">Photo:</label><br>
<input type="file" name="photo" id="filename"><br><br>
<label for="password">Password:</label><br>
<input type="password" name="password" id="password"><br><br>
<input type="submit" value="upload">
</form>
</body>
</html>

 

My code stopped working ever since I tried to extract the image name from an image that was posted. The code I added was:

 

	$title = trim(sql_safe($_FILES['photo']['filename']));

 

Any ideas on what I have done wrong or can anyone point me in the correct direction?

 

Thanks

quite a few errors. I think I fixed them all for you:

<?php
$db_host = 'localhost'; // don't forget to change 
$db_user = 'root'; 
$db_pwd = 'colum';
$database = 'colum';
$table = 'trailer';// use the same name as SQL table
$password = 'kinefad';// simple upload restriction,// to disallow uploading to everyone
if (!mysql_connect($db_host, $db_user, $db_pwd)) {   
die("Can't connect to database");
}
if (!mysql_select_db($database))  {  
die("Can't select database");
}
// This function makes usage of// $_GET, $_POST, etc... variables
// completly safe in SQL queries
function sql_safe($s){    
if (get_magic_quotes_gpc()) {       
	$s = stripslashes($s);    
return mysql_real_escape_string($s);
}
}
// If user pressed submit in one of the forms
if ($_SERVER['REQUEST_METHOD'] == 'POST'){   

if(isset($_POST['Submit']))  
{ 	//reads the name of the file the user submitted for uploading 

// cleaning title field    
//$title = trim(sql_safe($_POST['title']));  
$model = trim(sql_safe($_POST['model']));
$year = trim(sql_safe($_POST['year']));
$price = trim(sql_safe($_POST['price']));
$location = trim(sql_safe($_POST['location']));
$path = './images/';
$title = trim(sql_safe($_FILES['photo']['filename']));

if ($title == '') // if title is not set 

	$title = '(empty title)';// use (empty title) string    

if ($_POST['password'] != $password)  // cheking passwors        

	$msg = 'Error: wrong upload password';    

else    
{        
	if (isset($_FILES['photo']))        
	{                       
		if (!isset($msg)) // If there was no error            
		{                
			// Preparing data to be used in MySQL query                
			mysql_query("INSERT INTO {$table} SET 	

title='$title',model='$model',year='$year',price='$price',location='$location',path='$path'");                
			$msg = 'Success: image uploaded';            
		}        
	}        
elseif (isset($_GET['title']))      // isset(..title) needed     
	$msg = 'Error: file not loaded';
		// to make sure we've using                                            
		// upload form, not form                                            
		// for deletion           
if (isset($_POST['del'])) // If used selected some photo to delete        
{                         // in 'uploaded images form';            
	$id = intval($_POST['del']);            
	mysql_query("DELETE FROM {$table} WHERE id=$id");            
	$msg = 'Photo deleted';        
}    
}
}
?>
<html><head>
<title>Administration Page</title>
</head>
<body>
<?php
if (isset($msg)) // this is special section for                 
	// outputing message
{
?>
<p style="font-weight: bold;"><?php print $msg;?>
<br>
<a href="<?php print $_SERVER['PHP_SELF'];?>">reload page</a>
<!-- I've added reloading link, because     
refreshing POST queries is not good idea -->
</p>
<?php
}
}
?>
<h1>Administration Page
</h1>
<h2>Uploaded images:</h2>
<form action="<?php print $_SERVER['PHP_SELF'];?>" method="post">
<!-- This form is used for image deletion -->

</form>
<h2>Upload new image:</h2>
<form action="<?php print $_SERVER['PHP_SELF'];?>" method="POST" enctype="multipart/form-data">
//<label for="title">Title:</label><br>
//<input type="text" name="title" id="title" size="64"><br><br>
<label for="model">Model:</label><br>
<input type="text" name="model" id="model" size="64"><br><br>
<label for="year">Year:</label><br>
<input type="text" name="year" id="year" size="64"><br><br>
<label for="price">Price:</label><br>
<input type="text" name="price" id="price" size="64"><br><br>
<label for="location">Location:</label><br>
<input type="text" name="location" id="location" size="64"><br><br>
<label for="photo">Photo:</label><br>
<input type="file" name="photo" id="filename"><br><br>
<label for="password">Password:</label><br>
<input type="password" name="password" id="password"><br><br>
<input type="submit" value="upload">
</form>
</body>
</html>

Hi,

 

Thanks for the help. That got rid of 3 further errors, but I am stuck on this error:

 

Parse error: syntax error, unexpected $end in C:\Inetpub\wwwroot\newphoto.php on line 113

 

Here is the updated code:

 

<?php
$db_host = 'localhost'; // don't forget to change 
$db_user = 'root'; 
$db_pwd = 'colum';
$database = 'colum';
$table = 'trailer';// use the same name as SQL table
$password = 'kinefad';// simple upload restriction,// to disallow uploading to everyone
if (!mysql_connect($db_host, $db_user, $db_pwd))    
die("Can't connect to database");
if (!mysql_select_db($database))    
die("Can't select database");
// This function makes usage of// $_GET, $_POST, etc... variables
// completly safe in SQL queries
function sql_safe($s){    
if (get_magic_quotes_gpc())        
	$s = stripslashes($s);    
return mysql_real_escape_string($s);
}
// If user pressed submit in one of the forms
if ($_SERVER['REQUEST_METHOD'] == 'POST'){   

if(isset($_POST['Submit']))  
{ 	//reads the name of the file the user submitted for uploading 

// cleaning title field    
//$title = trim(sql_safe($_POST['title']));  
$model = trim(sql_safe($_POST['model']));
$year = trim(sql_safe($_POST['year']));
$price = trim(sql_safe($_POST['price']));
$location = trim(sql_safe($_POST['location']));
$path = './images/';
$title = trim(sql_safe($_FILES['photo']['filename']));

if ($title == '') // if title is not set 

	$title = '(empty title)';// use (empty title) string    

if ($_POST['password'] != $password)  // cheking passwors        

	$msg = 'Error: wrong upload password';    

else    
{        
	if (isset($_FILES['photo']))        
	{                       
		if (!isset($msg)) // If there was no error            
		{                
			// Preparing data to be used in MySQL query                
			mysql_query("INSERT INTO {$table} SET 	

title='$title',model='$model',year='$year',price='$price',location='$location',path='$path'");                
			$msg = 'Success: image uploaded';            
		}        
	}        
elseif (isset($_GET['title']))      // isset(..title) needed     
	$msg = 'Error: file not loaded';
		// to make sure we've using                                            
		// upload form, not form                                            
		// for deletion           
if (isset($_POST['del'])) // If used selected some photo to delete        
{                         // in 'uploaded images form';            
	$id = intval($_POST['del']);            
	mysql_query("DELETE FROM {$table} WHERE id=$id");            
	$msg = 'Photo deleted';        
}    
}
}
?>
<html><head>
<title>Administration Page</title>
</head>
<body>
<?php
if (isset($msg)) // this is special section for                 
	// outputing message
{
?>
<p style="font-weight: bold;"><?php echo $msg; ?>
<br>
<a href="<?php echo $PHP_SELF; ?>">reload page</a>
<!-- I've added reloading link, because     
refreshing POST queries is not good idea -->
</p>
<?php
}
?>
<h1>Administration Page
</h1>
<h2>Uploaded images:</h2>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<!-- This form is used for image deletion -->

</form>
<h2>Upload new image:</h2>
<form action="<?php echo $PHP_SELF; ?>" method="POST" enctype="multipart/form-data">
//<label for="title">Title:</label><br>
//<input type="text" name="title" id="title" size="64"><br><br>
<label for="model">Model:</label><br>
<input type="text" name="model" id="model" size="64"><br><br>
<label for="year">Year:</label><br>
<input type="text" name="year" id="year" size="64"><br><br>
<label for="price">Price:</label><br>
<input type="text" name="price" id="price" size="64"><br><br>
<label for="location">Location:</label><br>
<input type="text" name="location" id="location" size="64"><br><br>
<label for="photo">Photo:</label><br>
<input type="file" name="photo" id="filename"><br><br>
<label for="password">Password:</label><br>
<input type="password" name="password" id="password"><br><br>
<input type="submit" value="upload">
</form>
</body>
</html>

 

The line the error is refering to is the last line. This is odd. I also googled the error and it keeps pointing to using <?php instead of <? , but I have already done this.

 

Any ideas?

 

Thanks

your brackets were left unmatched :P

 

<?php
$db_host = 'localhost'; // don't forget to change 
$db_user = 'root'; 
$db_pwd = 'colum';
$database = 'colum';
$table = 'trailer';// use the same name as SQL table
$password = 'kinefad';// simple upload restriction,// to disallow uploading to everyone
if (!mysql_connect($db_host, $db_user, $db_pwd))    
die("Can't connect to database");
if (!mysql_select_db($database))    
die("Can't select database");
// This function makes usage of// $_GET, $_POST, etc... variables
// completly safe in SQL queries
function sql_safe($s){    
if (get_magic_quotes_gpc())        
	$s = stripslashes($s);    
return mysql_real_escape_string($s);
}
// If user pressed submit in one of the forms
if ($_SERVER['REQUEST_METHOD'] == 'POST'){   

if(isset($_POST['Submit']))  
{ 	//reads the name of the file the user submitted for uploading 

// cleaning title field    
//$title = trim(sql_safe($_POST['title']));  
$model = trim(sql_safe($_POST['model']));
$year = trim(sql_safe($_POST['year']));
$price = trim(sql_safe($_POST['price']));
$location = trim(sql_safe($_POST['location']));
$path = './images/';
$title = trim(sql_safe($_FILES['photo']['filename']));

if ($title == '') // if title is not set 

	$title = '(empty title)';// use (empty title) string    

if ($_POST['password'] != $password)  // cheking passwors        

	$msg = 'Error: wrong upload password';    

else    
{        
	if (isset($_FILES['photo']))        
	{                       
		if (!isset($msg)) // If there was no error            
		{                
			// Preparing data to be used in MySQL query                
			mysql_query("INSERT INTO {$table} SET 	

title='$title',model='$model',year='$year',price='$price',location='$location',path='$path'");                
			$msg = 'Success: image uploaded';            
		}        
	}        
elseif (isset($_GET['title']))      // isset(..title) needed     
	$msg = 'Error: file not loaded';
		// to make sure we've using                                            
		// upload form, not form                                            
		// for deletion           
if (isset($_POST['del'])) // If used selected some photo to delete        
{                         // in 'uploaded images form';            
	$id = intval($_POST['del']);            
	mysql_query("DELETE FROM {$table} WHERE id=$id");            
	$msg = 'Photo deleted';        
}    
}
}
}

?>
<html><head>
<title>Administration Page</title>
</head>
<body>
<?php
if (isset($msg)) // this is special section for                 
	// outputing message
{
?>
<p style="font-weight: bold;"><?php echo $msg; ?>
<br>
<a href="<?php echo $PHP_SELF; ?>">reload page</a>
<!-- I've added reloading link, because     
refreshing POST queries is not good idea -->
</p>
<?php
}
?>
<h1>Administration Page
</h1>
<h2>Uploaded images:</h2>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<!-- This form is used for image deletion -->

</form>
<h2>Upload new image:</h2>
<form action="<?php echo $PHP_SELF; ?>" method="POST" enctype="multipart/form-data">
//<label for="title">Title:</label><br>
//<input type="text" name="title" id="title" size="64"><br><br>
<label for="model">Model:</label><br>
<input type="text" name="model" id="model" size="64"><br><br>
<label for="year">Year:</label><br>
<input type="text" name="year" id="year" size="64"><br><br>
<label for="price">Price:</label><br>
<input type="text" name="price" id="price" size="64"><br><br>
<label for="location">Location:</label><br>
<input type="text" name="location" id="location" size="64"><br><br>
<label for="photo">Photo:</label><br>
<input type="file" name="photo" id="filename"><br><br>
<label for="password">Password:</label><br>
<input type="password" name="password" id="password"><br><br>
<input type="submit" value="upload">
</form>
</body>
</html>

Hi,

 

Thanks. I downloaded Notepad 2 and used it to match the brackets.....now the data won't upload to the DB....ahhhhhh ;)

 

Also my upload messages i.e. successful upload or failed to upload aren't even appearing....it's just one thing after another

 

<?php
$db_host = 'localhost'; // don't forget to change 
$db_user = 'root'; 
$db_pwd = 'colum';
$database = 'colum';
$table = 'trex';// use the same name as SQL table
$password = 'kinefad';// simple upload restriction,// to disallow uploading to everyone
if (!mysql_connect($db_host, $db_user, $db_pwd))    
die("Can't connect to database");
if (!mysql_select_db($database))    
die("Can't select database");
// This function makes usage of// $_GET, $_POST, etc... variables
// completly safe in SQL queries
function sql_safe($s){    
if (get_magic_quotes_gpc())        
	$s = stripslashes($s);    
return mysql_real_escape_string($s);
}
// If user pressed submit in one of the forms
if ($_SERVER['REQUEST_METHOD'] == 'POST'){   

if(isset($_POST['submit']))  
{ 	//reads the name of the file the user submitted for uploading 

// cleaning title field    
$title = trim(sql_safe($_POST['name']));  
$model = trim(sql_safe($_POST['model']));
$year = trim(sql_safe($_POST['year']));
$price = trim(sql_safe($_POST['price']));
$location = trim(sql_safe($_POST['location']));
$path = './images/';
$imagename = trim(sql_safe($_FILES['photo']['filename']));

if ($title == '') // if title is not set 

	$title = '(empty title)';// use (empty title) string    

if ($_POST['password'] != $password)  // cheking passwors        

	$msg = 'Error: wrong upload password'; 

else    
{        
	if (isset($_FILES['photo']))        
	{                       
		if (!isset($msg)) // If there was no error            
		{                
			// Preparing data to be used in MySQL query                
			mysql_query("INSERT INTO {$table} SET 	

title='$title',model='$model',year='$year',price='$price',location='$location',path='$path',imagename='$imagename'");                
			$msg = 'Success: image uploaded';            
		}        
	}        
elseif (isset($_GET['name']))      // isset(..title) needed     
	$msg = 'Error: file not loaded';
		// to make sure we've using                                            
		// upload form, not form                                            
		// for deletion           
if (isset($_POST['del'])) // If used selected some photo to delete        
{                         // in 'uploaded images form';            
	$id = intval($_POST['del']);            
	mysql_query("DELETE FROM {$table} WHERE id=$id");            
	$msg = 'Photo deleted';        
}    
}
}
}
?>
<html><head>
<title>Administration Page</title>
</head>
<body>
<?php
if (isset($msg)) // this is special section for                 
	// outputing message
{
?>
<p style="font-weight: bold;"><? echo $msg; ?>
<br>
<a href="<?php echo $PHP_SELF; ?>">reload page</a>
<!-- I've added reloading link, because     
refreshing POST queries is not good idea -->
</p>
<?php
}
?>
<h1>Administration Page
</h1>
<h2>Uploaded images:</h2>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<!-- This form is used for image deletion -->

</form>
<h2>Upload new image:</h2>
<form action="<?php echo $PHP_SELF; ?>" method="POST" enctype="multipart/form-data">
<label for="name">Name:</label><br>
<input type="text" name="name" id="name" size="64"><br><br>
<label for="model">Model:</label><br>
<input type="text" name="model" id="model" size="64"><br><br>
<label for="year">Year:</label><br>
<input type="text" name="year" id="year" size="64"><br><br>
<label for="price">Price:</label><br>
<input type="text" name="price" id="price" size="64"><br><br>
<label for="location">Location:</label><br>
<input type="text" name="location" id="location" size="64"><br><br>
<label for="photo">Photo:</label><br>
<input type="file" name="photo" id="filename"><br><br>
<label for="password">Password:</label><br>
<input type="password" name="password" id="password"><br><br>
<input type="submit" value="upload">
</form>
</body>
</html>

 

Any suggestions? I've been looking at it for hours and still can't figure it out.

 

Thanks

Hi,

 

Thanks. I've located where the execution of the code gets to...not sure as to why it does not get any further.

 

It gets as far as the 1st help, but doesn't get to the 2nd one...Still trying to figure it out.

 

<p>help</p>
<?php

if(isset($_POST['submit']))  
{ 	//reads the name of the file the user submitted for uploading 

?>
<p>help2</p>
<?php
// cleaning title field    
$title = trim(sql_safe($_POST['name']));  
$model = trim(sql_safe($_POST['model']));
$year = trim(sql_safe($_POST['year']));

 

Thanks

 

Hi,

 

It should be, see the code for the form\;

 

</form>
<h2>Upload new image:</h2>
<form action="<?php echo $_SERVER['PHP_SELF'];?>"  method="POST" enctype="multipart/form-data">
<label for="name">Name:</label><br>
<input type="text" name="name" id="name" size="64"><br><br>
<label for="model">Model:</label><br>
<input type="text" name="model" id="model" size="64"><br><br>
<label for="year">Year:</label><br>
<input type="text" name="year" id="year" size="64"><br><br>
<label for="price">Price:</label><br>
<input type="text" name="price" id="price" size="64"><br><br>
<label for="location">Location:</label><br>
<input type="text" name="location" id="location" size="64"><br><br>
<label for="photo">Photo:</label><br>
<input type="file" name="photo" id="filename"><br><br>
<label for="password">Password:</label><br>
<input type="password" name="password" id="password"><br><br>
<input type="submit" value="submit">
</form>
</body>
</html>

 

Thanks

Hi,

 

Thanks a million that worked. It's updating the DB...

 

I found one more problem, could you help me?

 

I am trying to extract the name of the image from the one that is selected, it's not setting anthing in the DB.

 

Is this the correct way to extract it from the image?

 

$imagename = trim(sql_safe($_FILES['photo']['filename']));

 

Thanks

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.