【解決方法】データベースの数値レコードを更新するにはどうすればよいですか?


私がやりたいことは、ユーザーが登録フォームのドロップダウン リストからオプションを選択するたびに、データベース テーブルのレコードが 1 ずつ加算されることです。

エラーが発生し続けます:

Fatal error: Uncaught mysqli_sql_exception: Unknown column 'information_service' in 'where clause' in C:\xampp\htdocs\user-page\user_interface\appointment.php:11 Stack trace: #0 C:\xampp\htdocs\user-page\user_interface\appointment.php(11): mysqli_query(Object(mysqli), 'UPDATE scoring ...') #1 {main} thrown in C:\xampp\htdocs\user-page\user_interface\appointment.php on line 11

HEREは私のフォームのコードです

HTML
<pre><body>
		<div class = "container-fluid">
			<form method= "post" action= "appointment.php">
				<h1>Book Appointment for Guidance</h1>
					<div class= "group">
					<select name="service" id ="services" onchange="enableType(this)">
						<option value ="0">--Choose Services--</option>
						<option value ="individual_inventory">Individual Inventory</option>
						<option value ="counselling_service">Counselling Services</option>
						<option value ="information_service">Information Services</option>
						<option value ="follow-up_service">Follow-up Services</option>
						<option value ="psychological_testing_and_evaluation">Psychological Testing and Evaluation</option>
						<option value ="referral">REFERRAL</option>
						<option value ="placement_service">Placement Services</option>


					<input name="submit" type ="submit" class="button" value="Submit">
			</form>
		</div>
</body>

私が試したこと:

これは私のphpコードです:

PHP
<pre><?php include_once('connect.php');

if(isset($_POST['submit'])){

    $serv =$_POST['service'];
    $type =$_POST['types'];
    $case =$_POST['cases'];

       if($serv){
           $mysql ="UPDATE scoring SET services_score = services_score + 1 WHERE services = $serv";
           mysqli_query($dbh,$mysql);
       }
       if($type){
        $mysqls ="UPDATE scoring SET types_score = types_score + 1 WHERE counseling_types= $type";
        mysqli_query($dbh,$mysqls);
    }
    if($case){
        $mysqlss ="UPDATE scoring SET cases_score = cases_score + 1 WHERE counseling_cases = $case";
        mysqli_query($dbh,$mysqlss);
    }
}

?> 

The variable $serv is assigned for the <select> tag named 'service'. and the information_service from the error message is a value name for <option>Information Service. it is also a name of a row in my database. I have named the row and the value the same, so that, if the user chooses any from the option, then the code will execute to call the row from my database according to the user selected option. but the code recognizes the option value as a column name.

私を助けてください

解決策 1

それはそのコードではありません – エラーメッセージを読んでください:

エラー
unknown column 'information_service' in 'where clause' in C:\xampp\htdocs\user-page\user_interface\appointment.php:11

という列が見つかりません information_service あなたのDBで。

あなたが私たちに示したものはどれも参照していないので information_service 問題は、コードの他の場所にあり、私たちにはわかりません。
だから、ファイルを見ることから始めます appointment.php 特に 11 行目 – 問題が報告されている場所です。

コメント

タイトルとURLをコピーしました