提交并重新提交摘要ID号

时间:2017-01-04 21:40:33

标签: php

我有一份摘要提交表格。客户提交摘要,我在我的数据库中收集它们。表单有一个选项,客户端可以通过确认邮件中生成的链接更改提交的摘要。我需要在他们重新提交摘要时,我在数据库中收到的提交ID如下:''提交ID = 1a,或提交ID = 1b,如果他们第二次重新提交等等。'' 。所以我需要数字相同,但每次重新提交时都会在旁边写一个字母。

现在,无论他们在摘要中做了多少更改,提交ID号都保持不变。 (仅限数字)

以下是重新提交表单的php代码:

<?php

require_once './lib.php';
include_once 'lib/swift_required.php';

function reSendSubmissions() {
    $ids = array(108, 117, 142, 170, 171, 154, 153, 146, 159, 255, 109, 185, 250, 257, 151, 235, 234, 233, 273, 275, 281, 355, 366, 373, 231, 365, 384, 425, 234, 290, 303, 153, 154, 391, 388);
    foreach ($ids as $id) {
        $sql = 'SELECT a.`title`, a.`speaker`, a.`submisssion_timestampt`, a.`submissionid`, a.`pincode`, b.`email` '
                . 'FROM `submissions` a INNER JOIN `personaldata` b ON(b.`pdataid`=a.`pdata_id`) '
                . 'WHERE a.`submissionid`="' . (int) $id . '" '
                . 'LIMIT 1';
        $db = new dbrequest();
        $data = array();
        if ($submission = $db->generalSelect($sql)) {
            if (!$submission[0])
                continue;
            $submission = $submission[0];
            $data['title'] = $submission['title'];
            $data['speaker'] = $submission['speaker'];
            $data['date'] = date('d-m-Y', strtotime($submission['submisssion_timestampt']));
            $data['time'] = date('H:i', strtotime($submission['submisssion_timestampt']));
            $data['no'] = $submission['submissionid'];
            $data['link'] = 'http://www.e-bass.org/22ndcongress/form/edit.php?pcode=' . $submission['pincode'];
//            maildata::mailSenderTest($submission['email'], $data);
            echo $id.'-'.$submission['email'].'<br/>';
        }
    }
}

reSendSubmissions();

结束提交表单的php代码:

<?php

if ((isset($_POST['firstname'])) && (isset($_POST['email']))) {
    require_once 'lib.php';
    (isset($_POST['poster'])) ? $poster = $_POST['poster'] : $poster = null;
    (isset($_POST['contestant'])) ? $contestant = $_POST['contestant'] : $contestant = null;
    $newdata = new dbrequest();
    $pdata = array(
        'firstname' => filter_input(INPUT_POST, 'firstname', FILTER_SANITIZE_STRING),
        'lastname' => filter_input(INPUT_POST, 'lastname', FILTER_SANITIZE_STRING),
        'address' => $_POST['address'],
        'city' => $_POST['city'],
        'poc' => $_POST['poc'],
        'country' => $_POST['country'],
        'workingplace' => $_POST['workingplace'],
        'specialization' => $_POST['specialization'],
        'email' => $_POST['email'],
        'cellphone' => $_POST['cellphone'],
        'phone' => $_POST['phone'],
        'fax' => $_POST['fax']);
    $authors = $_POST['authors1'] . '-' . $_POST['title1'] . '-' . $_POST['university1'] . ';' . $_POST['authors2'] . '-' . $_POST['title2'] . '-' . $_POST['university2'] . ';' . $_POST['authors3'] . '-' . $_POST['title3'] . '-' . $_POST['university3'] . ';' . $_POST['authors4'] . '-' . $_POST['title4'] . '-' . $_POST['university4'] . ';' . $_POST['authors5'] . '-' . $_POST['title5'] . '-' . $_POST['university5'];
    if ((isset($_POST['update'])) && ($_POST['update'] == 'true')) {
        $updateSubData = array(
            'authors' => $authors,
            'speaker' => trim(filter_input(INPUT_POST, 'speaker_firstname', FILTER_SANITIZE_STRING)) . ' ' . trim(filter_input(INPUT_POST, 'speaker_lastname', FILTER_SANITIZE_STRING)),
            'title' => $_POST['title'],
            'presentation_id' => $_POST['presentation'],
            'topic_id' => $_POST['topic'],
            'poster' => $poster,
            'contestant' => $contestant,
            'summary' => $_POST['summary']);
        $newdata->updatePersonalData($pdata, $_POST['pdata_id']);
        $newdata->updateSumission($updateSubData, $_POST['submissionid']);
        $html = <<<EOD
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title>Paper Submited</title>
                                </head>
                <body style="margin:0; padding:0">
                <div style="width:600px;height:auto; margin:0 auto;">
                <div id="header"></div>
                <div id="content">
                <h3>The processing of your paper is done successfully.</h3>
                <p style="text-align:center">Thank you for your participation.</p>
                </div>
                </div>
                </body>
                </html>
EOD;
        print $html;
    } else {
        $speakerPost = trim(filter_input(INPUT_POST, 'speaker_firstname', FILTER_SANITIZE_STRING)) . ' ' . trim(filter_input(INPUT_POST, 'speaker_lastname', FILTER_SANITIZE_STRING));
        $speakerDB = $newdata->metriseOmilites($speakerPost);
        $speakerDB = $speakerDB[0]['single_speaker'];
        if ($speakerDB >= 1) {
            $html = <<<EOD
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title>SUBMISSION FORM</title>
                                </head>
                <body style="margin:0; padding:0">
                <div style="width:600px;height:auto; margin:0 auto;">
                <               <div style="width:600px;height:auto; margin:0 auto;background-color:#4F6B92">
                <h3>There was an error in your application.</h3>
                <p style="text-align:center">The presenter chosen is already registered in 1 paper.</p>
                <p style="text-align:center"><a href="javascript:history.back(1)">Click here to return to the Submission Form.</a></p>
                </div>
                </div>
                </body>
                </html>
EOD;
            print $html;
            exit();
        }
        $newdata->insertPersonalData($pdata);
        $pdata_id = $newdata->selectLastInsert('personaldata', 'pdataid');
        $pdata_id = $pdata_id[0]['pdataid'];
        $pcode = mt_rand(1, 99999);
        $pcode = md5(time() . $pcode);
        $pcode = substr($pcode, 0, 22);
        $submission = array(
            'pincode' => $pcode,
            'pdata_id' => $pdata_id,
            'authors' => $authors,
            'speaker' => trim(filter_input(INPUT_POST, 'speaker_firstname', FILTER_SANITIZE_STRING)) . ' ' . trim(filter_input(INPUT_POST, 'speaker_lastname', FILTER_SANITIZE_STRING)),
            'title' => $_POST['title'],
            'presentation_id' => $_POST['presentation'],
            'topic_id' => $_POST['topic'],
            'poster' => $poster,
            'contestant' => $contestant,
            'summary' => $_POST['summary']);
        $newdata->insertSubmission($submission);
        $submissionNo = $newdata->selectLastInsert('submissions', 'submissionid');
        $submissionNo = $submissionNo[0]['submissionid'];
        $neoMail = new maildata();
        $datamail = array(
            'title' => $_POST['title'],
            'speaker' => $_POST['speaker_firstname'] . ' ' . $_POST['speaker_lastname'],
            'date' => date('d-m-Y'),
            'time' => date('H:i'),
            'no' => $submissionNo,
            'link' => 'http://' . $newdata->domainURL . '/edit.php?pcode=' . $pcode);
        $neoMail->mailSender($_POST['email'], $datamail);
        $html = <<<EOD
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title>SUBMISSION OF PAPER</title>
                                </head>
                <body style="margin:0; padding:0">
                <div style="width:600px;height:auto; margin:0 auto;">
                <div id="header"></div>
                <div id="content">
                <h3>Submitting your work done successfully.</h3>
                <p>You receive the relevant proof of submission to the email address you provided in the application form.</p>
                <p style="text-align:center">Thank you for your participation.</p>
                </div>
                </div>
                </body>
                </html>
EOD;
        print $html;
    }
}

你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

是的,我们可以,或者看起来如此。首先,您不应该更改ID本身。您应该为版本添加新的数据库列并仅更新它。 (嗯,你也可以直接更改ID,但是还有更多的代码需要修改,加上它不是一个非常聪明的方法。)< / p>

首先:修改您的数据库。我想你会使用像PHPMyAdmin这样的东西,在这种情况下:转到表submissions;转到&#34;结构&#34;标签;并添加一个名为version的字段。可能就在submissionid字段之后。您可以输入CHAR(1),假设您没有Z版本。

第二:修改您的更新例程,如下所示:

// We're modifying the code after this line:
if ((isset($_POST['update'])) && ($_POST['update'] == 'true')) {

// Here we get the current version:
// (You could also get it from your submit form, but then 
//  you'd have to check that the user hasn't messed with it.)

$curr = $newdata->generalSelect('SELECT `version` FROM `submissions` 
             WHERE `submissionid` = ' . (int)  $_POST['submissionid']);

// If the old version is 'a'; it becomes 'b' etc. here:

$version = $curr['version']++;

// Then add it to your array with updated fields:

$updateSubData = array(
    'version' => $version, 
    // ...

根据您共享的代码,这应该就是全部。您的应用程序的其他部分可能与其冲突或需要其他修订 - 您更了解(或者您即将发现)。现在我浏览了你的代码......下面还有几件需要研究的事情......

另外:请注意 - 除非您在数据库类中完成 - 更新查询中的变量(两者)都没有清理,您可能容易受到SQL注入攻击

另外:在function reSendSubmissions()由于某种原因,您要为每个ID单独查询,而不是像这样使用单个查询:

WHERE a.`submissionid` IN ("' . implode(',', $ids) . '")

您将在循环之前进行查询,这将返回所有行的资源,然后使用while($submission = $result->fetch_assoc()) {作为循环。 (也就是说,假设您的数据库类返回标准mysqli结果资源。)

另外:您的变量和方法名称中存在一些拼写错误,我的眼球会因submisssion_timestampt$newdata->updateSumission而受到伤害。如果这些错误没有给您带来好处,那么您可能希望在代码库中更新它们以便于维护。