Jump to content

unplugged_web

Members
  • Posts

    897
  • Joined

  • Last visited

Everything posted by unplugged_web

  1. I'm sorry I know I'm being really dumb here, but I still don't understand it. I just can't get my ahead around this. The entire code I've got is: <?php $image = intval($_GET['id']);?><?php include 'includes/db.php'; ?><?php$con = mysql_connect($host,$username,$password);if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM images WHERE id = $image");($row = mysql_fetch_array($result));mysql_close($con);$filename = $row['filename'];$title = $row['title'];$class = $row['class'];$category = $row['category'];?><!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=ISO-8859-1" /><title>Untitled Document</title></head> <body><div><form action="" method="get" name="Update_Image"><img src="/uploads/image/filename/<?php echo $filename ?>" alt="<?php echo $title ?>" title="<?php echo $title ?>" /><br />Image title: <input name="Title" value="<?php echo $title ?>"/><br />Image class (Portfolio, Artist or Bio): <input name="class" value="<?php echo $class ?>"/><?php$con = mysql_connect($host,$username,$password);if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM styles");while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";$style_id = $row['id'];$category = $row['category'];$new_category = (explode(" ",$category));if (in_array($style_id,$new_category)) {echo "checked=\"checked\""; }else {echo "checked=\"unchecked\""; }echo "/>";mysql_close($con);?></form></div></body></html> but that returns an error saying:Parse error: syntax error, unexpected '{' in edit.php on line 8If I remove that '{' then I get this:Parse error: syntax error, unexpected T_EXIT in edit.php on line 9
  2. Sorry I'm not sure where I'm going wrong here, I got the code to connect from this page So this is what I should be doing: $category = $row['category'];$old_category = (explode(" ",$category));$new_category = array($old_category);
  3. I've removed the extra semi-colon and added one where it should be but I still get the same error. I'd prefer to have it all in one go but will I still be able to do the checkboxes if I do? Thanks
  4. I've tried it but just get an error saying: Parse error: syntax error, unexpected '{' in edit.php on line 8 If I remove that '{' then I get this: Parse error: syntax error, unexpected T_EXIT in edit.php on line 9 This is the entire page:<?php $image = intval($_GET['id']);;?><?php include 'includes/db.php'?><?php$con = mysql_connect($host,$username,$password);if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM images WHERE id = $image");($row = mysql_fetch_array($result));mysql_close($con);?><?php $filename = $row['filename'];$title = $row['title'];$class = $row['class'];$category = $row['category'];?><!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=ISO-8859-1" /><title>Untitled Document</title></head> <body><div><form action="" method="get" name="Update_Image"><img src="/uploads/image/filename/<?php echo $filename ?>" alt="<?php echo $title ?>" title="<?php echo $title ?>" /><br />Image title: <input name="Title" value="<?php echo $title ?>"/><br />Image class (Portfolio, Artist or Bio): <input name="class" value="<?php echo $class ?>"/><?php$con = mysql_connect($host,$username,$password);if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM styles");$style_id = $row['id'];while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";$category = $row['category'];$old_category (explode(" ",$category));$new_category array($old_category);$category = array($new_category); if (in_array($id,$new_category)) {echo "checked=\"checked\""; }else {echo "checked=\"unchecked\""; }echo "/>";mysql_close($con);?></form></div></body></html>
  5. Sorry I wasn't very clear, the category value has already been retrieved from an earlier query. The full code is: <?php$con = mysql_connect($host,$username,$password);if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM images WHERE id = $image");($row = mysql_fetch_array($result));mysql_close($con);?><?php $filename = $row['filename'];$title = $row['title'];$class = $row['class'];$category = $row['category'];?><form action="" method="get" name="Update_Image"><img src="/uploads/image/filename/<?php echo $filename ?>" alt="<?php echo $title ?>" title="<?php echo $title ?>" /><br />Image title: <input name="Title" value="<?php echo $title ?>"/><br />Image class (Portfolio, Artist or Bio): <input name="class" value="<?php echo $class ?>"/><?php$con = mysql_connect($host,$username,$password);if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM styles");$style_id = $row['id'];while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";$category = $row['category'];$old_category (explode(" ",$category));$new_category array($old_category);$category = array($new_category); if (in_array($id,$new_category)) {echo "checked=\"checked\""; }else {echo "checked=\"unchecked\""; }echo "/>";mysql_close($con);?> </form>
  6. Sorry to sound dumb but I don't understand why it won't work? The first part <?php$category = $row['category'];$new_category (explode(" ",$category));?> Looks to me list it would get the value of 'category' from the database, then pass it through the explode function? So instead of being one long string it is then a series of values. (so 1 2 3 9 12 30 becomes 1, 2, 3, 9, 12, 30) The next part checks to see if the id of the style matches anything in the category field?Or is the problem with this line? It should be new_category instead? if (in_array($id,$category)) Or would this work better: <?php$category = $row['category'];$old_category (explode(" ",$category));$new_category array($old_category);?><?php$category = array($new_category); if (in_array($id,$new_category)) { echo "Match found"; }else { echo "Match not found"; }?>
  7. So if I did something like this: <?php$category = $row['category'];$new_category (explode(" ",$category));?><?php$category = array($new_category); if (in_array($id,$category)) { echo "Match found"; }else { echo "Match not found"; }?> would that work? The full code is below <?php$category = $row['category'];$new_category (explode(" ",$category));?><?php$con = mysql_connect($host,$username,$password);if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM styles");while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";$category = array($new_category); if (in_array($id,$category)) { echo "checked=\"checked\""; }else { echo "checked=\"unchecked\""; } echo "/>";mysql_close($con);?>
  8. Trouble is it's a live database that's already been set up, I've got to find a way to make it work within the site I'm building. Sorry to ask but how do I do that, I'm not very good with array's and my php knowledge is only basic. Thanks
  9. Is there a php equivalent that I can use then? If not what's the best way of doing this?
  10. I've got two tables, one has a list of categories in it and the other has a field with all of the categories that are active. So if categories 1, 3, 8, 90 and 70 are active for entry 'c' then that entry will have 1 3 8 90 70 in the category_id field. This is fine but I'm trying to display it using checkboxes and if the category id is in the category_id field then the box should be ticked. To do this I'm using, this ($category has ready been defined on the page): <?php$con = mysql_connect($host,$username,$password);if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM styles");$style_id = $row['id'];while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";if ( $category LIKE %$style_id% )echo "checked=\"checked\""; echo "/>";mysql_close($con);?> But all I get is Parse error: syntax error, unexpected T_STRING If I change if ( $category LIKE %$style_id% ) to if ( $category != $style_id ) then only the last box is ticked. I'm really puzzled as to what's happening here and how I can fix it. I want all of the categories to be shown, but only the active ones to be ticked.
  11. Thanks, I'll check out that link, the server was showing errors but I fixed those then it stopped showing them altogether.
  12. I'm not sure why this isn't working. I have a table of entries, but I'd like to change the running order of the entries. I've created a field called 'priority' and I want the people in the back end to change the order of the entries themselves. So for example, if they move one entry up then the one above will automatically move down. I'm not getting any errors at all, just a blank page.The code I've written is: <?php$id = $_GET['id'];$direction = $_GET['direction']; con = mysql_connect("hostname", "user", "password");if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("table", $con); $sql = "SELECT priority FROM Reviews WHERE ID = $id";list($curpos) = mysql_fetch_array(mysql_query($sql) or die(mysql_error())); // Find new positionif ($direction > 0){// To be moved up$sql = "SELECT priority FROM Reviews WHERE priority < '$curpos' ORDER BY priority LIMIT 1";list($newpos) = mysql_fetch_array(mysql_query($sql) or die(mysql_error()));}else{// To be moved down$sql = "SELECT priority FROM Reviews WHERE priority > '$curpos' ORDER BY priority LIMIT 1";list($newpos) = mysql_fetch_array(mysql_query($sql) or die(mysql_error()));} if ($newpos){$sql = "UPDATE Reviews SET priority = $curpos WHERE priority = $newpos";mysql_query($sql) or die(mysql_error()); $sql = "UPDATE Reviews SET priority = $newpos WHERE ID = $id AND priority = $curpos";mysql_query($sql) or die(mysql_error()); if (!mysql_error() && mysql_affected_rows()) $msg = "Review moved"; }mysql_close($con);?> but this doesn't seem to do anything. I'd be grateful for any help. I have in working perfectly for another table in the same database, but even if I copy the code over and ust change the relevant fields it still doesn't work. The 'priority' field is set to not null and is an integer. Thanks for any help
×
×
  • Create New...