Jump to content

Help with LIKE


unplugged_web

Recommended Posts

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

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 by thehappyappy
Link to comment
Share on other sites

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

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 by thehappyappy
Link to comment
Share on other sites

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

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

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 by thehappyappy
Link to comment
Share on other sites

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

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

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

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

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

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

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

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

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

Do you know what your query looks like before it gets executed? have you tried the same query via command line or phpMyAdmin?

Edited by thescientist
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...