Jump to content

colour in aray


runnerjp

Recommended Posts

The code you just posted doesn't make any sense. You would have to explain what your trying to do.

 

 

To make your code make sense, it would need to be something like this

if (some condition) {
   echo 'her';
} else if(isset($_POST["basic"])) {
   //code here
}

Link to comment
Share on other sites

so would this be correct

 

if (function show_form()) {

  echo 'her';

} else if(isset($_POST["basic"])) {

    check_form();

 

I don't know what your function show_form() looks like, but if it returns a value of TRUE or FALSE, then you can do this:

 

if (show_form()) {
   echo 'her';
} else if(isset($_POST["basic"])) {
    check_form();
}

 

I can only tell you if the syntax is correct, other than that...I have no idea what your trying to accomplish.

Link to comment
Share on other sites

note: stuff inside opening and closing curly brackets is called a 'block' of code. there can't be an opening curly bracket without a closing one

{ // opening curly bracket
   // here would be a block of code.

} // MUST ALWAYS have a closing curly bracket.

Link to comment
Share on other sites

humm thats not wrokign lol ok if i show you my code it might help

 

<? function error_bool($error, $field) {
         if($error[$field]) {
             print("<td style=color:red>");
         }
        else {
            print("<td>");
        }
    }

function show_form() {
global $HTTP_POST_VARS, $print_again, $error;
?>
<form id="FormName" action='<?php "$_SERVER[php_SELF]" ?>' method="post" name="basic">
<table width="440" border="0" align="center" cellpadding="0" cellspacing="2">
<tr><td colspan="3"> </td>
</tr>
<tr>
  <td><div align="right">
    <label for="dob">First name</label>
  </div></td>
  <td colspan="2"><input class="inputedit" id="first_name" name="first_name" type="text" size="25" value="" maxlength="255" /></td>
</tr>
<tr>
  <td width="150"><div align="right">
<label for="dob"></label>
  </div></td>
  </tr><tr><td colspan="2"> </td>
</tr>
<tr>
  <td width="150"><div align="right">
<label for="last_name">Club</label>
  </div></td>
  <td colspan="2"><p>
        <label for="birthday"></label>
        <?php $lines = file('runningclubs.txt');
echo '<select class="inputedit" id="club" name="club">';
foreach($lines as $line) {
    echo '<option>'.$line.'</option>';
}
echo '</select>';?>
     
        
    </p></td>
</tr>
<tr>
  <td width="150" align="right">status</td>
  <td colspan="2"><?
}
if(isset($_POST["basic"])) {
    check_form();
} else {
    show_form();
}

function check_form()
{
global $HTTP_POST_VARS, $error, $print_again;
$error['error'] = false;
if (($_POST["first_name"] == "") || (!preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $_POST["first_name"])))
{
    $error['first_name'] = true;
    $print_again = true;
    $message = "The first name field is either empty or incorrect data was input.<br>";
}

if (($_POST["last_name"] == "") || (!preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $_POST["first_name"]))) {
        $error['last_name'] = true;
         $print_again = true;
        $message="The last name field is either empty or incorrect data was input.<br>";
    }
  if($_POST["club"]=="") {
        $error['club'] = true;
         $print_again = true;
        $message="Please select a club<br>";
    }
  if($_POST["birthyear"]=="-DAY-") {
        $error['birthyear'] = true;
         $print_again = true;
        $message="Please select a dob<br>";
    }
  if($_POST["birthmonth"]=="-MONTH-") {
        $error['birthmonth'] = true;
         $print_again = true;
        $message="Please select a dob<br>";
    }
  if($_POST["birthday"]=="-YEAR-") {
        $error['birthday'] = true;
         $print_again = true;
        $message="Please select a dob<br>";
    }
     if($print_again) {
         show_form();
       
       } else {
        show_form();
          $message="<span class='style1'>Your profile has been created</span>";
	   $id =  mysql_real_escape_string( $_POST['id']);

$club = mysql_real_escape_string( $_POST['club']);
$first_name = mysql_real_escape_string( $_POST['first_name']);
$last_name =  mysql_real_escape_string( $_POST['last_name']);
$gender =  mysql_real_escape_string( $_POST['gender']);
$birthyear =  mysql_real_escape_string( $_POST['birthyear']);
$birthmonth =  mysql_real_escape_string( $_POST['birthmonth']);
$birthday =  mysql_real_escape_string( $_POST['birthday']);
$dob = $birthday.'-'.$birthmonth.'-'.$birthyear;






$update = "UPDATE users SET new_user='1',dob='$dob', club= '$club', first_name = '$first_name', gender = '$gender', last_name = '$last_name' WHERE id='$id' ";
$result = mysql_query($update);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
    $er  = 'Invalid query: ' . mysql_error() . "\n";
    $er .= 'Whole query: ' . $query;
    die($er);
       }}
  echo '			<p class="error">' . $message . '</p>' . "\n";
}

?>

 

so basicly where it says  echo ' <p class="error">' . $message . '</p>' . "\n"; i would like it to say please fill in the form, if a user has not yet submitted the form

Link to comment
Share on other sites

It's because you are using double quotes within double quotes.

 

Do this

$message="<span class='style1'>Your profile has been created</span>";

 

You could also just put a back slash infront of the double quotes. I think it's called escaping. ???

eg.

$message="<span class=\"style1\">Your profile has been created</span>";

 

Link to comment
Share on other sites

First off, before anything, you should stop using

 

<?

 

and start using

 

<?php

 

if not only because it will make your code easier to read when you post it on this site, which means you are likely to get help sooner. But you should also do it because the use of short tags ('<?') will not work on some servers, and on other servers the server admin may change it unexpectedly. It's sloppy scripting that can cause problems.

Link to comment
Share on other sites

sorry here you go

 

<?php function error_bool($error, $field) {
         if($error[$field]) {
             print("<td style=color:red>");
         }
        else {
            print("<td>");
        }
    }

function show_form() {
global $HTTP_POST_VARS, $print_again, $error;
?>
<form id="FormName" action='<?php "$_SERVER[php_SELF]" ?>' method="post" name="basic">
<table width="440" border="0" align="center" cellpadding="0" cellspacing="2">
<tr><td colspan="3"> </td>
</tr>
<tr>
  <td><div align="right">
    <label for="dob">First name</label>
  </div></td>
  <td colspan="2"><input class="inputedit" id="first_name" name="first_name" type="text" size="25" value="" maxlength="255" /></td>
</tr>
<tr>
  <td width="150"><div align="right">
<label for="dob"></label>
  </div></td>
  </tr><tr><td colspan="2"> </td>
</tr>
<tr>
  <td width="150"><div align="right">
<label for="last_name">Club</label>
  </div></td>
  <td colspan="2"><p>
        <label for="birthday"></label>
        <?php $lines = file('runningclubs.txt');
echo '<select class="inputedit" id="club" name="club">';
foreach($lines as $line) {
    echo '<option>'.$line.'</option>';
}
echo '</select>';?>
     
        
    </p></td>
</tr>
<tr>
  <td width="150" align="right">status</td>
  <td colspan="2"><?php
}
if(isset($_POST["basic"])) {
    check_form();
} else {
    show_form();
}

function check_form()
{
global $HTTP_POST_VARS, $error, $print_again;
$error['error'] = false;
if (($_POST["first_name"] == "") || (!preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $_POST["first_name"])))
{
    $error['first_name'] = true;
    $print_again = true;
    $message = "The first name field is either empty or incorrect data was input.<br>";
}

if (($_POST["last_name"] == "") || (!preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $_POST["first_name"]))) {
        $error['last_name'] = true;
         $print_again = true;
        $message="The last name field is either empty or incorrect data was input.<br>";
    }
  if($_POST["club"]=="") {
        $error['club'] = true;
         $print_again = true;
        $message="Please select a club<br>";
    }
  if($_POST["birthyear"]=="-DAY-") {
        $error['birthyear'] = true;
         $print_again = true;
        $message="Please select a dob<br>";
    }
  if($_POST["birthmonth"]=="-MONTH-") {
        $error['birthmonth'] = true;
         $print_again = true;
        $message="Please select a dob<br>";
    }
  if($_POST["birthday"]=="-YEAR-") {
        $error['birthday'] = true;
         $print_again = true;
        $message="Please select a dob<br>";
    }
     if($print_again) {
         show_form();
       
       } else {
        show_form();
          $message="<span class='style1'>Your profile has been created</span>";
	   $id =  mysql_real_escape_string( $_POST['id']);

$club = mysql_real_escape_string( $_POST['club']);
$first_name = mysql_real_escape_string( $_POST['first_name']);
$last_name =  mysql_real_escape_string( $_POST['last_name']);
$gender =  mysql_real_escape_string( $_POST['gender']);
$birthyear =  mysql_real_escape_string( $_POST['birthyear']);
$birthmonth =  mysql_real_escape_string( $_POST['birthmonth']);
$birthday =  mysql_real_escape_string( $_POST['birthday']);
$dob = $birthday.'-'.$birthmonth.'-'.$birthyear;






$update = "UPDATE users SET new_user='1',dob='$dob', club= '$club', first_name = '$first_name', gender = '$gender', last_name = '$last_name' WHERE id='$id' ";
$result = mysql_query($update);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
    $er  = 'Invalid query: ' . mysql_error() . "\n";
    $er .= 'Whole query: ' . $query;
    die($er);
       }}
  echo '			<p class="error">' . $message . '</p>' . "\n";
}

?>

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.