gpt4 book ai didi

php - MySQL 中 string 作为 varchar 类型

转载 作者:行者123 更新时间:2023-11-30 00:49:58 26 4
gpt4 key购买 nike

我正在插入用户输入的值,即两个数组ROOMTILTIE和CAPACITY。当我输入诸如“2s32”之类的字符串和容量时,RoomTitle是varchar,容量是整数类型,并且容量是任何整数值,它不会将其插入表中,但当两者都是整数时,它就可以完美工作..下面是代码

     <form name="venueform"   method="post" >
<input type="hidden" name="check_submit" value="1" id="check_submit" />
<table width="450px">
</tr>
<tr>
<td valign="top"">
<label for="TotalRooms">Total Number of Rooms*</label>
</td>

<td valign="top">
<input type="text" name="TotalRooms" maxlength="50" size="10"id='sth'>
</td>
</tr>
<td colspan="2" style="text-align:left">
<input name="submit1 "type="submit" value="submit">
</td>
</tr>
</table>
</form>

mysql_connect("localhost","root","");//database connection
mysql_select_db("ossd");
for($i=0;$i<$_POST['TotalRooms'];$i++)
{

echo"<p>\n</p>";
?><form method="post">
<input type="text" name='RoomTitle[]' /><br />
<input type="text" name='Capacity[]' /><br />
echo"<input name='addvenue' type='submit'value='Submit me' />
</form>";
if (isset($_POST['addvenue'])) {

<div>
<?php echo "<pre>".print_r($_POST['RoomTitle'],true)."</pre>";
echo "<pre>".print_r($_POST['Capacity'],true)."</pre>";

mysql_connect("localhost","root","");//database connection
mysql_select_db("ossd");
foreach ($_POST['RoomTitle'] as $row=>$name)

{

$RoomTitle = $name;

$Capacity = $_POST['Capacity'][$row];
$RoomTitle= mysql_real_escape_string($name);

$Capacity = mysql_real_escape_string($_POST['Capacity'][$row]);

$order = "INSERT INTO wp_ossd_venue
(RoomTitle,Capacity)
VALUES
(".$RoomTitle.",".$Capacity.")";

$result = mysql_query($order);

}
if($result){
echo("<br>Succesfully Added");
} else{
echo("<br>Fail... Error");
}

}

最佳答案

您的插入查询应该是:

$order = "INSERT INTO wp_ossd_venue
(RoomTitle,Capacity)
VALUES
('".$RoomTitle."',".$Capacity.")";

关于php - MySQL 中 string 作为 varchar 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21062919/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com