trink Posted August 22, 2007 Share Posted August 22, 2007 Alright, what I've got is this: <?php $postx=$_POST[postx]; $msg=$_POST[msg]; $name=$_POST[name]; $isimg=''; $filename='posts.txt'; if($postx){ if(trim($name)){ if(trim($msg)){ if($_FILES['imgup'] ['tmp_name']){ move_uploaded_file($_FILES['imgup'] ['tmp_name'], "../img/{$_FILES['imgup'] ['name']}"); $isimg='<img class="leftfloat" src="'.$_FILES['imgup'] ['name'].'" />'; } fwrite($fp=fopen($filename, "a"), '<div class="ptitle"><center><b>'.$name.'</b></center></div><div class="post">'.$isimg.$msg.'</div><br>') && fclose($fp); }else{ if($_FILES['imgup'] ['tmp_name']){ move_uploaded_file($_FILES['imgup'] ['tmp_name'], "../img/{$_FILES['imgup'] ['name']}"); $isimg='<img class="leftfloat" src="'.$_FILES['imgup'] ['name'].'" />'; fwrite($fp=fopen($filename, "a"), '<div class="ptitle"><center><b>'.$name.'</b></center></div><div class="post">'.$isimg.$msg.'</div><br>') && fclose($fp); }else{ $message='You must have a message or a file in order to post.'; } }if(!trim($name)){ $message='You must use a name in order to post.'; } } $handle=fopen("posts.txt", "r"); $posts=fread($handle, filesize("posts.txt")); fclose($handle); ?> Basically what it's supposed to do is: If they click the submit button, its supposed to check if they have a name, if they don't, it sets $message as 'you must have a name blah blah'. If they have a name, then it checks if they have a message, if they do have a message then it checks if they have a file, and if they do, it uploads it and sets a variable as a link to it, then writes all the stuff to an external file. If they do not have a message, but they do have an image, then it uploads the image and writes it all to the file. If they do not have a message or an image, then it sets $message as 'you must have a message blah blah'. The problem is, when I open the page, it says that there was an "unexpected $end" found on the last line of the file. OR if I change that }if(!trim($name)){ line to }else{ it says that there is an "unexpected else" on that line. I've looked over this file at least 20 times and found nothing that could be causing the problem, any help would be appreciated. You can find the full document at http://71.97.138.27:1009/doesntwork.txt If the IP changes for some reason, I'll post the change. Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/66088-problem-with-a-script-after-a-form-submit/ Share on other sites More sharing options...
jcanker Posted August 22, 2007 Share Posted August 22, 2007 You're missing a closing bracket to either the 1st or 2nd if statement depending on your intentions. In your editor, write the code so that the brackets line up and you 'll see what I mean: IF(blah) { some stuff here } else { some more stuff here if { more stuff here } else { more stuff here } } Quote Link to comment https://forums.phpfreaks.com/topic/66088-problem-with-a-script-after-a-form-submit/#findComment-330588 Share on other sites More sharing options...
jcanker Posted August 22, 2007 Share Posted August 22, 2007 As a side note, as I've been learning, I've found that it keeps the code cleaner and easier to debug if you use elseif { blah blah } if an else statement is immediately followed by an if statement. You eliminate a set of brackets to track that way. Quote Link to comment https://forums.phpfreaks.com/topic/66088-problem-with-a-script-after-a-form-submit/#findComment-330600 Share on other sites More sharing options...
matthewhaworth Posted August 22, 2007 Share Posted August 22, 2007 Yea, I think the problem definitely lies in your if statement structure Quote Link to comment https://forums.phpfreaks.com/topic/66088-problem-with-a-script-after-a-form-submit/#findComment-330616 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.