通过帖子我将值发送到包含以下代码的php文件:
// Prepare values for database
$username = $_SESSION['username'];
$event_title = $db -> real_escape_string($_POST['create_title_hidden']);
$event_type = $db -> real_escape_string($_POST['create_type_hidden']);
$event_town = $db -> real_escape_string($_POST['create_town_hidden']);
// 1. Identify users_id
$results = $db -> query("SELECT * FROM users WHERE username='$username'");
while ($result = $results->fetch_assoc()) {
$users_id = $result['id'];
}
// 2. Identify towns_id
$query = "SELECT * FROM towns WHERE town='$event_town'";
// Do Search
$results = $db -> query($query);
while ($result = $results -> fetch_assoc()) {
$towns_id = $result['id'];
}
我的问题:第二个查询不起作用,即我无法获取town_id。
我已经检查了我的错误日志,没有这样的错误消息。
也许有些东西我忘了包括在内?是否有可能两个在php脚本中一个接一个地有两个不同的查询?
编辑:
这是我的前端形式:
<form id="form_create_event" method="post" action="system/upload_event_tourist.php">
<p>
You can now create the event:
</p>
<!-- Forms cannot be nested inside forms, that's why the input fields from first view
need to be inserted into hidden input fields via jquery that will be transferred
via post to upload_event_tourist.php -->
<input type="hidden" id="create_title_hidden" name="create_title_hidden">
<input type="hidden" id="create_type_hidden" name="create_type_hidden">
<input type="hidden" id="create_start_hidden" name="create_start_hidden">
<input type="hidden" id="create_end_hidden" name="create_end_hidden">
<input type="hidden" id="create_picturepath_hidden" name="create_picturepath_hidden">
<input type="hidden" id="create_meetingpoint_hidden" name="create_meetingpoint_hidden">
<input type="hidden" id="create_description_hidden" name="create_description_hidden">
<a href="#" class="button button_create_event">CREATE EVENT</a>
<input type="submit" id="submit_create_event" name="submit_create_event">
</form>
<!-- #form_create_event -->
<script>
// Load form details into hidden input fields and Simulate click on submit
$('.button_create_event').on('click', function() {
// load form details into hidden input fields
var event_title = $('#create_title').val();
var event_type = $('#create_type').val();
var event_town = $('#create_town').val();
var event_start = $('#create_start').val();
var event_end = $('#create_end').val();
var event_picturepath = $('#create_picturepath').val();
var event_meetingpoint = $('#create_meetingpoint').val();
var event_description = $('#create_description').val();
$('#create_title_hidden').val(event_title);
$('#create_type_hidden').val(event_type);
$('#create_town_hidden').val(event_town);
$('#create_start_hidden').val(event_start);
$('#create_end_hidden').val(event_end);
$('#create_picturepath_hidden').val(event_picturepath);
$('#create_meetingpoint_hidden').val(event_meetingpoint);
$('#create_description_hidden').val(event_description);
$('#form_create_event').submit();
});
</script>
答案 0 :(得分:0)
追踪你的变量。
$_POST['create_town_hidden']
由:
分配$('#create_town_hidden').val(event_town);
调用变量event_town。该变量在此处设置:
var event_town = $('#create_town').val();
应该选择ID为&#39; create_town&#39;,的内容,但HTML中没有包含该ID的元素。解决这个问题,你的问题就解决了。