通过带有列号的发布请求选择MySQL限制列

时间:2015-03-26 20:41:17

标签: php mysql post

我试图通过发送PHP帖子请求到列号为

的MySQL来获取MySQL列

PHP:

<?php

$columns = $_POST['number'];     

$result = mysql_query(" SELECT * FROM table3 order by RAND() LIMIT '$columns'");

?>

HTML:

<form action="file.php" method="post" >
    <input type="text" name="number" value="5" autocomplete="off">

    <input type="submit" Value="Submit">
</form>

1 个答案:

答案 0 :(得分:1)

你在说

SELECT * FROM table3 order by RAND() LIMIT '5'

查看报价问题?

应该是

<?php
$columns = (int)$_POST['number'];     
$result = mysql_query(" SELECT * FROM table3 order by RAND() LIMIT $columns");
?>