Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have an issue with HTML that created with php code

I am trying to create admin panel and get some data from data base to a table and then to be able to change it.

I have 2 forms one called searchForm that is create with HTML code and the form work fine after I am submitting it.

the other form (loadForm) is created dynamically with php code that get data from SQL DB. the PHP work fine and I get the table with all fields, the issue is When I submit specific line I dont get the values by post method. I checked eith var_dump and the result is 0. also I can't change the table css attribute.

please help....

    <?php

    include("config.inc.php");
    $lfname='';
    $llname='';
    $lphone='';
    $lemail='';
    $lcity='';
    $lphotos='';
    $fname='';
    $lname='';
    $phone='';
    $email='';

    if(isset($_POST['searchbtn'])){
        if (isset($_POST['fname'])) {
            $fname=$_POST['fname'];
        }

        if (isset($_POST['lname'])) {
            $lname=$_POST['lname'];
        }

        if (isset($_POST['phone'])) {
            $phone=$_POST['phone'];
        }

        if (isset($_POST['email'])) {
            $email=$_POST['email'];
        }
        var_dump($phone);
    }

    if (isset($_POST['savebtn'])){

        if (isset($_POST['lfname'])) {
            $lfname=$_POST['lfname'];
        }
        if (isset($_POST['llname'])) {
            $llname=$_POST['llname'];
        }
        if (isset($_POST['lphone'])) {
            $lphone=$_POST['lphone'];
        }
        if (isset($_POST['lemail'])) {
            $lemail=$_POST['lemail'];
        }
        if (isset($_POST['lcity'])) {
            $lcity=$_POST['lcity'];
        }
        if (isset($_POST['lphotos'])) {
            $lphotos=$_POST['lphotos'];
        }
        var_dump($lfname);
        }


        ?>
    <html>
        <head>
            <title>תמונה במתנה</title>
            <meta charset="utf-8">
            <link href="admin-style.css" rel="stylesheet" type="text/css">
            <script type="text/javascript" src="jquery.js"></script>

        </head>

        <body>
        <div id="container">
            <div id="customer-list">

            </div>
            <button type="button" id="loadbtn">טען</button>
            <div id="search">
                <form id="searchForm" action="admin.php" method="post">
                    שם פרטי:<input type="text" name="fname" id="fname">שם:
                    שם משפחה:<input type="text" name="lname" id="lname">
                    טלפון:<input type="text" name="phone" id="phone">
                    אימייל:<input type="text" name="email" id="email">
                    <input id="searchForm" type="submit" name="searchbtn" value="חפש" />
                </form>

            </div>
            <div id="serchList">

            </div>
            <div id="editCustomer">

            </div>
        </div>
                <script type="text/javascript">

                    $(document).ready(function() {  

                    showNoPicture();
                    alerta();



                    function showNoPicture() {


                         $("#loadbtn").click(function(){
                            var s = '                       <?php
    $link = mysql_connect($db_host,$db_user,$db_pass);
    if(!$link) die ('Could not connect to database: '.mysql_error());
    mysql_select_db($db_name,$link);
    mysql_query("SET NAMES 'utf8'");
        $i=0;
                        echo '<table border=1 cellspacing="0" cellpadding="0">';
                        echo '<tr>';

                        echo '<td>שם פרטי</td>';
                        echo '<td>שם משפחה</td>';
                        echo '<td>טלפון</td>';
                        echo '<td>אימייל</td>';
                        echo '<td>עיר</td>';
                        echo '<td>שעת רישום</td>';
                        echo '<td>מספרי תמונות</td>';
                        echo '<td>שמור</td>';
                        echo '</tr>';

                        $loadQuery="SELECT * FROM `claients` WHERE `eventreg_pictures` is null";
                        $result=mysql_query($loadQuery);
                        while($row= mysql_fetch_array($result)){
                            $client= $row;
                            $clients[]=$client;

                            echo '<tr>';
                            echo '<form id="loadForm" method="post" action="admin.php">'; 

                            echo '<td><input type="text" id="lfname" name="lfname" value="'.$client[1].'"/></td>';
                            echo '<td><input type="text" id="llname" name="llname" value="'.$client[2].'"/></td>';
                            echo '<td><input type="text" id="lphone" name="lphone" value="'.$client[3].'"/></td>';
                            echo '<td><input type="text" id="lemail" name="lemail" value="'.$client[4].'"/></td>';
                            echo '<td><input type="text" id="lcity" name="lcity" value="'.$client[5].'"/></td>';
                            echo '<td>'.$client[7].' ';
                            echo '<td><input type="text" id="lphotos" name="lphotos"/></td>';
                            echo '<td><input type="submit" id="savebtn" name=savebtn" value-"שמור"/></td>';
                            echo '</form>';
                            echo '</tr>';

                            }
                        echo '</table>';

                    ?>';
                            $("#customer-list").html(s);
                            //$("#customer-list").load('loadClient.php');
                            }); 

                    };



                    function alerta() {

                        $("#searchForm").click(function(){
                        s='<?php $searchEmail; ?>';
                        $("#customer-list").html(s);
                            }); 

                    };

        $(".btnClass").click(function(){
            alert('hi');
        //$("#customer-list").load('ghfgh.php');
        });         

    });
            </script>

        </body>
    </html>
like image 974
cfircoo Avatar asked Dec 12 '25 18:12

cfircoo


2 Answers

Fix the errors in the html code:

Missing " here:

echo '<td><input type="submit" id="savebtn" name=savebtn" value-"שמור"/></td>';

should be

echo '<td><input type="submit" id="savebtn" name="savebtn" value="שמור"/></td>';

You have duplicate id's, searchForm is used twice.

like image 110
Roland Jansen Avatar answered Dec 15 '25 10:12

Roland Jansen


This might be your problem:

   while($row= mysql_fetch_array($result)){
        $client= $row;
       $clients[]=$client;

       echo '<tr>';
      echo '<form id="loadForm" method="post" action="admin.php">'; 

Get the form tag outside of the while loop. You might be creating multiple forms with the same id. You also repeat a lot of the ids.

like image 41
Hanlet Escaño Avatar answered Dec 15 '25 09:12

Hanlet Escaño



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!