抱歉,英语不是我的母语。我真的被困了,因为我只是使用PHP在我的数据库中存储数据(我使用的是mysql)。
所以在我的HTML中我有主要的
function display() {
var canvas = document.getElementById('displaycanvas');
context = canvas.getContext('2d');
context.clearRect(0, 0, canvas.width, canvas.height);
if(document.getElementById('color1').checked){ context.strokeStyle="#FF0000"; } else if(document.getElementById('color2').checked){ context.strokeStyle="#0000FF"; }
if (document.getElementById('shape1').checked) {
context.beginPath(); context.arc(95,50,40,0,2*Math.PI); context.stroke(); }
if (document.getElementById('shape2').checked) {
context.beginPath(); context.rect(50, 27, 50, 100); context.stroke(); }
}
$('#review').click(function () {
$('#shape').html($('input[name="shape_design"]:checked').val());
$('#color').html($('input[name="color_design"]:checked').val());
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id="displaycanvas"></canvas>
<form role="form" id="showchoices" name="showchoices" method="post" onsubmit="return entry_check()" action="/user/ps/add/">
<div> <input type="radio" id="shape1" name="shape_design" value="CIRCLE" onchange="display()" /> O
<input type="radio" id="shape2" name="shape_design" value="RECTANGLE" onchange="display()" /> [] </div>
<div> <input type="radio" id="color1" name="color_design" value="RED" onchange="display()"/> RED
<input type="radio" id="color2" name="color_design" value="BLUE" onchange="display()" /> BLUE </div> </form>
<input type="button" name="btn" value="Review" id="review" data-toggle="modal" data-target="#con_rev" class="btn btn-primary" />
<!-- this modal displays the SUMMARY,working fine -->
<div class="modal fade" id="con_rev" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">Confirm Order</div>
<div class="modal-body">
<form action="#myModal1" role="form" method="POST"> <!-- display for the Order sent -->
<p> Shape: <span id="shape" name="shape" ></span> </p>
<p> Color: <span id="color" name="color" ></span> </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<input type="submit" class="btn btn-success" name="order"/> </div>
</div> </form>
</div>
</div>
&#13;
以上所有内容都运行正常,我只想展示它的外观。
这就是它的工作原理。一旦用户选择了他/她的选择,首先它将显示一个模式&#34; Summarizes&#34;数据的模态id =&#34; con_rev&#34;。 所以这里我们根据用户的选择显示数据。 现在,当用户决定&#34; ORDER&#34;时,我已经制作了另一个模态。或提交其选择。
HTML页面中的模态相同:(这个没有工作)
<div id="myModal1" class="modal modal-child" data-backdrop-limit="1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-modal-parent="#myModal">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">ORDER SENT</h4> </div>
<div class="modal-body">
<?php
include 'database.php';
$pdo = Database::connect();
$shape = $_POST['shape'];
$color = $_POST['color'];
$dbc = @mysql_connect('localhost' , 'root', '');
@mysql_select_db('order_db', $dbc);
$query = "INSERT INTO choice VALUES(NULL, '$shape','$color')";
if(@mysql_query($query,$dbc)){
print '<h1> Your order has been sent </h1>'; }
else{ print '<p> failed. '.mysql_error().'</p>'; }
?>
</div>
</div>
</div>
</div>
我已经按照不同的教程来源进行了整合。 它不会显示错误,但如果我要检查我的数据库,它仍然是空的。希望你能真正帮助我。 如果您使用Ajax,我们的课程无法解决它,所以我不确定我是否可以提升,但如果它是我唯一可以接受它的方式! 先感谢您!
答案 0 :(得分:0)
首先,不推荐使用mysql_connect()
,并且已在PHP 7.0.0中删除了include 'database.php';
$pdo = Database::connect();
现在让我感到困惑的是,你正在通过以下方式获取pdo实例(压缩它是 PDO 扩展名):
<div id="myModal1" class="modal modal-child" data-backdrop-limit="1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-modal-parent="#myModal">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">ORDER SENT</h4> </div>
<div class="modal-body">
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$database = 'order_db';
$shape = $_POST['shape'];
$color = $_POST['color'];
$options = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false
);
try {
$pdo = new PDO("mysql:host=host;dbname=database", $user, $pass, $options);
}
catch (PDOException $e) {
echo "connection error : <br> :";
echo $e->getMessage();
}
$sql = "INSERT INTO 'choice' VALUES (:mynull, :shape, :color)";
$statement = $pdo->prepare($sql);
$statement->bindValue(':mynull', null, PDO::PARAM_INT);
$statement->bindValue(':shape', $shape, PDO::PARAM_STR);
$statement->bindValue(':color', $color, PDO::PARAM_STR);
$inserted = $statement->execute();
if($inserted){
echo 'Your order has been sent !<br>';
}
?>
</div>
</div>
</div>
</div>
但根本没有使用它:
试试这个(我已经通过使用PDO扩展来适应您的配置):
@
也不使用Array
(
[total_results] => 47023
[products] => stdClass Object
(
[product] => Array
(
[0] => stdClass Object
(
[binds] => 1627836:3269460;1627836:3269461;1627836:3269458;1627839:3269490;1627841:3269526
[cid] => 50010368
[name] => 三九光学雷朋太阳镜RayBan超轻树脂镜片运动墨镜RB4039 816/13
[pic_url] => //img06.taobaocdn.com/bao/uploaded/i6/TB1532SOVXXXXcJXXXXN951FFXX_093838.jpg
[price] => 980.00
[product_id] => 717498724
[props] => 20000:55652;1629764:3596338
[status] => 0
[tsc] => CIKCQQU
)
,它旨在抑制错误,因此在抛出错误时您无法看到错误。