Ingolme Posted October 4, 2012 Share Posted October 4, 2012 I copied your code and I'm not getting the error message you mentioned. And that error message shouldn't be there. Link to comment Share on other sites More sharing options...
unplugged_web Posted October 4, 2012 Author Share Posted October 4, 2012 (edited) I copied your code and I'm not getting the error message you mentioned. And that error message shouldn't be there.This is the page where the code is: here I've got other pages on that site that are working okay - it's just that one. The hosts said that they've just moved it to a new server and I did wonder if that was the problem but I'm still getting hte error Edited October 4, 2012 by thehappyappy Link to comment Share on other sites More sharing options...
Ingolme Posted October 4, 2012 Share Posted October 4, 2012 Can you upload the file as an attachment on the forum? I cannot see anything in the code you pasted on the forum that would cause that error. Link to comment Share on other sites More sharing options...
unplugged_web Posted October 4, 2012 Author Share Posted October 4, 2012 I've also made the 'includes' part of the code a full address so you should be able to connect to the database. Thanks for trying to help me get this sorted edit.php Link to comment Share on other sites More sharing options...
Ingolme Posted October 4, 2012 Share Posted October 4, 2012 I'll tell you what's going on: Those aren't ordinary spaces in your code. I don't know what they are but you should remove them and press the space bar. Specifically the spaces on all your if() {} blocks. Did you copy that code from somewhere else? Link to comment Share on other sites More sharing options...
unplugged_web Posted October 4, 2012 Author Share Posted October 4, 2012 I'm pretty sure I've removed all of the spaces, but I'm still getting the same error. I've attached the file with the spaces gone. Yes I did copy the code from somewhere but I ended up getting myself in such a muddle I don't know where I got it from. edit.php Link to comment Share on other sites More sharing options...
Ingolme Posted October 4, 2012 Share Posted October 4, 2012 I just tried your new file but it's not giving me that error message. It's working fine for me. What error message do you see? Link to comment Share on other sites More sharing options...
unplugged_web Posted October 4, 2012 Author Share Posted October 4, 2012 (edited) I just tried your new file but it's not giving me that error message. It's working fine for me. What error message do you see?Still exactly the same one:Parse error: syntax error, unexpected '{' in /new_site/edit.php on line 6 EDIT:I think there might be a problem on the server - I've deleted the file from the server but when I go to the same address I still get the error rather than being told the page doesn't exist! The hosting has just been moved to a new server coudl that be causing a problem? Edited October 4, 2012 by thehappyappy Link to comment Share on other sites More sharing options...
Ingolme Posted October 4, 2012 Share Posted October 4, 2012 Maybe it's your browser's cache. Though maybe it's server-side cacheing. I've only ever experienced server-side cacheing with SWF files, though. Link to comment Share on other sites More sharing options...
unplugged_web Posted October 5, 2012 Author Share Posted October 5, 2012 Maybe it's your browser's cache. Though maybe it's server-side cacheing. I've only ever experienced server-side cacheing with SWF files, though.It's now working and the page is loading, although the original problem is still there. It's still not ticking only the boxes that are in the 'category' field: <?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);?> Link to comment Share on other sites More sharing options...
thescientist Posted October 5, 2012 Share Posted October 5, 2012 what does your generated HTML output look like? Have you checked the values of anything in your script? $category, $style_id, etc? I don't see any attempts at debugging. Link to comment Share on other sites More sharing options...
unplugged_web Posted October 5, 2012 Author Share Posted October 5, 2012 (edited) what does your generated HTML output look like? Have you checked the values of anything in your script? $category, $style_id, etc? I don't see any attempts at debugging.I've changed the page and the category outputs correctly. If I move the $style_id = $row['id']; row to just under the while($row = mysql_fetch_array...... then style_id out puts correctly, but the checkboxes don't show at all. If I leave it where it is then the checkboxes how but they're not checked as they should be. New_category just outputs Array whatever I do This is the code I've got so far:<?php$image = intval($_GET['id']);include 'includes/db.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'];$new_category = (explode(" ",$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'];if (in_array($style_id,$new_category)){echo "checked=\"checked\"";}else{echo "checked=\"unchecked\"";}echo "/>";mysql_close($con);?></form></div></body></html> Edited October 5, 2012 by thehappyappy Link to comment Share on other sites More sharing options...
thescientist Posted October 5, 2012 Share Posted October 5, 2012 i did ask for the generated HTML, can you provide that? You should be looking at what is being produced to see why it might not be showing correctly. If you aren't generating proper HTML, then you can't trust your logic. Also, since you didn't include the debugging lines, I'm not sure how you debugged $new_category. try var_dump instead. It sounds like the values are right, or at least there, but it sounds like you aren't putting the HTML together correctly. Link to comment Share on other sites More sharing options...
unplugged_web Posted October 5, 2012 Author Share Posted October 5, 2012 i did ask for the generated HTML, can you provide that? You should be looking at what is being produced to see why it might not be showing correctly. If you aren't generating proper HTML, then you can't trust your logic. Also, since you didn't include the debugging lines, I'm not sure how you debugged $new_category. try var_dump instead. It sounds like the values are right, or at least there, but it sounds like you aren't putting the HTML together correctly.This is what being generated. It doesn't look like it's generating anything after the first line, but I don't understand why. <!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/01-0.jpg" alt="" title="" /><br />Image title: <input name="Title" value=""/><br />Image class: <input name="class" value=""/><br />architecture: <input name="3" type="checkbox" <br />black & white: <input name="5" type="checkbox" <br />cut paper: <input name="6" type="checkbox" <br />vector: <input name="8" type="checkbox" <br />food & beverage: <input name="11" type="checkbox" <br />healthcare: <input name="12" type="checkbox" <br />humerous: <input name="13" type="checkbox" <br />infographics: <input name="15" type="checkbox" <br />tweens: <input name="48" type="checkbox" <br />nature: <input name="17" type="checkbox" <br />logo & lettering: <input name="18" type="checkbox" <br />maps: <input name="19" type="checkbox" <br />oil/acrylic: <input name="20" type="checkbox" <br />animation: <input name="44" type="checkbox" <br />pin ups: <input name="24" type="checkbox" <br />portraits: <input name="61" type="checkbox" <br />retro: <input name="26" type="checkbox" <br />watercolor: <input name="29" type="checkbox" <br />painterly: <input name="32" type="checkbox" <br />photo realistic: <input name="37" type="checkbox" <br />digital: <input name="47" type="checkbox" <br />CGI: <input name="45" type="checkbox" <br />collage: <input name="41" type="checkbox" checked="unchecked"/><br />category: 3 5 6 8 11 12 13 15 48 17 18 19 20 44 24 61 26 29 32 37 47 45 41<br />new: Array<br />id: </form></div></body></html> Link to comment Share on other sites More sharing options...
justsomeguy Posted October 5, 2012 Share Posted October 5, 2012 The checkbox tags aren't closed. The block of your while loop is only a single line, there aren't any brackets. Link to comment Share on other sites More sharing options...
unplugged_web Posted October 5, 2012 Author Share Posted October 5, 2012 The checkbox tags aren't closed.The only way I can get them to close it so add "/>' before the in_array - even if that's not there they still won't close. I know it probably sounds quite straightforward but I can't work it out - I don't know where I'm going wrong Link to comment Share on other sites More sharing options...
justsomeguy Posted October 5, 2012 Share Posted October 5, 2012 while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" "; That is your entire while loop. There aren't any brackets to tell it how many lines to loop over, so it loops over 1 line. It loops over that line outputting the unclosed checkboxes, and then runs the rest of the code once after the loop finishes. It sounds like you need more lines then just that one in the loop. Link to comment Share on other sites More sharing options...
unplugged_web Posted October 5, 2012 Author Share Posted October 5, 2012 while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" "; That is your entire while loop. There aren't any brackets to tell it how many lines to loop over, so it loops over 1 line. It loops over that line outputting the unclosed checkboxes, and then runs the rest of the code once after the loop finishes. It sounds like you need more lines then just that one in the loop. I thought the whole loop was this:while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";$style_id = $row['id'];if (in_array($style_id,$new_category)){echo "checked=\"checked\"";}else{echo "checked=\"unchecked\"";}echo "/>"; That's what I wanted/tried to get it to be Link to comment Share on other sites More sharing options...
justsomeguy Posted October 5, 2012 Share Posted October 5, 2012 Then tell that to PHP. How is PHP supposed to know whether you want to loop over this: while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" "; or this: while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";$style_id = $row['id']; or this: while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";$style_id = $row['id'];if (in_array($style_id,$new_category)){echo "checked=\"checked\"";}else{echo "checked=\"unchecked\"";} or this: while($row = mysql_fetch_array($result))echo "<br />". $row['name'] .": <input name=\"{$row['id']}\" type=\"checkbox\" ";$style_id = $row['id'];if (in_array($style_id,$new_category)){echo "checked=\"checked\"";}else{echo "checked=\"unchecked\"";}echo "/>"; You're not telling it what to loop over, so it assumes you only want to loop over a single line. Link to comment Share on other sites More sharing options...
unplugged_web Posted October 5, 2012 Author Share Posted October 5, 2012 So how do I tell it to continually loop until it's done? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 5, 2012 Share Posted October 5, 2012 The exit condition is part of the while statement, you're telling to loop as long as $row contains data. You're not telling it how many lines to loop over. You specify the block to execute the same way you specify the block that an if or else statement should execute, or any other loop or function for that matter. Link to comment Share on other sites More sharing options...
thescientist Posted October 5, 2012 Share Posted October 5, 2012 So how do I tell it to continually loop until it's done?a wild idea, but perhaps take a stroll through the tutorials? just sayin...http://www.w3schools.com/php/php_looping.asphttp://www.w3schools.com/php/php_mysql_select.asp Link to comment Share on other sites More sharing options...
unplugged_web Posted October 8, 2012 Author Share Posted October 8, 2012 Thank you, I've changed it to: <?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'];if (in_array($style_id,$new_category)){echo "checked=\"checked\"";}else{echo "checked=\"unchecked\"";}echo "/>";}mysql_close($con);?> and it now works perfectly Link to comment Share on other sites More sharing options...
unplugged_web Posted October 10, 2012 Author Share Posted October 10, 2012 I now seem to be having a problem adding the results into a database. I'm not sure why but it's just not updating This is what I've got: <?php$style = (isset($_POST['style']) ? implode(' ', $_POST['style']) : '');$title = $_POST['Title'];$image_id = $_POST['image_id']; echo $style;echo "<br />";echo $title;echo "<br />";echo $image_id; include 'includes/db.php';$con = mysql_connect($host,$username,$password);if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db($database, $con);mysql_query("UPDATE images SET title = '$title' AND category = '$style' WHERE id = '$image_id'");mysql_close($con);?> Everything seems to be outputting correctly, style, title and image_id all have values. Title changes to '0' regardless of what it actually is but nothing else changes at all. Link to comment Share on other sites More sharing options...
thescientist Posted October 10, 2012 Share Posted October 10, 2012 (edited) Do you know what your query looks like before it gets executed? have you tried the same query via command line or phpMyAdmin? Edited October 10, 2012 by thescientist Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now