Results 1 to 8 of 8
Thread: color change on php coding
-
02-25-2004, 02:55 PM #1webtechGuest
color change on php coding
i'm trying to change the color code but it doesn't work. can you pls check following code.
<?
if ($submit) {
else if($name == False)
{
$error = "You must enter all fields";
}
else if($email == False)
{
$error = "You must enter all fields";
}
else
{
$k=false;
//store
$result = mysql_query($sql_query);
while ($row = mysql_fetch_row($result))
{
if ($row[1] == $name)
{
echo "<br>This name is already EXISTS.<br><br>";
$k=True;
}
}
if (!$k)
{
$sql_query1 = "INSERT into company (Name, Email) VALUES('$name', '$email')";
$result1 = mysql_query($sql_query1);
}
echo "Thank You!";
}
}
if (!$submit || $error) {
echo $error;
?>
<form action="<?php echo $PHP_SELF ?>" method="post" name="form1">
<table width="100%" border="0" cellpadding="0" cellspacing="1" align="center" class="tborder">
<tr>
<td> Please fill in the form below.<br><br>
</td>
</tr>
<tr align="center">
<td class="alt2" width="200"><div align=right><b><font <? if ($error){echo "color=#ff0000";} ?>>*Name </font></b></div></td>
<td class="alt2"><div align=left><input type=text name=name value="<?php echo $name ?>" class=bginput size=50>
</div></td>
</tr>
<tr align="center">
<td class="alt2" width="200"><div align=right><b><font <? if ($error){echo "color=#ff0000";} ?>>*email
</font></b></div></td>
<td class="alt2"><div align=left><input type=text name=email value="<?php echo $email ?>" class=bginput size=50>
</div></td>
</tr>
<table>
</form>
-
02-25-2004, 03:29 PM #2
- Join Date
- Jan 2004
- Posts
- 3,363
May I just ask what does not work?
The color not change?
-
02-26-2004, 01:55 PM #3webtechGuest
Originally Posted by Tris
-
02-26-2004, 03:54 PM #4LippyGuest
Personally I would do an iff statement. two copies of the code in that file, one has the red text the other has black text. Just easier and in my opinion.
-
02-26-2004, 04:14 PM #5
- Join Date
- Jan 2004
- Posts
- 3,363
I changed the code a bit
first i used empty() instead of false (Just personal preference there).
Secondly and this is where you get the error you do
if ( !$submit || $error ) {
echo $error;
and dont close it. I also changed the if($error) to if(isset($error)). Again personal preference. Also neatened it a bit also. This should work. if not please just tell me. Ill fix it.
Code:<?php if ( $submit ) { else if ( empty($name) ) { $error = "You must enter all fields"; } else if ( empty($email) ) { $error = "You must enter all fields"; } else { $k = false; // store $result = mysql_query( $sql_query ); while ( $row = mysql_fetch_row( $result ) ) { if ( $row[1] == $name ) { echo "<br>This name is already EXISTS.<br><br>"; $k = true; } } if ( !$k ) { $sql_query1 = "INSERT into company (Name, Email) VALUES('$name', '$email')"; $result1 = mysql_query( $sql_query1 ); } echo "Thank You!"; } } if ( !$submit || $error ) { echo $error; } ?> <form action="<?php echo $PHP_SELF ?>" method="post" name="form1"> <table width="100%" border="0" cellpadding="0" cellspacing="1" align="center" class="tborder"> <tr> <td> Please fill in the form below.<br><br> </td> </tr> <tr align="center"> <td class="alt2" width="200"><div align=right><b><font <?php if ( isset($error) ) { echo "color=#ff0000"; } ?>>*Name </font></b></div></td> <td class="alt2"><div align=left><input type=text name=name value="<?php echo $name ?>" class=bginput size=50> </div></td> </tr> <tr align="center"> <td class="alt2" width="200"><div align=right><b><font <?php if ( isset($error) ) { echo "color=#ff0000"; } ?>>*email </font></b></div></td> <td class="alt2"><div align=left><input type=text name=email value="<?php echo $email ?>" class=bginput size=50> </div></td> </tr> <table> </form>
-
02-28-2004, 05:31 PM #6
- Join Date
- Jan 2004
- Posts
- 3,363
Just want to make sure?
Does it work now?
-
03-02-2004, 11:26 AM #7michalGuest
Originally Posted by Tris
-
03-02-2004, 03:36 PM #8
- Join Date
- Jan 2004
- Posts
- 3,363
I just used isset. I prefer it. Its easier to understand when I read over it and it also complies with my coding standards
Bookmarks