SkyRanger Posted May 23, 2007 Share Posted May 23, 2007 I am having a problem, which I am not sure if is even possible. With this I keep getting a white page: $formhere = if($submit) { mysql insert stuff here }else{ echo "showform"; }; $replyaccess = $rowreply["replies"]; } switch ($replyaccess) { case 0: $allowreplies = ""; break; case 1: $allowreplies = " <table width=\"95%\" cellpadding=\"3\" cellspacing=\"1\" border=\"0\" class=\"bordercolor\"> <tr class=\"titlebg\"> <td align=\"center\" colspan=\"2\" class=\"largetext\">Comments</td> </tr><tr> <td class=\"windowbg\" valign=\"top\" style=\"padding: 7px;\"> <table border=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\"> <tr> <td width=\"100%\" colspan=\"2\">$formhere</td> </tr> </table> </td> </tr> </table>"; break; } echo $allowreplies; If i remove the $formhere it works no problem. Quote Link to comment Share on other sites More sharing options...
trq Posted May 23, 2007 Share Posted May 23, 2007 if does not return a value, your code makes little sense. Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted May 23, 2007 Author Share Posted May 23, 2007 If I remove this: $formhere = if($submit) { mysql insert stuff here } else { echo "showform"; } Everything displays no problem. I can put in $formhere = "Show form"; and works without problem. but I cannot figure out how to do the other. The echo $allowreplies; shows no problem. The 0 is suppose to be empty. Quote Link to comment Share on other sites More sharing options...
trq Posted May 23, 2007 Share Posted May 23, 2007 but I cannot figure out how to do the other. What other? As I said, the code you posted makes little sense. if does not return a value so you can't assign a variable to its return. Explain... in words what it is exactly you are trying to do. Maybe you are looking for the ternary operator. $formhere = $submit ? domysqlstuff() : showform(); Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted May 23, 2007 Author Share Posted May 23, 2007 I am having a problem putting this into the case 1: allowreplies = "postedcodehere"; I am trying to figure out how to put: if($submit) { $sql = "insert into........"; } else { <form method=post action=reply.php> Reply: <input type=text name=reply> <input type=submit name=submit value=Submit> } Not sure if I explained it properly. Quote Link to comment Share on other sites More sharing options...
trq Posted May 23, 2007 Share Posted May 23, 2007 Not sure if I explained it properly. Nope, still not understanding. Maybe you should read the link in my signiture. How to ask.... Quote Link to comment Share on other sites More sharing options...
radar Posted May 23, 2007 Share Posted May 23, 2007 Try it like this.. <?php if (!$submit) { echo "show form" $replyaccess = $rowreply["replies"]; switch ($replyaccess) { case 0: $allowreplies = ""; break; case 1: $allowreplies = ' <table width="95%" cellpadding="3" cellspacing="1" border="0" class="bordercolor"> <tr class="titlebg"> <td align="center" colspan="2" class="largetext">Comments</td> </tr><tr> <td class="windowbg" valign="top" style="padding: 7px;"> <table border="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1"> <tr> <td width="100%" colspan="2">$formhere</td> </tr> </table> </td> </tr> </table>'; break; } echo $allowreplies; } else { // mysql stuff here } ?> see what that does.... Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted May 23, 2007 Author Share Posted May 23, 2007 Ok thorpe, sorry, After reading my own posts I lost myself. Now I see where you are coming from. Going to try this again. User enters page: comments.php The page checks the mysql to see if: $rowreply["replies"]; = 0 or 1 If = 0 then it doesn't echo anything If it = 1 then it echos the html/php and mysql stuff. case 1: $allowreplies = "<table width=\"95%\" cellpadding=\"3\" cellspacing=\"1\" border=\"0\" class=\"bordercolor\"> <tr class=\"titlebg\"> <td align=\"center\" colspan=\"2\" class=\"largetext\">Comments</td> </tr><tr> <td class=\"windowbg\" valign=\"top\" style=\"padding: 7px;\"> <table border=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\"> <tr> <td width=\"100%\" colspan=\"2\">$formhere</td> </tr> </table> </td> </tr> </table>"; break; } What I am trying to do is get the $formhere located in case 1: <tr> <td width=\"100%\" colspan=\"2\">$formhere</td> </tr> to be if($submit) { $sql = "insert into table.......... } else { echo a form here } But everytime I try adding the if($submit) ... I get a white page, when I remove it, everything shows correctly. Hopefully this time I explained this a little better. That page has allot of good info thorpe, thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted May 23, 2007 Share Posted May 23, 2007 Sorry, but your logic still makes little sense. Yove explained it well enough, it just doesn't seem a logical solution. Why do you have the swithc at all if only 1 option is going to do anything. As for this part.... if($submit) { $sql = "insert into table.......... } else { echo a form here } If the form is submitted, you want $formhere to hold what? The response from the db query? eg true / false. Otherwise you want it to hold your form? Sorry, just seems an over complicated approuch to a rather simple problem. Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted May 23, 2007 Author Share Posted May 23, 2007 I am still learning PHP/MySQL, I have picked up allot of time, and not sure if there is an easier way to do this or not. That is why I am using the switch. If the entry is 0 then don't show if 1 then show. This will active when the user clicks on the outer link comment.php?id=124 it will load the comment page and if entry 124 has an replies of 0 then don't show the form but if has a replies of 1 then shows the form. Quote Link to comment Share on other sites More sharing options...
per1os Posted May 23, 2007 Share Posted May 23, 2007 <?php $submit = (isset($_POST['submit']))?true:false; $replyaccess = $rowreply["replies"]; switch ($replyaccess) { case 0: $allowreplies = ""; break; case 1: $allowreplies = ' <table width="95%" cellpadding="3" cellspacing="1" border="0" class="bordercolor"> <tr class="titlebg"> <td align="center" colspan="2" class="largetext">Comments</td> </tr><tr> <td class="windowbg" valign="top" style="padding: 7px;"> <table border="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">'; if ($submit) { // do insert here }else { $allowreplies .= '<tr> <td width="100%" colspan="2">$formhere</td> </tr>'; } $allowreplies .= '</table> </td> </tr> </table>'; break; } echo $allowreplies; ?> Does that work ??? Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted May 23, 2007 Author Share Posted May 23, 2007 Awesome, so far so good frost, thanks. I will mark topic solved as soon as I finish setting the script to let you know that It works perfectly the way I need it. Keeping fingers crossed. Quote Link to comment 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.