Jump to content

unexpected '}' , but I'm not seeing it


turpentyne

Recommended Posts

Am I blind? I don't see the problem with this code. It says:

 

Parse error: syntax error, unexpected '}' in /data/21/2/40/160/2040975/user/2235577/htdocs/edit_user1.php on line 35

 

 




<html>
<body>

<?php


if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) {

$id = $_GET['id'];

} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) {

$id = $_POST['id'];

} else {

echo 'you have reached this page in error. no variable passed';
exit();
}

// that was the part to check for passed variables. This is what does something with it

require ('databaseconnect.php');

if (isset($_POST['submitted'])) {

$errors = array();

}

if (empty($_POST['scientific name'])) {

$errors[] = 'you did not enter a scientific name'

} else {

$sn = escape_data($_POST['scientific_name']);

}

// now the common name

if (empty($_POST['common_name_english'])) {

$errors[] = 'you did not enter a common name'

} else {

$cn = escape_data($_POST['scientific_name_english']);
}

// now make changes

if (empty($errors)) {

$query = "UPDATE table SET plant_name='$id', scientific_name='$sn', common_name_english='$cn' WHERE plant_name=$id";


$result = $mysql_query ($query);
if (mysql_affected_row() == 1) {

echo 'edit a plant<br>
The plant has edited'
} else {
echo 'system error<br>
the plant could not be edited due to a system error.';

echo mysql_error() . 'query:' . $query ;
exit();
}

} else {

echo 'error<br>
something already insystem or did not work.';

}

} else {

echo 'error<br>';
foreach ($errors as $msg) {

echo " - $msg<br>";

}
echo ' please try again';

} // end of if
} //  endo of submit condition
// always show form

$query = "SELECT scientific_name, Common_name_english FROM table WHERE plant_name=$id";

$result = $mysql_query ($query); 

if(mysql_num_rows($result) == 1) {

$row mysql fetch_array ($result);

echo 'edit a user'

<form action="edit_user1.php" method="post">
scientific name: <input type="text" name="scientific_name" size="45" value="'
. $row[scientific_name] . '"><br>
common name: <input type="text" name="common_name_english" size="45" value="'
. $row[common_name_english] . '"><br>

<input type="submit" name="submit" value="submit" /><br>
<input type="hidden" name="submitted" value="TRUE" />
<input type="hidden" name="id" value="' . $id . '"/>
</form>';

} else { 
echo 'page error';

}

mysql_close();

</body>
</html>

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

$errors[] = 'you did not enter a common name' needs a ;

 

instead all instances of $errors[] doesnt have a ;, and neither do your echo statements.

 

i'll get you fixed up code in a moment.  i keep relooking and see more things wrong.

Link to comment
Share on other sites

okay i havent tested this but try this and see what happens.

 

<html>
<body>
<?php
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) {
$id = $_GET['id'];

} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) {
	$id = $_POST['id'];

	} else {
		echo 'you have reached this page in error. no variable passed';

		exit();

		}
		// that was the part to check for passed variables. This is what does something with it
		require ('databaseconnect.php');

		if (isset($_POST['submitted'])) {
			$errors = array();

		}
		if (empty($_POST['scientific name'])) {
			$errors[] = 'you did not enter a scientific name';
		} else {
			$sn = escape_data($_POST['scientific_name']);

		}
		// now the common name
		if (empty($_POST['common_name_english'])) {
			$errors[] = 'you did not enter a common name';

		} else {
			$cn = escape_data($_POST['scientific_name_english']);

		}
		// now make changes
		if (empty($errors)) {
			$query = "UPDATE table SET plant_name='$id', scientific_name='$sn', common_name_english='$cn' WHERE plant_name=$id";

			$result = mysql_query ($query);

			if (mysql_affected_row() == 1) {
				echo 'edit a plant<br>The plant has edited';
			} else {
				echo 'system error<br>the plant could not be edited due to a system error.';

				echo mysql_error() . 'query:' . $query ;
exit();

			}
		} else {
			echo 'error<br>something already insystem or did not work.';

		}
		} else {
			echo 'error<br>';
foreach ($errors as $msg) {
				echo " - $msg<br>";
}echo ' please try again';

		} // end of if
		} //  endo of submit condition // always show form
		$query = "SELECT scientific_name, Common_name_english FROM table WHERE plant_name=$id";
$result = $mysql_query ($query);
if(mysql_num_rows($result) == 1) {
 $row mysql fetch_array ($result);
echo 'edit a user';
?>
<form action="edit_user1.php" method="post">scientific name: <input type="text" name="scientific_name" size="45" value="'. $row[scientific_name] . '"><br>common name: <input type="text" name="common_name_english" size="45" value="'. $row[common_name_english] . '"><br><input type="submit" name="submit" value="submit" /><br><input type="hidden" name="submitted" value="TRUE" /><input type="hidden" name="id" value="' . $id . '"/></form>
<?php
} else { echo 'page error';
}
mysql_close();
?>
</body></html>

 

saw some missing ;'s still so i just added those in.

Link to comment
Share on other sites

That's what I get for typing first thing in the morning, half asleep, eh? And for being a beginner.

 

Thanks for that.

 

I still get an unexpected } error for line 55.

 

When I take one out there, just to see what happens I get:

 

unexpected T_ELSE in /data/21/2/40/160/2040975/user/2235577/htdocs/edit_user1.php on line 55

Link to comment
Share on other sites

k i just rewrote your code from scratch...  try this

 

<html>
<body>
<?php
if (isset($_GET['id'])) && (is_numeric($_GET['id'])) {
$if = $_GET['id'];
} elseif (isset($_POST['id'])) && (is_numeric($_GET['id'])) {
$id = $_POST['id'];
} else {
echo "you have reached this page in error.  no variable passed";
exit();
}// end of if, elseif, else statement 1

require('databaseconnect.php');

if(isset($_POST['submitted'])) {
$errors = array();
} // setup the array

if(empty($_POST['scientific_name'])) {
$errors[] = 'you did not enter a scientific name';
} else {
$sn = escape_data($_POST['scientific_name']);
}

if(empty($_POST['common_name_english'])) {
$errors[] = 'you did not enter a common name';
} else {
$cn = escape_data($_POST['scientific_name_english']);
}

if(empty($errors)) {
$query = "UPDATE table SET plant_name='$id', scientific_name='$sn', common_name_english='$cn' WHERE plant_name=$id";
$result = mysql_query($query);
if(mysql_affected_rows() == 1) {
	echo 'edit a plant<br>The plant has edited';
} else {
	echo 'system error<br>the plant could not be edited due to a system error.';
	echo mysql_error(). 'query: '. $query;
	exit();
}
} else {
echo 'error<br>';
foreach($errors as $msg) {
	echo " - $msg<br>";
}
echo 'please try again';
}
$query = "SELECT scientific_name, Common_name_english FROM table WHERE plant_name=$id";
$result = $mysql_query ($query);
if(mysql_num_rows($result) == 1) {
$row mysql fetch_array ($result);
echo 'edit a user';
?>
<form action="edit_user1.php" method="post">scientific name: <input type="text" name="scientific_name" size="45" value="'. $row[scientific_name] . '"><br>common name: <input type="text" name="common_name_english" size="45" value="'. $row[common_name_english] . '"><br><input type="submit" name="submit" value="submit" /><br><input type="hidden" name="submitted" value="TRUE" /><input type="hidden" name="id" value="' . $id . '"/></form>
<?php
} else { 
echo 'page error';
}
mysql_close();
?>
</body></html>

 

problem was, you had an }else{ after an else which made is to the 2nd else didnt have any belonging especially since you closed the previous else already.

 

Then you had an extra } down at the bottom to compensate for that out of place else statement.

 

this should work for you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.