Send variable between two php files

1

Good morning

I have a page where I show a sql table. And I want if the user clicks on a title it shows only the information of a row.

I am trying to do so, news.php:

<form action="new.php" method="post">
                            <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
                            <h1><a type="submit" href="new.php">
                        <?php 
                            echo $row['name']; 
                        ?>
                            </a></h1>
                        </form>

And in new.php I receive the information:

$variable1=($_POST['id']);

Give this error:

Undefined index: id

He does not recognize it and I do not know why. Thanks

All the php code to see it better. news.php:

<?php
            include ('cfgdb.php');
            reset($db);
            try {
                $i=0;
                foreach($db->query("SELECT 'id','name','description','autor', 'fecha', 'imgRuta','imgNom','show1', url FROM 'noticias'") as $row) {
                   //print_r($row);
                    if ($row['show1']){
                            //echo '<div class="curso '.$colors[rand(0,9)].'">';
                        ?>
                        <article class="blog wow fadeInUp">
                        <figure>
                        <?php
                        //}
                        //echo '<div class="row">';
                        echo '<img src="'.$row['imgRuta'].'" width="727" height="485"  alt="'.$row['name'].'">';
                        ?>
                        </figure>
                        <header>
                        <form action="new.php" method="post">
                            <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
                            <h1><a type="submit" href="new.php">
                        <?php 
                            echo $row['name']; 
                        ?>
                            </a></h1>
                        </form>

                        <div class ="info">
                        <span><i class="fa fa-user"></i><a>
                        <?php 
                            echo $row['autor']; 
                        ?>
                        </a></span>
                        <span><i class="fa fa-calendar"></i>
                        <?php 
                            $date = date_create($row['fecha']);                                
                            echo date_format($date,'Y-m-d');
                        ?>
                        </span>
                        </div>
                        </header>
                        <p>
                            <?php 
                                echo '<p>'.$row['description'].'</p>'; 
                            ?>
                        </p>
                        </article>
                        <span class="line"></span>
                        <?php 
                        /*echo '<a data-remodal-target="'.$row['url'].'" class="btn btn-infoo" href="#'.$row['url'].'">';
                        echo '<i class="fa fa-info"></i> Más Info</a>';
                        echo '<div class="remodal" data-remodal-id="'.$row['url'].'">';
                        echo '<h1>'.$row['name'].'</h1>';
                        echo $row['description'];
                        //echo '<br>&nbsp;<br>'.$row['description_hours'];
                        //echo '<b><br>Fecha de Comienzo: '.$row["DATE_FORMAT('date_init',GET_FORMAT(DATE,'EUR'))"];
                        //echo '<br>Fecha de Fin: '.$row["DATE_FORMAT('date_end',GET_FORMAT(DATE,'EUR'))"];
                        echo '<br/>&nbsp;<br><a class="remodal-confirm" href="#">Ok!</a></div></div>';*/
                    }
                }
                $db = null;

            } catch (PDOException $e) {
                print "Error!: " . $e->getMessage() . "<br/>";
                die();
            }
        ?>
    
asked by CMorillo 31.08.2017 в 13:46
source

1 answer

2

You are using a link (allemento a ) as if it were a buton submit and this is not possible because when you click on the link you will only be redirected to the url but will not send the form information:

Change:

   <a type="submit" href="new.php"> <?php  echo $row['name'];  ?> </a>

By

<input type="submit" value="<?php  echo $row['name'];  ?>" /> 
    
answered by 31.08.2017 / 14:15
source