我想在用户插入的值小于指定值时显示警告框。此指定值取自数据库。我是php的新手,所以我没有弄错这段代码。
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("gunjanbid", $con);
$username=$_SESSION['userName'];
$id=$_SESSION['id'];
$result = mysql_query("SELECT * FROM bids WHERE id =$id");
//$query=mysql_query("SELECT * FROM bid
$numrow = mysql_num_rows($result);
while($row=mysql_fetch_array($result))
{
]
$bidfee=$row[5];
}
?>
<?php
echo '<script type="text/javascript">';
echo "function validateForm1()";
{
echo "var c=document.forms['auction1']['fir'].value";
echo "var d=document.forms['auction1']['bidamount'].value";
if echo "( c==null || c=="" )";
{
echo "alert('UserName must be filled out')";
echo "return false";
}
echo "else";
{
echo "if(c<$bidfee)"
{
echo "alert('Bid can not be less than Bid fee')";
echo "return false";
}
}
echo "if (d==null || d=="")";
{
echo "alert('UserName must be filled out')";
echo "return false";
}
echo "else";
{
echo "if(d<$bidfee)";
{
echo "alert('Bid can not be less than Bid fee')";
echo "return false";
}
}
}
echo "</script>";
?>
<form action="multiplebid.php" name="auction1" onsubmit="return validateForm1()" method="post" >
<input type="hidden" name="description" value="" >
<input type="hidden" name="closing_date" value="" >
<input type="text" name="fir" value="" size="5" >
<input type="text" name="sec" value="" size="5" ></td><td> </td><td><input type="submit" name="submit" class="button" value="Bid Now" ></form>
上面的代码没有显示警告框并显示错误,语法错误,意外T_ECHO,期待'('在C:\ wamp \ www \ old \ detailproduct.php第426行 或者如果有任何其他方式显示警告框,那么请帮助我。
答案 0 :(得分:0)
尝试以下代码:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("gunjanbid", $con);
$username=$_SESSION['userName'];
$id=$_SESSION['id'];
$result = mysql_query("SELECT * FROM bids WHERE id =$id");
$numrow = mysql_num_rows($result);
while($row=mysql_fetch_array($result))
{
$bidfee=$row[5];
}
?>
<script type="text/javascript">
var bidfee = '<?php echo $bidfee;?>';
function validateForm1(){
var c=document.forms['auction1']['fir'].value;
var d=document.forms['auction1']['bidamount'].value;
if ( c==null || c=="" ){
alert('UserName must be filled out');
return false;
}else{
if(c<bidfee){
alert('Bid can not be less than Bid fee');
return false;
}
}
if (d==null || d==""){
alert('UserName must be filled out');
return false;
}else{
if(d<bidfee){
alert('Bid can not be less than Bid fee');
return false;
}
}
}
</script>
<form action="multiplebid.php" name="auction1" onsubmit="return validateForm1()" method="post" >
<input type="hidden" name="description" value="" >
<input type="hidden" name="closing_date" value="" >
<input type="text" name="fir" value="" size="5" >
<input type="text" name="bidamount" value="" size="5" ></td><td> </td><td><input type="submit" name="submit" class="button" value="Bid Now" >
</form>