javascript - Page count function -


every time visit index page need check if record exists in database, if does, need update field 'count' if not add row.

i've managed create row on visit, cant seem update count if row exists.

// create connection  $conn = mysqli_connect($servername, $username, $password, $dbname);  // check connection  if (!$conn) {      die("connection failed: " . mysqli_connect_error());  }    // check see if record exists  $sql = "select * page_tracking name ="index.php"";  if (mysqli_query ($conn, $sql)) {  	$sql= "update page_tracking set count=count+1 name= "index.php")";  }    else if {  //insert query  $sql = "insert page_tracking (name, count)  values ('index.php', '1')";   }  if (mysqli_query($conn, $sql)) {      echo "thanks visiting! visit has been recorded";  } else {      echo "unfortunately unable record visit: " . $sql . "<br>" . mysqli_error($conn);  }

there's simple explanation! issue code 'check see if record exists'

1) dont use double quotes around index.php use single quotes. run update query

    $sql = "select * page_tracking name ="index.php"";     $result =  mysqli_query ($conn, $sql);     $num_rows = mysqli_num_rows($result);     if ($num_rows) {         $sql= "update page_tracking set count=count+1 name= 'index.php'";      }else{     $sql = "insert page_tracking (name, count) values ('index.php', '1')";  }  if (mysqli_query($conn, $sql)) {     echo "thanks visiting! visit has been recorded"; } else {     echo "unfortunately unable record visit: " . $sql . "<br>" . mysqli_error($conn); } 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -