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!
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.
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.
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) {
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.
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.
I just reread my code and realized that $pix and $_REQUEST['name'] if/else statement in editing part can cause complications... 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....
<?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 ." | ";
}
}
}
}
?>