如何将mysql中的值变成变量

时间:2014-01-13 00:50:14

标签: php mysql

我的代码就是这个

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
require("db.php");


$datetoday = date("Y-m-d");


if (isset($_POST['submit']))
    {      
    include 'db.php';



$loginid =$_REQUEST['loginid'];

$result = mysql_query("SELECT * FROM info WHERE id  = '$loginid'");
$test = mysql_fetch_array($result);
$testid=$test['id'];
$fnameloginsuccess1=$test['firstname'];
$mnameloginsuccess1=$test['middlename'];
$lnameloginsuccess1=$test['lastname'];
$departmentloginsuccess1=$test['department'];
echo'<input type="text" name="fname" value="<?php echo $fnameloginsuccess1 ?>"/></td>';
if (!$loginid)
{header("location:../index.php");   }





    $natureofleave =$_POST['group1'];
    $datestart=$_POST['startofleave'];
    $dateend=$_POST['endofleave'];
    $reason=$_POST['reason'];
    $status= 'pending';
    $fname = $_GET[$fnameloginsuccess1];
    $mname = $test['middlename'];
    $lname = $test['lastname'];
    $dept = $test['department'];




    mysql_query("INSERT INTO `request`(id,natureofleave,dateofleavestart,dateofleaveend,reasons,datesubmitted,department,status,firstname,middlename,lastname)
         VALUES('$log','$natureofleave','$datestart','$dateend','$reason','$datetoday','$dept','$status','$fname','$mname','$lname')");





    }


?>


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>


<body>
<table width="532" height="237" border="1">
  <tr>
    <td width="176"><input type="button" value="Notification" name="notification" />
    <br /><p>logged in as <label>'user'</label><input type ="button" value="Sign Out" name="buttonout" /> </p></td>
  </tr>
  <tr>
    <td width="161"><p><a href="index.php?loginid=<?php echo $loginid; ?>">Home Page</a></p>
    <p><a href="requestleave.php?loginid=<?php echo $loginid ?>">Request for a Leave</a></p>
    <p><a href="leavehistory.php?loginid=<?php echo $loginid ?>">Leave History</a></p>
    <p><a href="leavestatus.php?loginid=<?php echo $loginid ?>">Leave Status</a></p>
    <p><a href="viewprofile.php?loginid=<?php echo $loginid ?>">View Profile</a></p>
    <p><a href="editemployee.php?loginid=<?php echo $loginid ?>">Update/Search Personnel Info</a></p>
    <p><a href="addemployee.php?loginid=<?php echo $loginid ?>">Add Personnel</a></p>
    <p><a href="postannouncement.php?loginid=<?php echo $loginid ?>">Post Announcements</a></p>
    <p><a href="reports.php?loginid=<?php echo $loginid ?>">Reports</a></p>
    <p>&nbsp; </p>
    <p>&nbsp;</p></td>
    <td colspan="2"><p>Application for Leave</p>
      <p><form action='requestleave.php' method='post'>Name:
        <?php  echo $fnameloginsuccess1,' ',$mnameloginsuccess1,' ', $lnameloginsuccess1; ?>
        <label name="name1"></label>
      </p>
    <p>Department:<?php  echo $departmentloginsuccess1; ?>
      <label name="department1"> </label>
  </p>
    <p>Date<?php  echo $datetoday; ?></p>

我无法在MYSQL_QUERY中插入firstname,middlename,lastname,department和ID ..但我可以“回应”它们。我已经尝试将$ departmentloginsuccess1等放在MSQL_QUERY中,但它不起作用。我已经打电话给db了。

我想将它们插入我的数据库。怎么样? helpp !!!

1 个答案:

答案 0 :(得分:0)

mysql_query("INSERT INTO `request`(id,natureofleave,dateofleavestart,dateofleaveend,reasons,datesubmitted,department,status,firstname,middlename,lastname)
         VALUES('$loginid','$natureofleave','$datestart','$dateend','$reason','$datetoday','$dept','$status','$fname','$mname','$lname')");