0

Hi All! i have her a code

<?php
/**
 * Main.php
 */
include("include/session.php");
//include("viewproj.php");
?>
<html>
<head>
<title>Export to Excel</title>
</head>
<body>
<form action="searchemp.php" method="post" >
<?php
    define ('DB_NAME', 'vincegac_vince');
    define ('DB_USER', 'root');
    define ('DB_PASSWORD', '');
    define ('DB_HOST', 'localhost');
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }

    $db_selected = mysql_select_db(DB_NAME, $link);

    if (!$db_selected) {
        die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
    }
    $UserName = $session->username;
    //$pname = $_POST["projname"];
    //$Proj = $session->proj_name;
    $strSQL = "SELECT * FROM employee WHERE projmgr = '$UserName' AND projname = '"$_POST["projname"]"' "; 
    $rs = mysql_query($strSQL);

?>
<table border="1">

<tr>
    <th>Employee Name</th><th>Home Address</th><th>Email Address</th><th>Office/project number</th><th>Mobile number</th><th>Home number</th>
    <th>Position</th><th>Practice</th>
</tr> 

<?php

    while($row = mysql_fetch_array($rs)) {

?>
<tr>

    <td><?php echo $row['lname'] . ", " . $row['fname']  ?></td><td><?php echo $row['homeadd'] ?></td>
    <td><?php echo $row['emailadd'] ?></td><td><?php echo $row['ofcnum'] ?></td><td><?php echo $row['mobilenum'] ?></td>
    <td><?php echo $row['homenum'] ?></td><td><?php echo $row['position'] ?></td><td><?php echo $row['practice'] ?></td>


</tr>    

    <?php    
    } 
    ?>
    </table>
    <?php mysql_close(); ?>

    <p><a href="main.php"> Home</a> <a href="demo-form.php"> Add Member</a></p>
    <input type="submit" name="search" value="Modify record" />
</form>

</body>
</html>

but i have an error. is says

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\testing\export.php on line 33

its in my sql. Thanks!

4
Contributors
4
Replies
28
Views
4 Years
Discussion Span
Last Post by Eng. Hadi
0

Your problem is syntaxis try adding the grave accent quote to tablenames and column names.

$strSQL = "SELECT * FROM `employee` WHERE `projmgr` = '$UserName' AND `projname` = '"$_POST["projname"]"' "; 

I would also place the $_POST variable in a regular variable to avoid using extra quotes:

$projname=$_POST["projname"];
$strSQL = "SELECT * FROM `employee` WHERE `projmgr` = '$UserName' AND `projname` = '$projname'"; 

Edited by pritaeas: Added markdown.

0

hi tekagami!

i used your code, and it says undefined variable projname. but i have the same name for my textbox. why is that?

0

take this query

$strSQL = "SELECT * FROM employee WHERE projmgr = '".$UserName."' AND projname = '".$_POST["projname"]."' ";

this one should be work

0

The Error is in line 33.
First define a variable $projname = $_POST["projname"];
Then use this variable in your query

$strSQL = "SELECT * FROM employee WHERE projmgr = '$UserName' AND projname = '$projname' ";

That should work properly.
And an other advice to clarify your code so you can read, maintain and change it easily in the future use the HERE document statments you can find more about it http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

It's very useful when you have to embed php code into your html and vise versa (line 37 to 61 could be written in HERE syntax more easily)

Edited by Eng. Hadi

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.