나는 stackoverflow에서 이와 같은 질문이 많지만 아무도 내 문제를 팔지 못했다.데이터베이스에 데이터 추가하기 PHP
저는 이벤트 캘린더를 작성 중이며 현재 이벤트 추가 페이지를 만들고 있습니다. 페이지가 제출 될 때 오류는 표시되지 않지만 양식 정보는 데이터베이스에 업로드되지 않으며 구문을 검사하고 오류를 볼 수없는 이유는 확실하지 않습니다.
* $ _SESSION [ 'user_id']을 (를) 표시하도록 요청하면 loginform.php 및 core.php를 추가하십시오. 코드에서 유래 : loginform.php
<?php
$con = mysql_connect("localhost","pytsuemg_brodie","brodie");
$db = mysql_select_db("pytsuemg_brodie");
if (isset($_POST['username'])&&isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$password_hash =md5($password);
if (!empty($username)&&!empty($password)) {
$query="SELECT `AccountID` FROM `Parent` WHERE `Username`='$username' AND `Password`='$password_hash'";
if ($query_run = mysql_query($query)) {
$query_num_rows = mysql_num_rows($query_run);
if ($query_num_rows==0) {
echo 'Invalid username/password combination';
} else
if ($query_num_rows==1) {
$user_id = mysql_result($query_run,0,'AccountID');
$_SESSION['user_id']=$user_id;
header('Location: profilepage.php');
}
}
} else {
echo 'You must supply a username and password.';
}
}
?>
<form action="login.php" method="POST">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" value="Log In">
</form>
core.php
require 'core.php';
$con=mysqli_connect("localhost","pytsuemg_brodie","brodie","pytsuemg_brodie");
if (isset($_POST['DateStart'])&&isset($_POST['DateEnd'])&&isset($_POST['TimeStart'])&&isset($_POST['TimeEnd'])&&isset($_POST['EventType'])&&isset($_POST['Description'])&&isset($_POST['Children'])&&isset($_POST['Location'])&&isset($_POST['MealsGiven'])){
$DateStart = $_POST['DateStart'];
$DateEnd = $_POST['DateEnd'];
$TimeStart = $_POST['TimeStart'];
$TimeEnd = $_POST['TimeEnd'];
$EventType = $_POST['EventType'];
$Description = $_POST['Description'];
$Children = $_POST['Children'];
$Location = $_POST['Location'];
$MealsGiven = $_POST['MealsGiven'];
if (!empty($DateStart)&&!empty($DateEnd)&&!empty($TimeStart)&&!empty($TimeEnd)&&!empty($EventType)&&!empty($Description)&&!empty($Children)&&!empty($Location)&&!empty($MealsGiven)){
$sql = "INSERT INTO Events (DateStart, DateEnd, TimeStart, TimeEnd, Location, EventType, MealsGiven, description,Children, AccountID) VALUES(
'$DateStart','$DateEnd','$TimeStart','$TimeEnd','$Location','$EventType','$MealsGiven','$Description','$Children','".$_SESSION['user_id']."')";
mysqli_query($con, $sql);
/* commit transaction */
if (!mysqli_commit($con)) {
print("Transaction commit failed\n");
exit();
}
} else {
echo'All fields are required';
}
}
/* close connection */
mysqli_close($con);
?>
<br>
<form action="addevent.php" method="post">
<p> Date:<label for="from"> From</label>
<input type="text" id="from" name="DateStart">
<label for="to">to</label>
<input type="text" id="to" name="DateEnd"></p>
<p>Start Time:<input type="text" name="TimeStart" /></p>
<p>End Time:<input type="text" name="TimeEnd" /></p>
<p>Event Type :
<select name="EventType">
<option value="Change over">Changeover</option>
<option value="Parents Evening">Parents Evening</option>
<option value="After School Activity">After School Activity</option>
<option value="Weekend Activity">Weekend Activity</option>
<option value="Holiday">Holiday</option>
</select> </p>
<p>Description (max 100 Characters) <br><textarea rows="2" cols="50" maxlength="100" name="Description"></textarea></p>
<p>Children Involved: <br><textarea rows="1" cols="50" maxlength="32" name="children"></textarea></p>
<p>Location: <input type="text" name="Location" /></p>
<p>Meals Given: <select name="MealsGiven">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select></p>
<p><input type="submit" value="Submit"/></p>
</form>
'$ _SESSION ['user_id ']'에 대한 참조가 보이지 않고 코드에 표시된'session_start();도 없습니다. 참조가 비어 있으면 전체 쿼리가 실패합니다. 그것에 대한 참조를 만들거나 제거하십시오. –
그것은 core.php에 있습니다. 나는 그 $ _SESSION [ 'user_id']을 다른 페이지에서 사용하고 있습니다. – user3393477
정확히'core.php'에 무엇이 있습니까? –