Editing Error [Status: Unsolved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dm7
Forum Commoner
Posts: 67
Joined: Sat Oct 08, 2005 9:16 pm
Location: USA

Editing Error [Status: Unsolved]

Post by Dm7 »

Code: Select all

<?php
#########################################
#       Admin Gallery System            #
#             admin.php                 #
#########################################
include("auth.inc.php");
include("functions_main.inc.php");
include("fields_login.inc.php");
include("gallery.css");
include("links.css");
$table = "art";
$pix = $_GET['pix'];
$a = $_GET['a'];

//is a (action variable) set?
if (isset($a))
{
	//is a = del?
	if (($a == "del") && ($_SESSION['auth'] == "yes"))
	{
		if (isset($pix))
		{
			Connect_to_db("Vars.inc.php");
			$sql = "DELETE FROM $table WHERE name = '$pix'";
			mysql_query($sql) or die("Error performing query - could not delete! ". mysql_error());
			?><font color="red"><h2><center>This picture has been deleted!</center></font></h2>
			<center><?php echo loginmenu(); ?></center> <?php ;
			mysql_close();
		}
		else 
		{
			echo "No picture to delete from!";
		}
	}
	//is a = edit?
	if (($a == "edit") && ($_SESSION['auth'] == "yes"))
	{
		if (isset($pix))
		{ 
			if (isset($_REQUEST['name'])) 
			{
				$title = $_POST['title'];
				$comment = $_POST['comment'];
				Connect_to_db('Vars.inc.php');
				$sql = "UPDATE $table SET title='$title', comment='$comment' WHERE name='$pix'";
				mysql_query($sql) or die("Error performing query - could not update the tables! ". mysql_error());
				echo '<font color="red"><h2><center>Your picture has been edited!</center></h2></font>';
				mysql_close();
			}
			else
			{
				Connect_to_db('Vars.inc.php');
				$sql = "SELECT * FROM $table WHERE name='$pix'";
				$result = mysql_query($sql);
				
				if ($rows = mysql_fetch_assoc($result) { 
				?>
				   <form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
					  <div align="center">
					  <table width="320" border="0" align="center" cellpadding="2" cellspacing="0">
							<input name="name" type="hidden" value="<?php echo $_REQUEST['pix']; ?>">
						  <tr>
							<td>Title:</td>
							<td><input name="title" type="text" id="title" value="<?php printf("%s",$row['title']); ?>" size="32"></td>
						  </tr>
						  <tr>
							<td valign="top">Comment:</td>
							<td><textarea name="comment" cols="32" rows="4" id="comment" value="<?php print("%s",$row['comment']); ?>"></textarea></td>
						  </tr>
						  <tr>
							<td colspan="2"><div align="right">
							  <input type="submit" name="submit" value="Edit">
							</div></td>
						  </tr>
					</table>
					
					</form>
					<center>
					<?php
					echo loginmenu();
					?>
					</center>
					<?php
					exit();
					}
					
					else
					{
						echo 'Error performing query! '. mysql_error();
					}
			}
		}
		else
		{
			echo "No picture to edit from!";
		}
	}
}
function loginmenu() 
{
global $menu, $menuloginview, $pix;
if($menu == "yes")
{
$edit = "<a href='admin.php?pix=". $pix ."&a=edit'>Edit</a> | ";
$del = "<a href='admin.php?pix=". $pix ."&a=del'>Delete</a> | ";
echo $edit ." ". $del;
	foreach($menuloginview as $key => $value)
	{
		if ($key == "logout") 
		{
			echo $value;
		}
		else 
		{
			echo $value ." | ";
		}
	}
}
}
?>
The error is

Code: Select all

Parse error: parse error, unexpected '{' in /var/www/vhosts/dm7.net/httpdocs/gallery/admin.php on line 56
which is at this line...

Code: Select all

if ($rows = mysql_fetch_assoc($result) {
Any ideas? I can't find any missing { or }'s... I made sure and even counted them... I must have missed something. Thank you in advance for helping... I like this forum very much and I will help out more when I'm more experienced with php someday. :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you're missing a closing paren before {
Dm7
Forum Commoner
Posts: 67
Joined: Sat Oct 08, 2005 9:16 pm
Location: USA

Post by Dm7 »

feyd wrote:you're missing a closing paren before {
Huh I dont see one? I thought all are closed properly.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

count them ;) there are three parens.. two open and one close.
Dm7
Forum Commoner
Posts: 67
Joined: Sat Oct 08, 2005 9:16 pm
Location: USA

Post by Dm7 »

mmm even when I added } before that line.. I still got the same error.. except that it was on line 57.. ( of course cuz i added other line with } in it )...
Here's code snapped from the entire codes.. the rest is the same as above.

Code: Select all

if (isset($pix))
		{ 
			if (isset($_REQUEST['name'])) 
			{
				$title = $_POST['title'];
				$comment = $_POST['comment'];
				Connect_to_db('Vars.inc.php');
				$sql = "UPDATE $table SET title='$title', comment='$comment' WHERE name='$pix'";
				mysql_query($sql) or die("Error performing query - could not update the tables! ". mysql_error());
				echo '<font color="red"><h2><center>Your picture has been edited!</center></h2></font>';
				mysql_close();
			}
		}
			else
			{
				Connect_to_db('Vars.inc.php');
				$sql = "SELECT * FROM $table WHERE name='$pix'";
				$result = mysql_query($sql);
				
				if ($rows = mysql_fetch_assoc($result) {
mmm?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

parens: ( )
braces: { }
brackets: [ ]

;)
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

Code: Select all

if ($rows = mysql_fetch_assoc($result) {
2 ( 1 )
Dm7
Forum Commoner
Posts: 67
Joined: Sat Oct 08, 2005 9:16 pm
Location: USA

Post by Dm7 »

Gotcha.. lol :oops:

Okay... it's still not solved... I have no errors right now, but I'm having weird results... whenever I click a picture and edit it, I don't get any thumbnail image to show up nor that the form with results from database to show up.. as if they are broken... not even loginmenu() function would show up either. o_0.. the only that is working is my form... without values working. :( Here's my updated script with comments, etc.

Code: Select all

<?php
#########################################
#       Admin Gallery System            #
#             admin.php                 #
#########################################
include("auth.inc.php");
include("functions_main.inc.php");
include("fields_login.inc.php");
include("gallery.css");
include("links.css");
$table = "art";
$pix = $_GET['pix'];
$a = $_GET['a'];

//is a (action variable) set?
if (isset($a))
{
	//is a = del?
	if (($a == "del") && ($_SESSION['auth'] == "yes"))
	{
		// checks if $pix is set
		if (isset($pix))
		{
			// deletes the row with $pix as its picker
			Connect_to_db("Vars.inc.php");
			$sql = "DELETE FROM $table WHERE name = '$pix'";
			mysql_query($sql) or die("Error performing query - could not delete! ". mysql_error());
			?><font color="red"><h2><center>This picture has been deleted!</center></font></h2>
			<center><?php echo loginmenu(); ?></center> <?php ;
			mysql_close();
		}
		
		// if $pix isn't set, then an error msg is given.
		else 
		{
			echo "No picture to delete from!";
		}
	}
	//is a = edit?
	if (($a == "edit") && ($_SESSION['auth'] == "yes"))
	{
		// checks if $pix is set
		if (isset($pix))
		{ 
			// checks if form has been submitted.
			if (isset($_REQUEST['name'])) 
			// updates the information.
			{
				$title = $_POST['title'];
				$comment = $_POST['comment'];
				Connect_to_db('Vars.inc.php');
				$sql = "UPDATE $table SET title='$title', comment='$comment' WHERE name='$pix'";
				mysql_query($sql) or die("Error performing query - could not update the tables! ". mysql_error());
				echo '<font color="red"><h2><center>Your picture has been edited!</center></h2></font>';
				mysql_close();
		}
			// if it isn't submitted, then the form is shown
			else
			// connects to db and calls all for form
			{
				Connect_to_db('Vars.inc.php');
				$sql = "SELECT * FROM $table WHERE name='$pix'";
				$result = mysql_query($sql);
				
				if ($rows = mysql_fetch_assoc($result)) { 
				?>
				   <form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
					  <div align="center">
					  <table width="320" border="0" align="center" cellpadding="2" cellspacing="0">
							<input name="name" type="hidden" value="<?php echo $_REQUEST['pix']; ?>">
						  <tr>
						  	<td><img src="<?php printf("%s",$row['tbimage']); ?>"></td>
						  <tr>
							<td>Title:</td>
							<td><input name="title" type="text" id="title" value="<?php printf("%s",$row['title']); ?>" size="32"></td>
						  </tr>
						  <tr>
							<td valign="top">Comment:</td>
							<td><textarea name="comment" cols="32" rows="4" id="comment" value="<?php printf("%s",$row['comment']); ?>"></textarea></td>
						  </tr>
						  <tr>
							<td colspan="2"><div align="right">
							  <input type="submit" name="submit" value="Edit">
							</div></td>
						  </tr>
					</table>
					</form>
					
					<center>
					<?php
					echo loginmenu();
					?>
					</center>
					<?php
					exit();
					}
					
					// for no apparent reasons... if it doesn't run right.. then it'll give an error
					else
					{
						echo 'Error performing query! '. mysql_error();
					}
			}
		}
		// if $pix isn't set then an error msg is given.
		else
		{
			echo "No picture to edit from!";
		}
	}
}

// menu
function loginmenu() 
{
global $menu, $menuloginview, $pix;
if($menu == "yes")
{
$edit = "<a href='admin.php?pix=". $pix ."&a=edit'>Edit</a> | ";
$del = "<a href='admin.php?pix=". $pix ."&a=del'>Delete</a> | ";
echo $edit ." ". $del;
	foreach($menuloginview as $key => $value)
	{
		if ($key == "logout") 
		{
			echo $value;
		}
		else 
		{
			echo $value ." | ";
		}
	}
}
}
?>
Any ideas?
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

i have got few suggestions and clarifications from your code
1. use backticks in sql stmts....i think using 'name' literally shd hv given you a problem.

Code: Select all

$sql = "DELETE FROM $table WHERE name = '$pix'";
2.

Code: Select all

<?php echo loginmenu(); ?>
why do you echo a function when there is no return value

3.

Code: Select all

isset($_REQUEST['name'])
where is this name variable coming from???

4.

Code: Select all

global $menu, $menuloginview, $pix;
I dont see you using those variables earlier in the file; are you importing them from some other files???
Dm7
Forum Commoner
Posts: 67
Joined: Sat Oct 08, 2005 9:16 pm
Location: USA

Post by Dm7 »

Code: Select all

<input name="name" type="hidden" value="<?php echo $_REQUEST['pix']; ?>">
That's where $name comes from. :) and $_REQUEST['pix'] would be from the url.

backticks? What do you mean? I didn't have any problems with that?

I changed

Code: Select all

echo loginmenu();
to

Code: Select all

loginmenu();
And...

Code: Select all

global $menu, $menuloginview, $pix;
$pix is...

Code: Select all

$pix = $_GET['pix'];
$menu and $menuloginview are included from other files. :)
Dm7
Forum Commoner
Posts: 67
Joined: Sat Oct 08, 2005 9:16 pm
Location: USA

Post by Dm7 »

I just reread my code and realized that $pix and $_REQUEST['name'] if/else statement in editing part can cause complications... :oops: I changed $_REQUEST['name'] to $_POST['name'] so that it would get only from form.. not from $_GET... just in case.
Here's my fixed code.. still have weird "not working" editing form (supposed to show the values of old data so I can edit or whatever....

Code: Select all

<?php
#########################################
#       Admin Gallery System            #
#             admin.php                 #
#########################################
include("auth.inc.php");
include("functions_main.inc.php");
include("fields_login.inc.php");
include("gallery.css");
include("links.css");
$table = "art";
$pix = $_GET['pix'];
$a = $_GET['a'];

//is a (action variable) set?
if (isset($a))
{
	//is a = del?
	if (($a == "del") && ($_SESSION['auth'] == "yes"))
	{
		// checks if $pix is set
		if (isset($pix))
		{
			// deletes the row with $pix as its picker
			Connect_to_db("Vars.inc.php");
			$sql = "DELETE FROM $table WHERE name = '$pix'";
			mysql_query($sql) or die("Error performing query - could not delete! ". mysql_error());
			?><font color="red"><h2><center>This picture has been deleted!</center></font></h2>
			<center><?php loginmenu(); ?></center> <?php ;
			mysql_close();
		}
		
		// if $pix isn't set, then an error msg is given.
		else 
		{
			echo "No picture to delete from!";
		}
	}
	//is a = edit?
	if (($a == "edit") && ($_SESSION['auth'] == "yes"))
	{
		// checks if $pix is set
		if (isset($pix))
		{ 
			// checks if form has been submitted.
			if (isset($_POST['name'])) 
			// updates the information.
			{
				$title = $_POST['title'];
				$comment = $_POST['comment'];
				Connect_to_db('Vars.inc.php');
				$sql = "UPDATE $table SET title='$title', comment='$comment' WHERE name='$pix'";
				mysql_query($sql) or die("Error performing query - could not update the tables! ". mysql_error());
				echo '<font color="red"><h2><center>Your picture has been edited!</center></h2></font>';
				mysql_close();
		}
			// if it isn't submitted, then the form is shown
			else
			// connects to db and calls all for form
			{
				Connect_to_db('Vars.inc.php');
				$sql = "SELECT * FROM $table WHERE name='$pix'";
				$result = mysql_query($sql);
				
				if ($rows = mysql_fetch_assoc($result)) { 
				?>
				   <form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
					  <div align="center">
					  <table width="320" border="0" align="center" cellpadding="2" cellspacing="0">
							<input name="name" type="hidden" value="<?php echo $_REQUEST['pix']; ?>">
						  <tr>
						  	<td><img src="<?php printf("%s",$row['tbimage']); ?>"></td>
						  <tr>
							<td>Title:</td>
							<td><input name="title" type="text" id="title" value="<?php printf("%s",$row['title']); ?>" size="32"></td>
						  </tr>
						  <tr>
							<td valign="top">Comment:</td>
							<td><textarea name="comment" cols="32" rows="4" id="comment" value="<?php printf("%s",$row['comment']); ?>"></textarea></td>
						  </tr>
						  <tr>
							<td colspan="2"><div align="right">
							  <input type="submit" name="submit" value="Edit">
							</div></td>
						  </tr>
					</table>
					</form>
					
					<center>
					<?php
					loginmenu();
					?>
					</center>
					<?php
					exit();
					}
					
					// for no apparent reasons... if it doesn't run right.. then it'll give an error
					else
					{
						echo 'Error performing query! '. mysql_error();
					}
			}
		}
		// if $pix isn't set then an error msg is given.
		else
		{
			echo "No picture to edit from!";
		}
	}
}

// menu ($menu and $menuloginview are called from included files)
function loginmenu() 
{
global $menu, $menuloginview, $pix;
if($menu == "yes")
{
$edit = "<a href='admin.php?pix=". $pix ."&a=edit'>Edit</a> | ";
$del = "<a href='admin.php?pix=". $pix ."&a=del'>Delete</a> | ";
echo $edit ." ". $del;
	foreach($menuloginview as $key => $value)
	{
		if ($key == "logout") 
		{
			echo $value;
		}
		else 
		{
			echo $value ." | ";
		}
	}
}
}
?>
Post Reply