2

I am trying to print data from dataBASE with SQL and PHP. all worked fine the issue is when I am trying to to warp all thing to function it not working and the table is not showing.

with out the function loadClient it work fine.

please help...

$("#loadbtn").click(function(){
    var s = '                       
    <?php
    loadClients()

    function loadClients(){
        $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'");

        echo '<table id="clienttable" border="1" cellspacing="0" cellpadding="0" width="100%">';
        echo '<tr>';

        echo '<td width="80px">שם פרטי</td>';
        echo '<td>שם משפחה</td>';
        echo '<td>טלפון</td>';
        echo '<td>אימייל</td>';
        echo '<td>עיר</td>';
        echo '<td width="120px">שעת רישום</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>';
    }
?>';
5
  • 4
    I'm sure if you look at the actual HTML/Javascript being generated by your PHP, or even the error console the error won't be too hard to spot. I'd also suggest looking in to AJAX, rather than dumping a massive HTML table as a javascript string variable. Commented Aug 17, 2013 at 13:56
  • 2
    Semicolon is missing off your loadClients() call as well. Commented Aug 17, 2013 at 14:01
  • 1
    Are you sure this word is correct claients in $loadQuery=? Try replacing it with clients - may just be a typo and "part" of the problem. Commented Aug 17, 2013 at 14:03
  • 2
    You should use MySQLi or PDO instead of mysql_* functions, which are deprecated and will be removed in the future versions of PHP. More information avalible here. Commented Aug 17, 2013 at 14:05
  • This code is bound to fail. You're doing a SELECT * and then fetching the result as an array. At least use an associative array... better yet, only select the columns you want. Otherwise, you're going to make a database change some day and everything will come crashing down. What a mess. Also, wrap any variable data used in an HTML context with htmlspecialchars(). That way you can be sure that you're generating valid HTML and not opening yourself up to potential XSS attacks. Commented Aug 17, 2013 at 15:44

1 Answer 1

1

You should use $.ajax() like

Javascript

$("#loadbtn").click(function(){
   $.ajax({
     type: "POST",
     url: 'page.php',
     success: function(d){alert(d);},
   });
});

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'");
echo '<table id="clienttable" border="1" cellspacing="0" cellpadding="0" width="100%">';
 echo '<tr>';

 echo '<td width="80px">שם פרטי</td>';
 echo '<td>שם משפחה</td>';
 echo '<td>טלפון</td>';
 echo '<td>אימייל</td>';
 echo '<td>עיר</td>';
 echo '<td width="120px">שעת רישום</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>';
}
Sign up to request clarification or add additional context in comments.

2 Comments

i see no reason to even use mysql_query
Why not? If the OP needs to show claients whose eventreg_pictures is NULL.

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.