开发者

mySQL insert HTML form posting problem on results... Need help

I am stumped!! I can't figure this out.

I created an HTML form that inserts a record into mySQL. It works and I can see the new records I add/insert. BUT, I get the wrong confirmation page: I get a the FAIL PAGE instead of the SUCCESS page. I see the new record but I always get taken to the fail page. Why?

Is there somethi开发者_JS百科ng wrong with the script or a setting inside mySQL?

Here is my form post script:

<? 
$host="XXXXXXXXXXXX";
$username="XXXXXXXX";
$password="XXXXXXXX";
$db_name="XXXXXXXXX";
$tbl_name="cartons_current";

mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$order = "INSERT INTO cartons_current (type, part_no, description, count, 
size, min, max, qty)

VALUES
('$_POST[type]', '$_POST[part_no]', '$_POST[description]', '$_POST[count]',
'$_POST[size]', '$_POST[min]', '$_POST[max]', '$_POST[qty]')";

$result = mysql_query($order);

$result = mysql_query($order);  //order executes
if ($result) {

$part_no = $_REQUEST['part_no'] ;

header("location: inv_fc_result_new_success.php?part_no=" . urlencode($part_no));
}
else {
header("location: inv_fc_result_new_fail.php");
}
?>


Your code looks OK, except for the possibility that mysql_query() gets called twice. If that is actual code, then I suspect the first call loads the record you are seeing, and the subsequent call returns the error message.

$result = mysql_query($order);  
$result = mysql_query($order);  //order executes 


You appear to be calling mysql_query twice. If it's not a typo in copying the code onto stackoverflow then this could be the issue.

The first call is returning true but second call is returning 'false' hence the fail page is displayed

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜