无法使用php从html页面获取值

时间:2014-07-23 04:24:37

标签: javascript php html mysqli

这是我的html代码,其中将输入值..

<script type="javascript">
function author_list()
{
<?php
global $con;
$con=mysqli_connect("localhost","root","","project");
if(mysqli_connect_errno())
{
echo "failed to connect".mysqli_connect_errno();
}

//$author=mysqli_query($con,"select * from english where author='".$SBA."' ");
$author=mysqli_query($con,"select * from english where genre='english' ");
echo"<table>";
while($data=mysqli_fetch_array($author))
{
echo"<tr>";
echo"<td>".$data['genre'];
echo"<td>".$data['author'];
echo"<td>".$data['title'];
echo"<td>".$data['year'];
echo"<td>".$data['avail'];
}
echo"</table>";
mysqli_close($con);

?>
}

function go()
{
window.location = "http://localhost/library/author.php";
} 

</script>

<html>
<head>
<title>Library Management System| Feedback</title>
<link rel="stylesheet" href="styles/layout.css" type="text/css" />
</head>
<body id="top">
<div class="wrapper col1">
<div id="header">
<div id="topnav">
<ul>
<li class="last"><a href="#aboutus.html">About Us</a></li>
<li><a href="#">Search Books</a>
<ul>
<li><a href="byauthor.html">Search By Author</a></li>
<li><a href="bytitle.html">Search By Title</a></li>
<li><a href="bygenre.html">Search By Genre</a></li>
</ul>
</li>
<li><a href="full-width.html">Request A Book</a><span>Propose A New Book</span></li>
<li><a href="feedback.html">Feedback</a></li>
<li><a href="index.html">Home</a></li>
</ul>
</div>
<div id="logo">
<h1><a href="index.html">University Library</a></h1>
<p>Chitkara University(H.P)</p>
</div>
<br class="clear" />
</div>
</div>
<div class="wrapper col2">
<div id="breadcrumb">

</div>
</div>
<div class="wrapper col4">
<div id="container">
<h2>Search The book</h2>
<form action="author.php" method=GET>
Search By Author:<input type="text" name="SBA" value=""><br>
<td>                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><input type="submit" value="submit" onclick= "go()">
<td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><input type="reset" value="reset">
</div>
</div>
<div class="wrapper col5">
<div id="footer">

<br class="clear" />
</div>
</div>
<br class="clear" />
</div>
</div>
</div>
</body>
</html>

这是我的php代码,在从数据库中检查后显示值....

<html>
<head>
<title>Library Management System| Feedback</title>
<link rel="stylesheet" href="styles/layout.css" type="text/css" />
</head>
<body id="top">
<div class="wrapper col1">
<div id="header">
<div id="topnav">
<ul>
<li class="last"><a href="#aboutus.html">About Us</a></li>
<li><a href="#">Search Books</a>
<ul>
<li><a href="byauthor.html">Search By Author</a></li>
<li><a href="bytitle.html">Search By Title</a></li>
<li><a href="bygenre.html">Search By Genre</a></li>
</ul>
</li>
<li><a href="full-width.html">Request A Book</a><span>Propose A New Book</span></li>
<li><a href="feedback.html">Feedback</a></li>
<li><a href="index.html">Home</a></li>
</ul>
</div>
<div id="logo">
<h1><a href="index.html">University Library</a></h1>
<p>Chitkara University(H.P)</p>
</div>
<br class="clear" />
</div>
</div>
<div class="wrapper col2">
<div id="breadcrumb">

</div>
</div>
<div class="wrapper col4">
<div id="container">
<h2>Search The book</h2>
<form action = byauthor.php>
<td>
<?php
global $con;
$con=mysqli_connect("localhost","root","","project");
if(mysqli_connect_errno())
{
echo "failed to connect".mysqli_connect_errno();
}

$SBA = $_GET['SBA'];
$author=mysqli_query($con,"select * from english where author='".$SBA."' ");
$author1=mysqli_query($con,"select * from maths where author='".$SBA."' ");

$author3=mysqli_query($con,"select * from science where author='".$SBA."' ");
$author4=mysqli_query($con,"select * from programming where author='".$SBA."' ");

echo"<table>";
while($data=mysqli_fetch_array($author))
{
echo"<tr>";
echo"<td>".$data['genre'];
echo"<td>".$data['author'];
echo"<td>".$data['title'];
echo"<td>".$data['year'];
echo"<td>".$data['avail'];
echo"<td>".'<button>Issue</button>';
}
while($data=mysqli_fetch_array($author1))
{
echo"<tr>";
echo"<td>".$data['genre'];
echo"<td>".$data['author'];
echo"<td>".$data['title'];
echo"<td>".$data['year'];
echo"<td>".$data['avail'];
echo"<td>".'<button>Issue</button>';
}

while($data=mysqli_fetch_array($author3))
{
echo"<tr>";
echo"<td>".$data['genre'];
echo"<td>".$data['author'];
echo"<td>".$data['title'];
echo"<td>".$data['year'];
echo"<td>".$data['avail'];
}
while($data=mysqli_fetch_array($author4))
{
echo"<tr>";
echo"<td>".$data['genre'];
echo"<td>".$data['author'];
echo"<td>".$data['title'];
echo"<td>".$data['year'];
echo"<td>".$data['avail'];
echo"<td>".'<button>Issue</button>';
}
echo"</table>";

mysqli_close($con);

?>
</td>
</body>
</html>

但是打印了这些值,它是直接打印&#34;页面的代码,而循环&#34; ...我是sqli和php的新手...请帮帮我

0 个答案:

没有答案