通过PHP在SQL中隐藏索引值
我目前正试图让用户通过PHP/HTML表单提交数据,并将其放入SQL数据库。我可以很高兴地做到这一点,但不允许用户输入通过PHP在SQL中隐藏索引值,php,html,sql,Php,Html,Sql,我目前正试图让用户通过PHP/HTML表单提交数据,并将其放入SQL数据库。我可以很高兴地做到这一点,但不允许用户输入索引列,因为它会自动递增,ajd不希望被摆弄 我当前的代码如下所示: $result = mysql_query("SELECT * FROM {$table}") or die(mysql_error()); // Start a form to run insert.php echo "<form action=\"insert.php\" method=\"pos
索引
列,因为它会自动递增,ajd不希望被摆弄
我当前的代码如下所示:
$result = mysql_query("SELECT * FROM {$table}") or die(mysql_error());
// Start a form to run insert.php
echo "<form action=\"insert.php\" method=\"post\">";
// Loop to create boxes in the form
for ($i = 0; $i < $fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "{$field->name}: <br /><input type=\"text\" name=\"{$field->name}\"onkeypress=\"return noenter()\"/>";
echo "<br />";
};
// End form.
echo "<input type=\"submit\">
</form>
</div>";
for ($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
if ($field->name != "yourindexfieldname")
{
echo "{$field->name}: <br><input type=\"text\" name=\"{$field->name}\"onkeypress=\"return noenter()\"/>";
echo "<br>";
}
};
$result=mysql\u query(“SELECT*FROM{$table}”)或die(mysql\u error());
//启动一个表单以运行insert.php
回声“;
//循环以在表单中创建框
对于($i=0;$i<$fields\u num;$i++)
{
$field=mysql\u fetch\u字段($result);
回显“{$field->name}:
”;
回声“
”;
};
//结束形式。
回声“
";
从这里我怎么能忽略索引列呢。如果有帮助的话,我可以完全访问数据库
提前谢谢大家 如果不希望显示此字段,只需在生成输出之前在循环中添加一个前提条件,如下所示:
$result = mysql_query("SELECT * FROM {$table}") or die(mysql_error());
// Start a form to run insert.php
echo "<form action=\"insert.php\" method=\"post\">";
// Loop to create boxes in the form
for ($i = 0; $i < $fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "{$field->name}: <br /><input type=\"text\" name=\"{$field->name}\"onkeypress=\"return noenter()\"/>";
echo "<br />";
};
// End form.
echo "<input type=\"submit\">
</form>
</div>";
for ($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
if ($field->name != "yourindexfieldname")
{
echo "{$field->name}: <br><input type=\"text\" name=\"{$field->name}\"onkeypress=\"return noenter()\"/>";
echo "<br>";
}
};
for($i=0;$iname!=“yourindexfieldname”)
{
回显“{$field->name}:
”;
回声“
”;
}
};
像这样:
for ($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
if($field->name == 'Index') continue; //This does the trick
echo "{$field->name}: <br><input type=\"text\" name=\"{$field->name}\"onkeypress=\"return noenter()\"/>";
echo "<br>";
};
for($i=0;$iname=='Index')继续//这就是诀窍
回显“{$field->name}:
”;
回声“
”;
};
continue
语句“跳过”循环的下一次迭代。所以,我们要做的是‘如果字段名是“Index”,跳到下面的字段’
希望这有帮助。干杯您可以省略查询中的索引字段:
从{table}中选择代码>在数据库中创建一个没有索引的视图
$result = mysql_query("SELECT * FROM v_{$table}) or die(mysql_error());