Jump to content

Yahweh

Members
  • Posts

    186
  • Joined

  • Last visited

Everything posted by Yahweh

  1. Here's my advice: ween yourself from the habit of using session variables. In fact, add this line of code to the top of your ASP pages: <%@ Language="VBScript" enablesessionstate=false %> That disables session variables on your ASP page altogether and makes your pages run much much faster.The problem with Session variables is that they only last for as long as a user's session lasts (hence the name), so they typically have a lifetime of about 20 minutes before they expire. Thats what they are designed for. Although Sessions are technically cookies, you can't manipulate them to the same extent as cookies (such as controlling when they expire), sessions are basically a very impotent form of cookies that that really irritate your users immensely by having them log in all the time. There are two general solutions to this problem:1) Start using cookies (and make sure to set their expiration dates, otherwise they're automatically session cookies). Heres a good tutorial on ASP cookies:http://www.aspit.net/tutorials/beginner/co...r_advantage.asp2) Use hidden fields to store a username and password in a form, then everytime the user sends form data you can log them back in automatically if their cookie has expired. I don't recommend doing this with links, because its a security risk.
  2. Yahweh

    select the last register

    That's a bad way to select the last registered user, because it causes MySQL to cache all of the records in the database, when it only makes use of a single record.A better SQL statement is:Select * From Your_TABLE ORDER BY ID Desc Limit 1 Basically, this just reverses the order the table and selects one record, its much faster, doesn't require MySQL to cache all the data in the table, and doesn't require an "RS.Movelast" line.
  3. Off the top of my head, I imagine this code would work if you already know the 4 fields you want to use:'connect to your databaseDim SQL, X, someVarSQL = "Select field1, field2, field3, field4 from Your_Table"Set RS = Server.CreateObject("ADODB.Recordset")RS.open Conn, sql1, 1, 1For each X in RS.Fields someVar = RS(X)Next
  4. There is no Try/Catch in VBScript, but there is one in JScript. Also, you'll generate a syntax error by using respones.write("error") instead of response.write("error"). Generally, when catching errors in ASP, you can use On Error Resume Next and use if err.number then ... end if to troubleshoot after any line which you suspect could cause a proble, or use On Error Goto 0 to stop the error right away.However, if you want to send emails, use this code:<% Option Explicit %><html><body><%Dim objCDOSet objCDO = Server.CreateObject("CDONTS.NewMail")objCDO.To = "sender@someone.com"objCDO.From = "reciever@someone.com"Dim txtSubjecttxtSubject = "Your message should go right here." objCDO.Subject = "Your subject should go here."objCDO.Body = txtSubjectobjCDO.SendSet objCDO = nothing%></body></html> If you have CDONTS installed, that code will execute without any errors.
  5. This problem is exactly what ASP Includes are for. Basically, every ASP website ever is constructed in pieces, usually with a header.asp, footer.asp, and maybe a menu.asp in between.Example Header.asp:<html><head><title>My Site</title><style>/* some style sheet goes here */</style></head><body> Example Footer.asp: <p>Some copyright notice here</p></body></html> Then, for any single page on your site, you can display it like this, example Cat.asp: <%@ Language="VBScript" enablesessionstate=false %><!--#include file="header.asp"-->I like cats, they rock![i]Miscellaneous cat appreciation goes here[/i].<!--#include file="footer.asp"--> The page above will execute, putting the code from the other files in the place where the includes are located. (Yes, there can be includes inside other includes.)Now, as for your page, I recommend doing this:1) Seperate your main functions from the rest of your code, put it in a file called global.asp. You can use <!--#include file="global.asp"--> to include those functions in any page.2) Next, if you have several different styles for your site, you can create several different files called style1.asp, style2.asp, style3.asp and so on. Then you this code to call any style: <%Dim myStylemyStyle = request.Cookies("MyCookies")("someStyle") 'The cookie should contain the value "style1.asp" or "style2.asp" or whatever the names of your style files are called.Server.execute myStyle%> You could probably call the code above inc_style.asp and include it in your header.asp.3) If you are looking to change more than just the CSS, such as chaging where elements on your page are laid out, then this technique works really well:3.1) You'll have to store your page elements in a database, where each element is its own field. So you'll have to create a database and a few tables.In the first table, add the following fields: ID, Author, DateCreated, DateEdited, Article, Title, any other desired fields.In the second table, add the following fields: ID, Template.I recommend using ID in your tables because its easier to reference rows by ID rather than by article or template title.3.2) Your template will be written in a kind of pseudomarkup language, put it will position elements on your page like this: <table><tr><td>$AUTHOR</td><td>$DATE</td></tr><tr><td colspan="2"><b>$TITLE</b><p>$Article</td></tr></table> (I usually like to use the [element] format, because its a little more human readable.)3.3) For each page, you'll have to use an SQL query to extract the ID, Author, Title, and other information into variables like this: <%Author = rs("Author")Title = rs("Title")Article = rs("Article")' You might have to execute another SQL query to retrieve the template from the other tableTemplate = rs("Template")'...etc. ...%> 3.4) Now that you have all your data, you can start making replacements: <%Template = replace(Template, "$AUTHOR", Author, 1, -1, vbTextCompare)Template = replace(Template, "$TITLE", Title, 1, -1, vbTextCompare)Template = replace(Template, "$Article", Article, 1, -1, vbTextCompare)Template = replace(Template, "$DATE", Date, 1, -1, vbTextCompare)'...etc. ...'After all of the replacements are done, just print your Template variableReponse.write Template%> The first 2 options are consistent with having normal looking URLs. The third option requires you to use a URL like article.asp?id=10 or something similar, although it technically is possible to have normal looking URLs if you're willing to recycle the same code over and over for each page.
  6. Yahweh

    dynamic table

    Glad you learned about response.BinaryWrite in time, however displaying the images in a dropdown list usually requires some CSS, something that looks like this:<select name="products"><option value="1" style="height : 100px; background-image : url(someimage1.gif);"></option><option value="2" style="height : 100px; background-image : url(someimage2.gif);"></option><option value="3" style="height : 100px; background-image : url(someimage3.gif);"></option><option value="4" style="height : 100px; background-image : url(someimage4.gif);"></option><option value="5" style="height : 100px; background-image : url(someimage5.gif);"></option></select> If that doesn't work, you can try displaying the images in a table (you can use Javascript to collapse/expand parts of the table).
  7. This is exactly what databases are for. It is possible to save information to an Excel or a text file, but it isn't as cut-and-dry as using a simple database.The number of clients expected to be accessing a database at any given time will determine the type of database you want to use. If you don't expect more than, say, 10 people be simultaneously connecting to a database at any given time, then you can safely use an MSAccess database. Otherwise, use MySQL or PostGres.About a month ago, someone asked me how to make a script that stores errors, which does exactly the same function that you want from script, but you want the database to store hours instead. Maybe the error script will help you out as a reference:- Working version of error script.- Zip of all the files used in that script.With a few minor changes, such as changing the name and datatype of at least one field, and changing the name of the field in the ASP scripts, the script will do exactly what you want it to do.
  8. Well actually I write content management systems in my spare time, and I could probably whip a Friendster in about a week. There are actually pretty good reasons why a person would want to create a site like that, namely on the basis that they get millions of hits a day and just a single Google ad on each page can generate a lot revenue (about 5500 hits per day average US$1 in Google Ad revenue, so having hundreds of times the traffic earns hundreds of times the income).But if you are a newbie ASP programmer, then the task of creating that kind of site requires such insane amounts of overhead that'd you'd never be able to do it. I recommend starting a little smaller, perhaps by writing a messageboard. However, if you are up to the challenge, then here's the information you need:Linking pages together is easy, it usually requires a session object. But personally, I really dislike Session Objects, they slow down page processing and rarely last for more than 20 minutes; after that, a user has to log in again. Use cookies instead.Sessions and Cookies are the same thing, but a Cookie is a textfile that stays on a clients computer, and a session deletes itself after the client's session has ended (usually after 20 minutes).Heres some information on ASP cookies:http://www.aspwebpro.com/aspscripts/miscel...ookiebasics.aspAfter a user logs in, use this code to set a cookie:<% Response.Cookies("MyCOOKIE").Domain = "www.yourdomain.com"Response.Cookies("MyCOOKIE").Expires = Date() + 1Response.Cookies("MyCOOKIE")("Username") = UsernameResponse.Cookies("MyCOOKIE")("Password") = Password%> After the cookie is set, use this code to access the cookie: <% DIM strUsername, strPasswordstrUsername = Request.Cookies("MyCOOKIE")("Username")strPassword = Request.Cookies("MyCOOKIE")("Password")response.write "Hello, " & strUsername%>
  9. Use the CStr function. Example:<%=cstr(250)%> And to convert the string back into a number, use CInt.
  10. Yahweh

    hello

    Among other things, you can't have an anchor tag embeded inside the attribute of your input tag, and "action" isn't an attribute of buttons. And unless dconn_rla.asp is a javascript snippet, then it doesn't have a purpose being in the onClick event of your button. In other words, you don't have valid HTML syntax at all.Also, you're going to get nothing but syntax errors because the VBScript comparison operator is one equal sign ("="), not two ("=="). So the line objConn == "true" is wrong. And if you're checking something that is true or false, or something that a boolean value, don't put the word "true" or "false" in quotations. The correct syntax is objConn = True. And you cannot use HTML within your ASP tags, you need to precede those statements with response.write "<a href....>sometext</a>", otherwise you'll get syntax errors.To get the results you want, use this code instead:<%Dim myURLIf objConn.state then 'Is the connection open? myURL = "http://127.0.0.1/muneet/l_QuerymainP.asp"else myURL = "http://127.0.0.1/muneet/puneet.asp"end if%><form action="<%=myURL%>" method="post"><input type="submit" value="Submit"></font>
  11. Very likely, the author of the website you were viewing put his site in frames. Example: <frameset rows="50,*"> <frame name="Top" src="top.asp" marginwidth="10" marginheight="10" scrolling="no" frameborder="0"> <frame name="bottom" src="bottom.asp" marginwidth="10" marginheight="10" scrolling="auto" frameborder="0"></frameset> The URL in the browser is always the URL of the topmost window, and in this case the topmost window houses two frames, so you'll see the URL of that window instead of the URLs of the frames. When clicking links in a frame, unless you specifically set your href's target="_top", then you'll never see the URL change.
×
×
  • Create New...