Jump to content

Convert for mssql


Ermac222

Recommended Posts

Hello to everyone !

 

I had i votebar system for my site using mssql database:

 

I use ready system which use mysql. I want to work with mssql database.

So there is the system.

 

mysql.sql

CREATE TABLE `bgtop` (
`ip` varchar(33) default NULL,
`ctime` varchar(33) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=cp1251;

 

 

conf.php

<?
$server = "localhost";
$dbuser = "username";
$dbpass = "password";
$dbname = "vote";
$dbtable = "bgtop";
$db_conn = mysql_connect($server, $dbuser, $dbpass);
@mysql_select_db($dbname, $db_conn) or die(mysql_error());
$ip = $_SERVER["REMOTE_ADDR"];
$link = "http://bgtop.net/in.php/123456789";
$time = time();
$vtime = "86400"; 
$dtime = "345600";
function show() {
echo '<a href="vote.php"><div style="width: 100%; height: 22px; position: absolute; top: 0px; left: 0px; z-index: 100; background-color: #ddd; text-align: center; font-size: 15px;">Press here to vote for us!</div></a>';
}
?> 

 

 

index.php

<?
include("conf.php");
$sql = mysql_query("SELECT ctime FROM $dbtable WHERE ip=\"$ip\"");
if($row = mysql_fetch_array($sql)) {
$calc = $row['ctime'] + $vtime;
if ($calc < $time) { show(); }
}
else { show(); }
?> 

 

vote.php

<?
ob_start();
include("conf.php");
$sql = mysql_query("SELECT ctime FROM $dbtable WHERE ip=\"$ip\"");
if($row = mysql_fetch_array($sql)) {
$calc = $row['ctime'] + $vtime;
if ($calc > $time) { echo "You can vote only once in 24 hours!"; }
else {
$sqlQ = mysql_query("UPDATE $dbtable SET ctime = \"$time\" WHERE ip=\"$ip\"");
header("location: $link");
}
}
else {
$sql = mysql_query("INSERT into `$dbtable`(`ip`,`ctime`) VALUES ('$ip','$time')");
header("location: $link");
}
?>

 

Can someone help me to convert this system to work with mssql?

 

I manage to convert only this:

 

CREATE TABLE [bgtop] (
[ip] [varchar] (33) default NULL,
[ctime] [varchar] (33) default NULL
)
GO

 

conf.php

<?
$host = "localhost";
$username = "username";
$password = "password";
$database = "database";
$dbname = "vote";
$dbtable = "bgtop";
mssql_connect($host, $username, $password);
mssql_select_db($database);
$ip = $_SERVER["REMOTE_ADDR"];
$link = "http://bgtop.net/in.php/123456789"; // тук посочи твоя линк.
$time = time();
$vtime = "86400"; // това е времето в секунди, за което ще може да се гласува. в случая е 24 часа.
$dtime = "345600"; // времето, след което ще се изтриват ненужните записи. в случая е 4 дни(72 часа)
function show() {
echo '<a href="vote.php"><div style="width: 100%; height: 22px; position: absolute; top: 0px; left: 0px; z-index: 100; background-color: #ddd; text-align: center; font-size: 15px;">Натисни тук за да гласуваш за сайта </div></a>';
}
?> 

 

P.S Sorry for my bad English!

Link to comment
https://forums.phpfreaks.com/topic/167775-convert-for-mssql/
Share on other sites

So i mange to record information in the db but i have problem:

 

here is the vote.php

<?
ob_start();
include("conf.php");
$query = mssql_query("SELECT ctime FROM bgtop WHERE ip=\"$ip\"");
if($row = mssql_fetch_array($sql)) {
$calc = $row['ctime'] + $vtime;
if ($calc > $time) { echo "You can vote only once in 24 hours!"; }
else {
$update = mssql_query("Update bgtop set ctime = \"$time\" WHERE ip=\"$ip\"");
header("location: $link");
}
}
else {
$insert = mssql_query("INSERT INTO bgtop (ip, ctime) VALUES('$ip','$time')"); 
header("location: $link");
}
?>

 

 

This part just dont work

if($row = mssql_fetch_array($sql)) {
$calc = $row['ctime'] + $vtime;
if ($calc > $time) { echo "You can vote only once in 24 hours!";

Link to comment
https://forums.phpfreaks.com/topic/167775-convert-for-mssql/#findComment-884760
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.