Jump to content

gueland

New Members
  • Posts

    5
  • Joined

  • Last visited

About gueland

  • Birthday 10/04/1961

Profile Information

  • Gender
    Male
  • Location
    Brandon, Manitoba, Canada

gueland's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have been using a tutorial from udemy and have reached a point where we are adding to the cart using the IP address of the user. The scripts in the functions.php work EXCEPT for the cart() function. It just blinks the page but does not add the items to the database table cart. The instructor is not getting back to me in the feedback function of the course. Can you help? Here is the code written: function getIp() { $ip = $_SERVER['REMOTE_ADDR']; if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } return $ip; } function cart() { if(isset($_GET['add_cart'])) { global $con; $ip = getIp(); $pro_id = $_GET['add_cart']; $check_pro = "select * from cart where ip_add='$ip' and p_id='$pro_id'"; $run_check = mysqli_query($con, $check_pro); if(mysqli_num_rows($run_check)>0){ echo ""; } else { $insert_pro = "insert into cart (p_id,ip_add) values ('$pro_id','$ip')"; $run_pro = mysqli_query($con, $insert_pro); echo "<script>window.open('index.php','_self')</script>"; } } } The database connection is not written in this, but it does work for the other functions, like adding products for example. I am running Windows 10, with MySQL, Apache, PHP5. I cannot go any further until I resolve this. Please help. Thank you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.