Page 1 of 1

mental constipation - trying to work in a conditional stmt

Posted: Tue Oct 22, 2002 2:51 pm
by DiamondLil
Hi all. I'm stuck.

I need users(retailers) to only be able to sign up for a position if there is not a user(retailers) detail already in the adjacent slot. They sign up by clicking on the slot name (platinum, gold, silver, etc.) That link when clicked tells a switch on index.php that it's a case of "update" (which is defined on the index.php), gives user a page to input data (edit.php), and updates the record as specified in update.php. I've tried to prevent the update of the record by using an if my $retailer is not null statement to tell it not to update unless there is no value yet. I've tried putting the conditional in the index.php, here:

Code: Select all

case "update":
require("update.php"); // update the db where rid=$rid
header("Location: index.php"); // go to listing
break;
default:
that broke it. tried here in update.php:

Code: Select all

<?
mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name);
$sql = "UPDATE $db_table SET retailer='".$HTTP_POST_VARSї'retailer']."' WHERE rid=".$HTTP_POST_VARSї'rid'];
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
?>
but then it zeroed other values in that row, and gave me 'headers already sent from the index.php' error.

The only other place I can think of putting it is the list page:

Code: Select all

<?php
mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name);
$result = mysql_query("select * from $db_table");
while($r=mysql_fetch_array($result))
{
?>
<tr>
<td><?php print $rї'rid']; ?></td>
<td><?php print $rї'week']; ?></td>
<td><?php print $rї'week_ending']; ?></td>
<td><?php print $rї'theme']; ?></td>
<td><a href="index.php?todo=edit&editrid=<?php print $rї'rid']; ?>"><?php print $rї'avail_slot']; ?></td>
<td><?php print $rї'retailer']; ?></td>
</tr>
<?php
}
?>
But how? Is this the right place and is this even the right way to do this?
here's a link in case I was too roundabout or otherwise unclear:
http://www.mc2ads.com/liltestretail/ret ... /index.php

Ultimately - I would like to disable the link if someone has already signed up.

try this

Posted: Tue Oct 22, 2002 3:28 pm
by phpScott
I haven't seen synatx like yours before so I hope I got it right. If not you get the jest of what I am doing.
Put an if else statement like I did 'bolded' to test if a retailer exists for that spot. If not then use your href else print the slot name(platinum, gold etc.) with out the hreg and display the retailers name like you have.


while($r=mysql_fetch_array($result))
{

<tr>
<td><?php print $r['rid']; </td>
<td><?php print $r['week']; </td>
<td><?php print $r['week_ending']; </td>
<td><?php print $r['theme']; </td>
<?php if($r['retailer'] != "")
{
<td><a href="index.php?todo=edit&editrid=<?php print $r['rid']; "><?php print $r['avail_slot']; </td>
}
<?php else
{
<td><?php print $r['rid']; </td>
}

<td><?php print $r['retailer']; </td>
</tr>
<?php

phpScott

Posted: Tue Oct 22, 2002 4:00 pm
by DiamondLil
arrggggg...
thanks for the reply phpscott. I'm trying here...but I'm getting parse errors. I've got so many open / close php tags that I don't know which way is up and what is correct 'syntastically'...

I'm even tring to take advantage of the color coding I get here in this forum when I post code with the php tags around it, but it's still indicating that I have my else statement outside of the tags!

Posted: Tue Oct 22, 2002 4:51 pm
by Heavy
If you're using windows, try this:

http://www.phpedit.org/

If you're using Linux, you might just like Quanta for KDE.

Then you'll get syntax hi-liting. :)

By the way, it might be a bad idea to jump <? in and ?> out of PHP that frequent. I don't really KNOW, but I guess the PHP-parser changes mode in some slow way when you alternate "echoes" with raw html like that.

You do know that PHP supports multiple line string span, don't you?

Regards

try this

Posted: Tue Oct 22, 2002 5:14 pm
by phpScott
try this. I color coded it on my IDE so it should be alright just put inside of your <?php ?> tags;

Code: Select all

&lt;?php
 while($r=mysql_fetch_array($result))
{
$table="&lt;tr&gt;&lt;td&gt;".$r&#1111;'rid']." &lt;/td&gt;";
$table.="&lt;td&gt;".$r&#1111;'week']."&lt;/td&gt;";
$table.="&lt;td&gt;".$r&#1111;'week_ending']."&lt;/td&gt;";
$table.="&lt;td&gt;".$r&#1111;'theme']." &lt;/td&gt;";
if($r&#1111;'retailer'] != "")
{
$table.="&lt;td&gt;&lt;a href='index.php?todo=edit&amp;editrid=".$r&#1111;'rid']."&gt;".$r&#1111;'avail_slot']." &lt;/td&gt;";
}
else
{
$table.="&lt;td&gt;".$r&#1111;'rid']." &lt;/td&gt;";
}
$table.="&lt;td&gt;".$r&#1111;'retailer']."&lt;/td&gt;&lt;/tr&gt;";
echo $table;

?&gt;
There might be a couple of parse errors still with the & but give this a try.

phpScott

Posted: Wed Oct 23, 2002 3:50 pm
by DiamondLil
hi.
yep, getting a parse error that won't go away. added a period, deleted some invisible spaces, but nothing, still there..?

..let me go through it again...

Posted: Wed Oct 23, 2002 4:50 pm
by mydimension
what parse errors are you getting? we might be able to help you find them. :)