虽然插入数据成功,但插入数据库的数据变成了整数,但我的数据库中插入数据时出现问题。使用php插入数据到数据库的问题
<?php
//connect to database
include "databaseconnection.php";
?>
<body bgcolor="#e5edf8">
<form name="addform" method="post" action="../insert.php">
<table width="1110" height="184" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="393" height="28"><strong> TICKET NO :
<?php
$sql = mysql_query("SELECT * FROM troubleticket");
$record = mysql_fetch_array($sql);
echo '<input type="text" name="ticketnofld" readonly value=" '.$record['ticketno'].' " >';
?>
</strong>
</td>
<td width="717"> <strong>TECHNICAL NAME :
<?php
echo "<select name='techname' type='text'>";
echo '<option id="0">'.'--Select technical Name--'.'</option>';
$sql = mysql_query("SELECT * FROM technical");
while($record = mysql_fetch_assoc($sql))
{
echo '<option value=" '.$record['ID'].'">'.$record['FNAME']. '</option>';
}
echo '</select>';
?>
</strong></td>
</tr>
<tr>
<td><strong>COMPANY NAME :
<?php
echo "<select name='companyname' type='text'>";
echo '<option id="0">'.'--Select Company Name--'.'</option>';
$sql = mysql_query("SELECT * FROM client");
while($record = mysql_fetch_assoc($sql))
{
echo '<option value=" '.$record['ID'].'">'.$record['NAME']. '</option>';
}
echo '</select>';
?>
</select>
</strong></td>
<td><strong>TYPE OF SERVICE :
<?php
echo " <select name='typeofservice' type='text'>";
echo '<option id="0">'.'--Select type of service--'.'</option>';
$sql = mysql_query("SELECT * FROM typeofservice");
while($record = mysql_fetch_assoc($sql))
{
echo '<option value=" '.$record['tosid'].'">'.$record['typeofservice']. '</option>';
}
echo '</select>';
?>
</strong></td>
</tr>
<tr>
<td colspan="2"><p><strong>PROBLEM :<textarea type='text' rows="10" cols="100" name="problemfld" id="problemfld"> </textarea>
</strong></p>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Addbutton" value="ADD" >
<input type="button" name="Cancelbutton" value="CANCEL" ></td>
</tr>
</table>
</form>
,这是insert.php
<?php
$con=mysql_connect("127.0.0.1","root","","ojt") or die('Could not reach the database'.mysql_error());
$techname=isset($_POST['techname']);
$companyname=isset($_POST['companyname']);
$typeofservice=isset($_POST['typeofservice']);
$problem=isset($_POST['problemfld']);
$techname=stripslashes($techname);
$companyname=stripslashes($companyname);
$typeofservice=stripslashes($typeofservice);
$problem=stripslashes($problem);
$techname=mysql_real_escape_string($techname);
$companyname=mysql_real_escape_string($companyname);
$typeofservice=mysql_real_escape_string($typeofservice);
$problem=mysql_real_escape_string($problem);
$sql="INSERT INTO `ojt`.`troubleticket` (`ticketno`, `technicalname`, `services`, `problem`, `companyname`, `remarks`) VALUES (' ','$techname', '$typeofservice', '$problem', '$companyname', 'NEW')";
$query=mysql_query($sql,$con);
if($query)
{
echo '1 Data Added';
}
else
{
echo 'Unsuccessfully Saved';
}
?>
什么是您的数据库结构?你确定这些字段有文字吗? – JakeGould
MySQL在PHP 5.5.x中已弃用,请考虑切换到MySQLi。 – OPatel
肯定与'$技术= isset($ _ POST ['技术'])中'isset'有关;'等等 –