开发者

Problems implementing "Save" feature on website

Here's my code:

<?php 
session_start();
$currentPage = $_POST["currentPage"];
$passedCoupID = $_POST["passedCoupID"];
/*
if youre logged in, save

if not, take you to the register page with an option to go right back to the coupon if you dont want to register

*/

$con = mysql_connect("localhost","admin","admin");
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("users", $con);

if($_SESSION["loggedIn"] == 1)
    {
        $userID = $_SESSION["userID"];
        mysql_query("开发者_开发百科INSERT INTO users_saves (userID, couponID) VALUES ('$userID', '$couponID')");
        mysql_select_db("coupons", $con);
        mysql_query("UPDATE stats SET saves = saves + 1 WHERE id = '$couponID'");
        header('Location: ' . $currentPage);
    }
else
    {
        header('Location: register.php');
        $_SESSION["goBack"] = $currentPage;
    }
?>

What I'm trying to do is when the user clicks the "Save" button on a page, it will go to this form, which will insert both the user's ID and the coupon's ID into the table users_saves. Then I want it to change databases and increment the row saves at the id of the saved coupon. It looks fine to me, and it works without errors, but it writes 0, 0 to the table users_saves instead of either of the values, and I'm not sure why. Also, there is no increment of saves when I do the database switch.


Well, your variable seems to be called $passedCoupID, while in the sql you are referencing $couponID

that might be your problem right there. You should turn on all errors, then you'll probably see a lot of "notice" errors in your code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜