当我使用方法get提交表单时,表单中的get将删除之前的表单?p=page1&title=food.我的网址看起来像localhost/test/index.php?p=page1&title=0
<form action="" method="get">
<input type="text" name="q" placeholder="Search" />
<input type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
在我提交表单后,它将替换localhost/test/index.php?p=page1&title=0为localhost/test/index.php?q=example我想要q添加到现有的URL中&
我正在尝试将一个简单的MVC模式应用到我当前的网站而没有任何框架.因为我还没有真正进入oop但我现在还在使用程序.
我有一个简单的登录表单(查看)
<form action="controller/login.php" method="Post">
<input type="text" name="username" placeholder="Username" />
<input type="text" name="password" placeholder="Password" />
<input type="submit" value="Sign in" />
</form>
Run Code Online (Sandbox Code Playgroud)
此表格将提交给控制人员登录表格.控制器现在将检查两个字段是否都有输入并且或多或少地"清理"输入
if(isset($_POST['username'])){
$username = $_POST['username'];
$password = $_POST['password'];
$username_escape = mysqli_real_escape_string($connect, $username);
$password_escape = mysqli_real_escape_string($connect, $password);
}
header("../model/login.php");
Run Code Online (Sandbox Code Playgroud)
这是一个非常简单的检查现在,但我现在想知道我应该将控制器包含在模型中并从控制器或表单重定向到模型提交它在第一个位置并包含控制器.
模型
include_once("../controller/login.php");
$query = mysqli_query($connect, "INSERT into DB_table (username, password)
VALUES($username_escape, $password_escape)");
Run Code Online (Sandbox Code Playgroud) 用户在函数中输入字符串后动态扩展数组dynamic_array我的问题似乎是当我在main dynamic_array返回true 后尝试在main中使用扩展数组agian时.
函数调用后,我尝试打印input与printf("main string: %s\n", input)程序会崩溃.这似乎是*input在main永远不会被延长.
int dynamic_array(char *input, int *string_current_len){
int string_len = 0;
char temp_c;
input = (char *) malloc(sizeof(char));
if(input == NULL) {
printf("Could not allocate memory!");
exit(1);
}
printf("File to search in: ");
while((temp_c = getchar()) != '\n') {
realloc(input, (sizeof(char)));
input[string_len++] = temp_c;
}
input[string_len] = '\0';
printf("\nYou entered the string: %s\n", input);
printf("length of string is %d.\n", string_len);
*string_current_len = string_len;
return …Run Code Online (Sandbox Code Playgroud)