Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server Side

Status
Not open for further replies.

markemark

Instructor
Nov 11, 2003
21
GB
Hiya,
I have written a search facility that looks through an access database saved on a web server and the client will end up knowing if a date is available to take a holiday to their chosen destination.

The problem is that if the database is local then no problem but if the database is on a web server then jscript errors, trying to resolve a netbios name rather than a http request.

I know there are two sides of java, client and server, and I think that I need some server side code but do not know how to code it or where to place it as the website is on geocities and I do not have any physical access to the server.

here is the java script code I have at the moment.

<SCRIPT language=&quot;JavaScript&quot;>

function searchdb(form) {
// varible init section
var TADB // tadb is the varible for the database
var ConnectionString // connectionstring is the adodbc string
var strSQL // strsql is the sql statement storage
var recnum // record number
var housenm // house name field
var startdate //holiday start date
var noofnights // number of nights field
var inc //incremental count for loop
var incinner //incremental count for loop
var prevdate //previous date for searching
var searchydate //check all permutations of date
var finalresult //if =1 then already booked
Form1.elements(6).value = &quot;Checking, Please Wait&quot;;

TADB = new ActiveXObject(&quot;ADODB.Recordset&quot;); // Create the Recordset Object
ConnectionString = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\\\uk.geocities.com\\cypruspremiervillas\\available.mdb&quot;;
strSQL = &quot;SELECT * FROM holiday ORDER BY startdate DESC&quot;;// Build a SQL statement
TADB.Open(strSQL, ConnectionString, 3,1,1);// Open the recordset

// init finalresult
finalresult = 0;
// Loop through the Recordset
while(!TADB.EOF)
{
// Load date and house name variables from the Recordset
recnum = TADB.Fields.Item(0).Value;
housenm = TADB.Fields.Item(1).Value;
startdate = TADB.Fields.Item(2).Value;
noofnights = TADB.Fields.Item(3).Value;
//alert (recnum+housenm+startdate+noofnights)
// Set default value
if (housenm == null) {
housenm = 0;
}
else {
// if house field is populated then do this..
// if database has an entry that matches the drop down box then
if (housenm == Form1.elements(0).value)
{
for (inc=0; inc<Form1.elements(3).value; inc++)
{
//add days onto database booked date
var mday = Form1.elements(2).value.substr(0,2);
var mmonth = Form1.elements(2).value.substr(3,2)-1;
var myear = Form1.elements(2).value.substr(6,4);
var newDate = new Date(myear,mmonth,mday);
var newtimems=newDate.getTime()+(inc*24*60*60*1000);
newDate.setTime(newtimems);
var year=newDate.getYear();
var month=newDate.getMonth()+1;
var day=newDate.getDate();
var outerfindate = day+&quot;/&quot;+month+&quot;/&quot;+year;
prevdate = newDate;

for (incinner=0; incinner<noofnights; incinner++)
{
// replacement for addays
var mday = startdate.substr(0,2);
var mmonth = startdate.substr(3,2)-1;
var myear = startdate.substr(6,4);
var innerfindate = mday+mmonth+myear;
var newDate = new Date(myear,mmonth,mday);
var newtimems=newDate.getTime()+(incinner*24*60*60*1000);
newDate.setTime(newtimems);
var year=newDate.getYear();
var month=newDate.getMonth()+1;
var day=newDate.getDate();
var innerfindate = day+&quot;/&quot;+month+&quot;/&quot;+year;
searchydate=newDate;
//end of replacement

if (outerfindate == innerfindate)
{
finalresult=1;
}
}


}
}


}

// Go to the next Record
TADB.MoveNext();

};

// Close the Recordset
TADB.Close();


if (finalresult == 1)
{
Form1.elements(6).value = &quot;Villa unavailable, sorry&quot;;
}
else
{
Form1.elements(6).value = &quot;Villa is available&quot;;
}
}
//endofunc


If anyone has any idea where I go from here then that will be very appreciated.

Regards

Mark
 
Are you doing this via .jsp/.asp or regular .htm? I recommend that you look in some of the FAQs of the ASP forum333 to see how to access the database...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
all through htm, if I go via asp or jsp will that require a total re-write of my code?
 
When you want a central database for your site, you need to do it server-side (unless each client has the db you require located locally on their computer - VERY UNLIKELY). You should read-up on server-side code. I recommend ASP as it is more widely used. Other options as are ColdFusion, JSP (java server pages), and PHP.

Once you read up on them, you will see that a total rewrite shouldn't be necessary (still connect to DB and load a recordset). However, you will need to get used to server-side vs. client-side issues...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
do you know where i can get more information on jsp?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top