Viewed   53 times

In my form I have the following values that are based on a standard PHP/MySql query.

echo "<tr>n
        <td align='right'><b>Location</b></td>
        <td><input name='student_location' type='text' size='25' style='font-weight: 700' value=$location></td>

When the value of $location is a single word it displays properly, when it is more than one word say 'North Campus' only 'North' displays.

I've doubled and triple checked and the correct value is in the database, when I do an echo for the value of $location it echoes the correct value but when it's displayed in the field above it chops the last word. It's doing it to all of my variables that are more than one word, so I've missed something obvious.



You forgot quotes :

echo "<tr>n
    <td align='right'><b>Location</b></td>
    <td><input name='student_location' type='text' size='25' style='font-weight: 700' value="$location"></td>

Without quotes, the first word will be noted, others will be interpreted as wrong attributes.

Thursday, October 6, 2022
<form name="add" method="post">
     <select name="age">
        <option value="1_sre">23</option>
        <option value="2_sam">24</option>
        <option value="5_john">25</option>
     <input type="submit" name="submit"/>

You will have the selected value in $_POST['age'], e.g. 1_sre. Then you will be able to split the value and get the 'stud_name'.

$stud = explode("_",$_POST['age']);
$stud_id = $stud[0];
$stud_name = $stud[1];
Tuesday, October 4, 2022

The usual workflow:

  1. Provide a Javascript rich-text editor for your users such as TinyMCE:
  2. Grab the source generated by the RTE and filter it through HTML Purifier before saving to the database.
  3. Escape the existing HTML: <div id="myHtml" style="display: none"><?php echo htmlentities($html); ?></div>
  4. Re-populate the RTE via Javascript - in the case of TinyMCE as follows: tinyMCE.activeEditor.setContent($('#myHtml').html());

You can also load the HTML content via AJAX.

Tuesday, December 27, 2022

The HTML interpreter in the mail program is looking at the input elements and seeing the value attribute followed by a single unquoted word. Then it sees a bunch of other attributes without values. Quote the value properly in the first place. And sanitize too; you don't want your clients being hacked because of an email that was sent from your system.

Thursday, October 27, 2022

If your string is heavy, componentsSeparatedByString() tends to be faster.

Swift 2:

var date = "1,340d 1h 15m 52s"
if let first = date.componentsSeparatedByString(" ").first {
    // Do something with the first component.

Swift 3/4/5:

if let first = date.components(separatedBy: " ").first {
    // Do something with the first component.
Saturday, November 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 :