簡體   English   中英

當我在php表單上單擊Submit時,登錄頁面變為空白,並且它不向數據庫提交日期

[英]When I click submit on my php form the landing page comes up blank and it does not submit date to the database

如標題中所述,當我在php表單上單擊“提交”時,登錄頁面顯示為空白,並且不向數據庫提交日期。 盡管我不確定為什么,但是它在以前(我肯定做錯了某些事情)就起作用了,實際上偶爾(極其罕見)也起作用了。 以下是表單的登錄頁面。 下面是表格本身。 我對此很陌生,因此感謝您的幫助/評論。

表單登陸頁面

 <?php
    session_start();
    if(isset($_SESSION['myusername']))
    if ($_POST['title'] == '' or $_POST['story'] == '' or $_POST['city'] == '' or $_POST['province'] == '' ) {
    $_SESSION['error1'] = "All fields required!";
    header("Location: debate.php");
    print "issue";
    }
    else {
    include 'config.php';
    if (get_magic_quotes_gpc())
    {
    function stripslashes_deep($value)
    {
    $value = is_array($value)?
    array_map('stripslashes_deep',$value):
    stripslashes($value);
    return $value;
    }

    $_POST = array_map('stripslashes_deep',$_POST);
    $_GET = array_map('stripslashes_deep',$_GET);
    $_COOKIE = array_map('stripslashes_deep',$_COOKIE);
    $_REQUEST = array_map('stripslashes_deep',$_REQUEST);
    }
    $name = mysql_real_escape_string($_POST['title']);
    $content = mysql_real_escape_string($_POST['story']);
    $city = mysql_real_escape_string($_POST['city']);
    $province = mysql_real_escape_string($_POST['province']);
    $query = "INSERT INTO comments(commentusername, commentcontent, status, debateid, city, province) VALUES ('.$name.','.$content.','0','1','.$city.','.$province.')";
    $result=mysql_query($query,$conn);
    $_SESSION['error1'] = "Thank you for your submission!";
    header("Location: debate.php");
    print "issue";
    mysql_close();
    }?>

提交表格

提交表格編碼。

<!-- comment form -->
<div style="position:absolute;left:600px;top:750px;border-style:solid;border-color:#970033;background-color:black;border-width:4px;">
<div align="center"><strong><font color="white"><b>Join the debate</b></font></strong></div>
<form action="cposting.php" method="post">
    <TABLE WIDTH="60%">
     <tr>
      <td>Name:<input type="text" name="title" SIZE="35"> </td>
 <tr>
      <td>City:<br><input type="text" name="city" SIZE="35"> </td>
     </tr>
<tr>
      <td>Province:<input type="text" name="province" SIZE="35"> </td>
     </tr>
     <tr><td>Comment<br></td></tr>
       <tr width="80%">

      <td><TEXTAREA NAME="story" ROWS="5" COLS="30"></TEXTAREA></td>
     </tr>
 <td><input type="submit" value="Post"></td></tr>
</table>
</form>

非常感謝您的幫助。 謝謝!

以下代碼用於管理員批准頁面。 這是我第一次發帖時的注釋所在(如果我保持瀏覽器處於打開狀態,則是后續發帖),但是之后不去。

<?php
session_start();
if(isset($_SESSION['myusername'])) 
if($_SESSION['myusername'] == "Bobert") {
?>
<html>
<title>Discourse Magazine</title>
<head>
</head>
<body background="" style="background: url() no-repeat;  background-size: 100%;">

<?php
include 'config.php';

print '<h4>'.'Welcome back:'.'&nbsp'.$_SESSION['myusername'].'</h4>';
?>
<div style="float:left;border-style:solid;border-width:2px;"><img style="z-index:1;height:200px;" src="/favicon.png" alt="" /></div><br><br><br><br><br><br><br><br><br><br><br><br><br>
Approving Comments (listed oldest to newest)
<?php
if (get_magic_quotes_gpc()) {
    $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    while (list($key, $val) = each($process)) {
        foreach ($val as $k => $v) {
            unset($process[$key][$k]);
            if (is_array($v)) {
                $process[$key][stripslashes($k)] = $v;
                $process[] = &$process[$key][stripslashes($k)];
            } else {
                $process[$key][stripslashes($k)] = stripslashes($v);
            }
        }
    }
    unset($process);
}


if ($conn) {

$SQL = "SELECT * FROM comments where status = '0' ORDER BY commentid";
$result = mysql_query($SQL,$conn) OR die(mysql_error());
while ($row = mysql_fetch_array($result)) {


$rows=mysql_num_rows($result);
$capproveidid = $row['commentid'];
$cdeleteid = $row['commentid'];
print '&nbsp';
print '<div style="background: url() no-repeat;overflow:auto;padding-top:3px;border-style:solid;border-width:5px;width:800px;">';
print '<p style="padding-left:5px;">'.'<u>'.'<strong>'. $row['commentusername'].'</strong>'.'</u>' .'<br>'. $row['commentcontent'] .'<br>'.'<br>'.'</p>';
?>

<form action="approve.php" method="post">
<input type="hidden" name="capproveidid" value="<?php echo $capproveidid;?>"/>
<input type="submit" value="Approve">
</form>
<form action="cdelete.php" method="post">
<input type="hidden" name="cdeleteid" value="<?php echo $cdeleteid;?>"/>
<input type="submit" value="Delete">
</form>

<?php
print '</div>';

}
}
else {
print "Database NOT Found ";
}
}
else{
header('Location: debate.php');
}
ob_end_flush();
?>
</body>
</html>

您很可能沒有正確設置INSERT查詢的格式。 通過在整個查詢中使用雙引號,您實際上是在發送...'.something.'...

您可以執行以下操作:

$query = "INSERT INTO comments(commentusername, commentcontent, status, debateid, city, province) VALUES ('$name','$content','0','1','$city','$province')";

或這個:

$query = "INSERT INTO comments(commentusername, commentcontent, status, debateid, city, province) VALUES ('" . $name . "','" . $content . "','0','1','" . $city . "','" . $province . "')";

無論哪種方式,都可以通過添加... or die(mysql_error());進行調試... or die(mysql_error()); 在您的mysql_query 另外,您可以只echo $query; 看看正在發送什么。

最后,您應該停止使用已被棄用的 mysql_函數,並使用mysqli_PDO ,它們允許准備好的語句並防止SQL注入。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM