Jump to content

[SOLVED] Case Problem


SkyRanger

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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 ???

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.