السلام عليكم ..
لدي صفحة لإضافة غرفة الى موقع فندق .. وعندما اقوم بتشغيل الكود .. تظهر لي صفحة الاضافة تمام بس يظهر لي خطأ عند اضافة الغرفة لقاعدة البيانات ..
unable to insert records: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from ,to ,type ,floor ,price ,TV ,air_condition ,internet_access, booked ) VALU' at line 1
طبعاً فيه عندي 3 صفحات :
صفحة الاتصال بقاعدة البيانات config.php
<!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">
<?php
// define the server information
$db_server='localhost';
$db_user='root';
$db_pass='';
$db_name='abha_hotel';
// define a new function to use many methods like strip_tags(), addslashes() and trim()
function make_it_safe($string)
{
$string = strip_tags(addslashes(trim($string)));
return $string;
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>فورم اضافة الغرف addnewroom.php
<?php
session_start();
?>
<!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>add new room</title>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationCheckbox.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationCheckbox.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" name="form1" method="post" action="addroom_check.php">
<table width="50%" border="1" align="center">
<tr>
<th scope="row"> </th>
<td> </td>
</tr>
<tr>
<th scope="row">Room type:</th>
<td><span id="spryselect1">
<label>
<select name="type" id="type">
<option value="Single">Single</option>
<option value="Double">Double</option>
</select>
</label>
<span class="selectRequiredMsg">Please select an item.</span></span> </td>
</tr>
<tr>
<th scope="row">Floor:</th>
<td><span id="spryselect2">
<label>
<select name="floor" id="floor">
<option value="First">First</option>
<option value="Second">Second</option>
<option value="Third">Third</option>
</select>
</label>
<span class="selectRequiredMsg">Please select an item.</span></span> </td>
</tr>
<tr>
<th scope="row">Price:</th>
<td><span id="sprytextfield1">
<label>
<input name="price" type="text" id="price" size="10" maxlength="3" />
</label>
<span class="textfieldRequiredMsg">A value is required.</span></span> </td>
</tr>
<tr>
<th scope="row">TV:</th>
<td><span id="sprycheckbox1">
<label></label>
<span class="checkboxRequiredMsg">Please make a selection.</span></span> <label>
<input type="checkbox" name="TV" id="TV" />
</label></td>
</tr>
<tr>
<th scope="row">Air-condition:</th>
<td><span id="sprycheckbox2">
<label></label>
<span class="checkboxRequiredMsg">Please make a selection</span></span> <label>
<input type="checkbox" name="air_condition" id="air_condition" />
</label></td>
</tr>
<tr>
<th scope="row">Internet access:</th>
<td><span id="sprycheckbox3">
<label></label>
<span class="checkboxRequiredMsg">Please make a selection.</span></span> <label>
<input type="checkbox" name="internet_access" id="internet_access" />
</label></td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td><label>
<input type="submit" name="add" id="add" value="add" />
</label>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2");
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1");
//-->
</script>
</body>
</html>صفحة تشييك بيانات الغرفة وكذلك اضافة الغرفة الى قاعدة البيانات addroom_check.php
<?php
include 'config.php';
$type= $_POST['type'];
$floor= $_POST['floor'];
$price= $_POST['price'];
$TV= $_POST['TV'];
$air_condition= $_POST['air_condition'];
$internet_access= $_POST['internet_access'];
// connect to the server, mysql_error() gives a msg if connection fails
$connection= mysql_connect ($db_server, $db_user, $db_pass ) or die ('unable to connect to the server'.mysql_error());
// select the database
mysql_select_db ($db_name) or die ('unable to select the database' .mysql_error);
// select the table from the database
$insert= "INSERT INTO rooms (roomNo ,from ,to ,type ,floor ,price ,TV ,air_condition ,internet_access, booked )
VALUES ('', '', '', '$type', '$floor', '$price', '$TV', '$air_condition', '$internet_access', '')";
$do_insert= mysql_query ($insert) OR DIE ('unable to insert records: '.mysql_error());
echo $do_insert;
if ($do_insert_one == 1)
{
echo 'The new room has been added';
}
else
{
echo 'Error: unable to add a new room';
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>وش الحل ؟؟