2

我的代码有一个烦人的问题,即拒绝插入 MySQL 表。谁能告诉我我做错了什么?

这是SQL代码..

<?php
if (isset($_POST['submitpraes'])) 
{
    $praesTitel = $row['kontypeBeskriv'];           
    $praesStr = $_POST['praesidag'];
    $konID = $row['konID']; 

    $sql=("INSERT INTO  `mah1233411190550`.`praestationer` (
        `praesID` ,
        `praesTitel` ,
        `praesStr` ,
        `brugerID` ,
        `holdID`,
        `konID` 
        )
        VALUES (NULL ,  '$praesTitel',  '$praesStr',  '$brugerID', '$holdID', '$konID');");
    mysql_query($sql);
    echo $sql;
}
?>

和PHP代码...

<?php
$virksomhedsID = $_SESSION['virkID'];
$sql = "SELECT * 
        FROM konkurrence 
        INNER JOIN konkurrenceType ON konkurrenceType.kontypeID = konkurrence.kontypeID 
        WHERE konkurrence.virkID = '$virksomhedsID' 
        AND (CURDATE() BETWEEN `konStart` AND `konSlut`)";  

$result = mysql_query($sql);                
$row = mysql_fetch_assoc($result);  

echo '<td width="12%" height="45">';
echo 'konID' . $row['konID'];   
echo '<img src="' . $row['kontypeFilename'] . '" width="38px" alt="' . $row['kontypeBeskriv'] . '"/>';
echo '</td>';           
echo '<td width="25%">Jeg har i dag ' .  $row['kontypeBeskriv'] . 't</td>';
echo '<td>';

echo '<input class="textboxReport" type="text" name="praesidag" size="3"/>&nbsp;km &nbsp;&nbsp;';
echo '<input type="submit" name="submitpraes" id="submitpraes" value="GEM" />';
echo '</td>';
?>

sql看起来像这样:

INSERT INTO `mah1233411190550`.`praestationer` ( `praesID` , `praesTitel` , `praesStr` , `brugerID` , `holdID`, `konID` ) VALUES (NULL , '', '2', '39', '23', '');

并表明以下内容不起作用,但我不明白为什么......

$praesTitel = $row['kontypeBeskriv'];           
$konID = $row['konID'];
4

2 回答 2

1

表格需要这样设置。里面有你需要的值:

echo '<form method="post" action="">';
echo'<input type="hidden" name="" value="' . $row['konID'] . '">'; 
echo '<input type="hidden" name="" value="' . and $row['kontypeBeskriv'] . '">';        
echo '<input class="textboxReport" type="text" name="praesidag" size="3"/>';
echo '<input type="submit" name="submitpraes" id="submitpraes" value="GEM" />';
echp '</form>';

将行动点指向您需要发布表单的地方。

于 2012-12-17T23:04:00.953 回答
0

您从此处的 POST 获取变量:

$praesTitel = $row['kontypeBeskriv'];           
$praesStr   = $_POST['praesidag'];
$konID      = $row['konID']; 

$_POST你应该从而不是得到你的价值观$row

$praesTitel = $_POST['kontypeBeskriv'];           
$praesStr   = $_POST['praesidag'];
$konID      = $_POST['konID']; 

因为在您的第一个 php 代码中没有要获取的行。

于 2012-12-17T22:34:14.127 回答