rom*_*meo 1 html php forms get
我的代码非常简单,但它不起作用.它曾经工作,但后来我改变了一些东西,现在我又恢复了基础.你们能明白为什么它不起作用吗?
客户代码
<h1>Logg inn</h1>
<form method="get" action="herpaderp.php">
<input type="text" class="form-control" id="title" value="Testtittel">
<input type="text" class="form-control" id="desc" value="Testbeskrivelse">
<input type="text" class="form-control" id="src" value="lollolol.jpg">
<button type="submit" class="btn btn-primary">Logg inn</button>
</form>
Run Code Online (Sandbox Code Playgroud)
服务器代码:
<?php
if(isset($_GET["title"]))
echo $_GET["title"];
if(isset($_GET["desc"]))
echo $_GET["desc"];
if(isset($_GET["src"]))
echo $_GET["src"];
?>
Run Code Online (Sandbox Code Playgroud)
很简单,您的表单元素需要命名而不是ID.
你id="title"
还应该name="title"
(添加到你现在拥有的)
你可以使用id="title"
,但只要确保你也包括name="title"
(一个预测)=>我也注意到你正在使用这个词,desc
如果你将它与数据库结合使用,就像desc
一个MySQL 保留字,只是说.
一个例子:
以下将抛出错误:
"INSERT INTO yourTable (desc) VALUES ('value')"
Run Code Online (Sandbox Code Playgroud)
正确的方法:(使用列名周围的tick字符)
"INSERT INTO yourTable (`desc`) VALUES ('value')"
Run Code Online (Sandbox Code Playgroud)