我有两个不同的php文件,每个文件都有一个表单。表格
在我的sql数据库中更新不同的东西。每个文件中的代码是
当我一次运行一个时工作完美,但当我打开它时
在index.php文件中单独的div我只能从下面提交
一页在页面上。当我点击上面的提交它改变了
在地址栏中的地址类似于
localhost/~******/fisk/?select=&select=&name=asdfa&weigth=23&info=adfa&add2=L�gg+till+art
而不是运行PHP代码我不会运行?
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" /><!--Viktors CSS -->
<script type="text/javascript">
</script>
</head>
<body>
<div id="species">
<?php include('main.php'); ?>
</div>
<div id="catch">
<?php include('main2.php'); ?>
</div>
<br><br>
<div id="2">
<?php include('insert.php'); ?>
</div>
<br><br>
<div id="3">
<?php include('insert_catch.php'); ?>
</div>
</body>
<html>
<head>
<title>Add New Record in MySQL Database</title>
<script type="text/javascript">
</script>
</head>
<body>
<?php
if(isset($_POST['add2']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('fishing');
if(! get_magic_quotes_gpc() )
{
$fish_name = addslashes ($_POST['name']);
$fish_ideal_weigth = addslashes ($_POST['weigth']);
$fish_info = addslashes ($_POST['info']);
}
else
{
$fish_name = $_POST['name'];
$fish_ideal_weigth = $_POST['weigth'];
$fish_info = $_POST['info'];
}
$sql = "INSERT INTO species (name,ideal_weigth,info) VALUES('$fish_name','$fish_ideal_weigth','$fish_info')";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
$message = 'Sucsess!';
echo "<SCRIPT>
alert('$message');
</SCRIPT>";
mysql_close($conn);
}
else
{
?>
<form method="post" action="">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Art:</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td width="100">Idealvikt:</td>
<td><input name="weigth" type="text" id="weigth"></td>
</tr>
<tr>
<td width="100">Art information:</td>
<td><input name="info" type="text" id="info"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="add2" type="submit" id="add2" value="L�gg till art">
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
<html>
<head>
<title>Add New Record in MySQL Database</title>
</head>
<body>
<?php
if(isset($_POST['add1']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('fishing');
if(! get_magic_quotes_gpc() )
{
$fish_place = addslashes ($_POST['plats']);
$fish_list = addslashes ($_POST['list']);
}
else
{
$fish_place = $_POST['plats'];
$fish_list = $_POST['list'];
}
$sql="INSERT INTO cach (location, species) VALUES ('$fish_place','$fish_list')";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
$message = 'Sucsess!';
echo "<SCRIPT>
alert('$message');
</SCRIPT>";
mysql_close($conn);
}
else{
?>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT id, name, ideal_weigth FROM species';
mysql_select_db('fishing');
$getUser_sql = 'SELECT name FROM species';
$getfish = mysql_query($getUser_sql);
?>
<form method="post" action="">
<br>
Plats: <input type="text" name="plats"><br>
Koordinater: <input type="text" name="koordinats"><br>
Datum: <input type="text" name="date"><br>
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea><br>
<select name="list">
<?php
while ($row = mysql_fetch_array($getfish)) {?>
<option value="<?php echo $row['name']; ?>"> <?php echo
$row['name']; ?>
</option>
<?php } ?>
</select><br>
<input name="add1" type="submit" id="add1" value="L�gg till f�ngst">
</form>
<?php
}
?>
</body>
</html>