Viewed   111 times

How do I change the color of an echo message and center the message in the PHP I've written. The line I have is:

echo 'Request has been sent. Please wait for my reply!';



How about writing out some HTML tags and some CSS if you're outputting this to the browser?

echo '<span style="color:#AFA;text-align:center;">Request has been sent. Please wait for my reply!</span>';

Won't work from console though, only through browser.

Tuesday, September 13, 2022

You can style it by the following way:

echo "<p style='color:red;'>" . $ip['cityName'] . "</p>";
echo "<p style='color:red;'>" . $ip['countryName'] . "</p>";
Wednesday, November 23, 2022

Form basics 101:

<form action='the_new_page.php' method='POST'>
  <input type='text' name='first_thing'>
  <input type='hidden' name='some_hidden_guy' value='1'>
  <input type='submit' name='submit_button' value='submit'>

When a user submits the above form, the browser will direct them to the_new_page.php, and the_new_page.php will know all of the form information.

Forms pass the name and the value, nothing else for as what you need to know. id is PURELY for html purposes, and as a rule in HTML, you are not allowed to have more than one element with the same ID. People usually confusingly name the id of the form field the same as the "name" of the form field, which makes learning what each means pretty difficult.

Thus, after submitting the form it will then go to your second page and then you can do:

//You can then do
echo $_POST['some_hidden_guy'] //will be 1
echo $_POST['first_thing'] //Will be whatever you inserted into the text box

If you want the form to go back to the current page you're on, you simply leave the action blank, either as <form action=''> or <form method='POST'>

Persisting the same information for multiple pages!

Now, this is a very not programmer way to do this, as you should find a way to not have to repeat the same code on ever page. If you do not, and I'm warning you now.. maintenance of this app will become a nightmare as you'll have to edit every single page every single time you want to add a new field. On to the example.

Now, say you passed information to car.php and you now want to use it on carplan.php.

    <form action='carplan.php' method='GET or POST, whichever it is you be using using'>
        <input type='hidden' name='Date' value='<?php echo $_GET['date'] ?>'>
        <input type='hidden' name='some_other_thing' value='<?php echo $_GET['some_other_thing'] ?>'>
        <option name='plan_id'>
            <?php foreach($plans as $plan): ?>
                <select value='<?php echo $plan['id'] ?>'><?php echo $plan['name'] ?>'>
            <?php endforeach; ?>
        <input type='submit' name='submit' value='Get That Plan'>

And finally on carplan.php

    <form action='the_next_step.php' method='GET or POST, whichever you be using'>
        <input type='hidden' name='Date' value='<?php echo $_GET['date'] ?>'>
        <input type='hidden' name='some_other_thing' value='<?php echo $_GET['some_other_thing'] ?>'>
        <input type='hidden' name='plan_id' value='<?php echo $_GET['plan_id']?>'>
        <input type='submit' name='submit' value='The next step!'>
Tuesday, September 13, 2022

Escape with a backslash, use "." for concatenation.

$row = array();
$row['ID'] = 1;

echo '<tr onclick="DoNav('list.php?id=' . $row['ID']. '');">';


<tr onclick="DoNav('list.php?id=1');">

Also make sure to escape any content you're going to use in Javascript or HTML. For an ID, you might just cast as an integer:

echo '<tr onclick="DoNav('list.php?id=' . (int)$row['ID']. '');">';

Strings'll be more important to escape.

Tuesday, September 27, 2022

Your code should look like this


            $query = "SELECT * FROM profilestemp"; 

            $result = mysql_query($query) or die(mysql_error());

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

            $merkenarray = unserialize($row[merken]);



            <td style="width:150px;background-color:#a8c11f;padding:2px;"><p style="color:White;font-weight:bold"><b>Merken</b></p></td>
            <td><div id="rubrieken">


            $sql = "SELECT merknaam FROM merken";
            $result = mysql_query($sql);

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

                if (isset($merkenarray) && is_array($merkenarray) && in_array($row2[merknaam], $merkenarray)) {

                  $checked = "checked='checked'";

                else $checked = "";

                echo "&nbsp;&nbsp;<input ".$checked."  type="checkbox" name="merken[]" value='" . $row2[merknaam] . "'>&nbsp;" . $row2[merknaam] . " <Br />  ";




<?php }?>
Wednesday, October 19, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :