3

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>
4
  • If you don't get your $_POST values then there's likely something wrong with your HTML form. Please post your HTML code. Commented Aug 16, 2013 at 19:35
  • 1
    @user1477388 the HTML is all mixed up together in the code posted above Commented Aug 16, 2013 at 19:36
  • Sorry I missed that. So, does it work when you remove the if statements ? i.e. remove if (isset($_POST['savebtn'])){ Edit: Looks like you've got some good answers below... Commented Aug 16, 2013 at 19:39
  • Be sure to use htmlspecialchars() around any variable data you are using in an HTML context. This ensures you are creating valid HTML, and helps mitigate the risk of XSS attacks. Commented Aug 17, 2013 at 2:30

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.