Jump to content

bennyboywonder

Members
  • Posts

    45
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bennyboywonder's Achievements

Member

Member (2/5)

0

Reputation

  1. am I the only one that thinks this would be a bit of a security risk, anyhow? if you manage to get js to send PHP code stored in a js variable, you must remember that the person browsing your site could easily read the code, find out the name of this variable and type "javascript: myvar = 'some_damageing_php_code; here()'" into the address bar, and then find the bit of the script that sends it off to your server and run that. This could lead to some real nasty stuff....
  2. Hey. I don't know if I am using a different version of php to you, but I always use session variables in a different way <?php session_start(); session_register('myvar'); this registers the normal php variable $myvar as a session variable. The value will be avaliable to all pages, so you can set it like this <?php $myvar = "loggedin"; ?> and test for it like this <?php if($myvar) { echo "user is logged in! YAY!"; } ?> Hope this helps
  3. currently I use the SQL statement $query = "INSERT INTO items (user, refId, itemType, itemName) VALUES ('$sessUser', $maincat, 4, '$name')"; to add certain items to my database. In this table, their is an auto_incrementing primary key. Is their a way of having this same sql statement also return the primary key for the row that the data is placed into?
  4. Because it's lazy, and prone to errors... the worst is when people put it on another line, then add another statement, and don't realize that the 2nd statement will always run, becase it's not covered by the if(). Always use the braces -- JS, unlike Perl, does not have a true inline if, so you shouldn't code like it does. but assuming I don't make what sounds like an *extremely stupid* mistake, then, it doesn't make any difference?
  5. I am trying to make a cross-browser getById and getStyle function to use with my other javascripts; at present to use these in conjunction with each other, I would have to write it like this var mystyle = getStyle(getById("addcat")) I think function getById(whichLayer) { this.getStyle = getStyle; object = document.getElementById ? document.getElementById(whichLayer) : document.all ? document.all[whichLayer] : document.layers ? document.layers[whichLayer] : false; return object } function getStyle(obj) { var object = obj.style ? obj.style : obj; return object; } is their a way of writing an object so that I could use standard dot syntax, ie var mystyle = getById("addcat").getStyle; I was thinking something along the lines of var browsers = new browserObject(); var mystyle = browsers.getById("myid").style; mystyle.left = "10"; function browserObject() { this.getById = function(whichLayer) { this.style = getStyle; object = document.getElementById ? document.getElementById(whichLayer) : document.all ? document.all[whichLayer] : document.layers ? document.layers[whichLayer] : false; return object } } function getStyle(obj) { var object = obj.style ? obj.style : obj; return object; } though this is just a guess of the sort of thing I am after, and I know this doesn't work.
  6. ok. ignore this, I am a moron. I had previously already defined two blank startdrag functions as placeholders and it was calling them instead
  7. *edit* ok, this is a small part of a script from a tutorial, and when I move document.onMouseDown=startDrag; document.onMouseUp=stopDrag; outside of the window.onload handler (wasn't sure why he did that anyway) then it works. HOWEVER this only works when I include it in the main HTML document. If the script is imported via a js file, it doesn't work *edit* trying to do a drag and drop script for my website. Halted at the very outset. this just WILL NOT WORK. help me here function startDrag(e) { alert("dragging started"); } function stopDrag(e) { alert("dragging stopped"); } window.onload = function() { document.onMouseDown=startDrag; document.onMouseUp=stopDrag; }
  8. I just thought I would check something. Whenever I write an IF (or other control structure) if the resulting code is only one line, I tend not to bother with the curly braces, as it seems to make no difference as to how the code is executed. I have recently seen some examples written and noticed that these people have put the curly braces in regardless. Does this matter? e.g. is if(myval == 1) alert("myval is 1"); exactly the same as if(myval == 1) { alert("myval is 1"); } cos it certainly seems to run the same. Or is this just a conventions thing?
  9. how would I go about doing loop like this inside a class then?
  10. presumably that would be a hidden div containing some sort semi transparent gif which is displayed using the onSubmit handler? Personally I find it easier to have the onSubmit handler call a function which disables the button (or the fields as well if you wish) document.formname.buttonname.disabled = true
  11. ok. I have been creating a javascript class for ajax calls. part of the class is going to be a method that calls the load method then loops back on itself. however whenever I try to execute one method from inside the loop method, I just get errors. here is the code in question htRequest.prototype.startLoop = function(lTime, obj) { setInterval("this.load()", 1000); } and here is the entire class code. The errors I keep getting (when adding try/catch handlers) are things like "this.load is not an object" etc etc etc HELP ME PLEASE this is annoying the SHIT out of me /********************/ function htRequest(page, baseQuery, rType, method, loopTime) /* - my xmlHTTPrequest class constructor variables: STRING page - the page to make the request to STRING baseQuery - the initial querystring to send to server not including any additional variables added to the object instance later STRING rType - the type of data the call will return. Currently either "json", "xml" or "text"; INT method - which httprequest method to use. 1, 2 or 3 for "GET" "POST" or "HEAD" respectively INT loopTime - how long in milliseconds to wait before looping the callback function; /*******************/ { htRequest.prototype.constructUrl = function() // Construct the url for a GET call { if(this.baseQuery) { this.query = this.baseQuery; if(this.addQuery) this.query += "&" + this.addQuery; } else if(this.addQuery) this.query += this.addQuery; if(!this.query || this.method != "GET") this.url = this.page; else this.url = this.page + "?" + this.query; return this.url; } // Sends the xmlHTTPrequest htRequest.prototype.load = function() { var rLoaded = this.reqLoaded; var eHandle = this.errorHandler; var callType = this.callType; var rType = this.rType; this.constructUrl(); var http = createXMLHttpRequest(); http.open(this.method, this.url, true); if(this.method == "POST") http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); http.onreadystatechange = function() { if (http.readyState != 4) return; if (http.status != 200) { if (eHandle) eHandle(http.status); return; } switch(rType) { case "json": var response = eval('('+ http.responseText +')'); break; case "xml": var response = http.responseXml; break; case "text": var response = http.responseText; } if(rLoaded) rLoaded(response); } if (this.method == "POST") var sendString = this.query; else var sendString = null; http.send(sendString); if(this.whileLoading) this.whileLoading(); } // Start a callback loop that executes the send method every (loopTime) milliseconds htRequest.prototype.startLoop = function(lTime, obj) { setInterval("this.load()", 1000); } //Initialise variables if (rType) this.rType = rType; else this.rType = "json"; // JSON is the default response type this.loopTime = loopTime; if (!method) method = 2; switch(method) { case 1: this.method = "GET"; break; case 2: this.method = "POST"; break; case 3: this.method = "HEAD"; break; } this.baseQuery = baseQuery; this.addQuery = null; this.page = page; this.constructUrl(); }
  12. The following script should echo a hyperlink containing a random quote looked up from a table on your database named translate (obviously you can call it what you want, as with the column names as well) the table needs to have three columns, one english (named english in my script) one spanish (named spanish in my script) and one auto incrementing primary key (named qId in my script). When you click the link, the page should reload with the translation instead. Be aware that I havn't tested this, so if it doesn't work, tell me what it says... <?php $dbhost = "myhost"; $dbuser = "myuser"; $dbpass = "mypass"; $dbname = "mydbase"; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to Mysql'); mysql_select_db($dbname) or die('cannot select database'); if(!$_GET) { // If no variables have been passed to the script through the url $query = "SELECT COUNT(qId) AS count FROM translate"; // Set the query string to count how many entries $result = mysql_query($query); $row = mysql_fetch_row($result); $select = rand(1, $row['count']); // generate a random number between 1 and the count value created earlier $query = "SELECT english FROM translate WHERE qId=$select"; // this counts how many entries are in the database $result = mysql_query($query); $row = mysql_fetch_row($result); echo "<a href='" . $_SERVER['PHP_SELF'] . "?translate=$select'>" . $row[0] . "</a>"; } else { $query = "SELECT spanish FROM translate WHERE qId=$_GET['translate']"; $result = mysql_query($query); $row = mysql_fetch_row($result); echo $row[0]; } mysql_close($conn); ?>
×
×
  • 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.