skip to Main Content

I’am styling my webpage and in my function.php file I have written some code which I wanna access from the elementor html code button.

<td width='25%'><input type='text' id='uptname' name='uptname' value=<?php echo $name ?></td>

the value is not printed. normally the value from my database is supposed to be displayed. Thats my part in the functions.php file.

if (isset($_GET['upt'])) {
    $upt_id = $_GET['up'];
    $result = $wpdb->get_results("SELECT * FROM gemeinde WHERE id='$upt_id'");
    foreach($result as $print) {
        $name = $print->name;
    }
}

either the id field or the gemeinde field is supposed to show the results from my database.
enter image description here
enter image description here

2

Answers


  1. You should try: <td width='25%'><input type='text' id='uptname' name='uptname' value='<?php echo $name ?>'></td>

    You just forgot to put quotes around <?php ... ?> and close correctly the <td> node.

    Login or Signup to reply.
  2. Change

    if (isset($_GET['upt'])) {
      $upt_id = $_GET['up'];
      $result = $wpdb->get_results("SELECT * FROM gemeinde WHERE id='$upt_id'");
        foreach($result as $print) {
          $name = $print->name;
        }
    }
    

    To

    if (isset($_GET['upt'])) {
      $upt_id = $_GET['upt']; //up changed by upt
      $result = $wpdb->get_results("SELECT * FROM $wpdb->gemeinde WHERE id='$upt_id'");
       foreach($result as $print) {
          $name = $print->name;
       }
    }
    

    And

    Change

    <td width='25%'><input type='text' id='uptname' name='uptname' value=<?php echo $name ?></td>
    

    To

    <td width='25%'><input type='text' id='uptname' name='uptname' value='<?php echo $name ?>'></td> // See for input tag close and  quotes around value
    

    ** The attribute value can remain unquoted if it doesn’t contain spaces or any of " or ‘ . Otherwise, it has to be quoted using either single or double quotes. The value, along with the = character, can be omitted altogether if the value is the empty string.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search