Jump to content

horseatingweeds

Members
  • Posts

    119
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

horseatingweeds's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks AyKay47. I had a feeling it was something like this. I looked up "JavaScript reserved words" and found nothing indicating 'clear'.
  2. Weird. I found the problem. It was the use of 'clear' as the function name. I changed it to 'test' and now to 'clean' and the same code runs and works properly. I wonder why that is.
  3. Thanks AyKay47, I put an alert() statement in the top of the clear() function, and it does not appear when I click the 'clear' button, so I guess the JavaScript isn't running at all. Does that mean the problem is in how I'm calling it in the html? <form action=""> Integer: <input id="int" type="text" onkeyup="convert(this.value)" /> <p> Binary: <span id="binary"></span> </p> <p> Hexadecimal: <span id="hex"></span> </p> <input type="button" value="Save" id="1" name="1" onclick="save()" /> <input type="button" value="Clear" id="2" name="2" onclick="clear()" /> </form> The php script is working properly when I call it directly ("script.php?r=c"), so the problem is not likely there. Here it is thought: <?php ini_set('display_errors',1); error_reporting(E_ALL); //get the q parameter from URL $q=$_GET["q"]; $r=$_GET["r"]; if ($r == 'h') { if ($q=='') $response = "No conversion."; else if ($q > 4294967295) $response = "To large to convert!"; else $response = dechex($q); } else if ($r == 'b') { if ($q=='') $response = "No conversion."; else if ($q > 4294967295) $response = "To large to convert!"; else $response = decbin($q); } else if ($r == 's') { $filename = 'data.txt'; $q=$_GET["q"]; if ($q=='') $content = $q . "No conversion."; else if ($q > 4294967295) $content = $q . "To large to convert!"; else { $content = $q . "|" . decbin($q) . "|" . dechex($q) . "\n"; } // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $content) === FALSE) { echo "Cannot write to file ($filename)"; exit; } fclose($handle); $handle = fopen($filename, 'r'); $response = fread($handle, filesize($filename)); fclose($handle); } else { echo "The file $filename is not writable"; } } else if ($r == 'c') { $filename = 'data.txt'; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; } if (fwrite($handle, "") === FALSE) { echo "Cannot write to file ($filename)"; exit; } fclose($handle); $response = ""; } } else $response = "Didn't clear!"; //output the response echo $response; ?>
  4. Ok, here is the Ajax: function clear() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("readout").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", "script.php?r=c", true); xmlhttp.send(); } Here's the html: <div id="container"> <h2>Integer Converter</h2> <div class="calculator"> <form action=""> Integer: <input id="int" type="text" onkeyup="convert(this.value)" /> <p> Binary: <span id="binary"></span> </p> <p> Hexadecimal: <span id="hex"></span> </p> <input type="button" value="Save" id="1" name="1" onclick="save()" /> <input type="button" value="Clear" id="2" name="2" onclick="clear()" /> </form> </div> </div> <div id="readout"> </div> Here is the piece of the php script, although, like I said, it works when I access it directly: else if ($r == 'c') { $filename = 'data.txt'; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; } if (fwrite($handle, "") === FALSE) { echo "Cannot write to file ($filename)"; exit; } fclose($handle); $response = ""; } }
  5. https://crux.baker.edu/~bwarri01/cs332a/w4/ajax_project I'm putting this together for a class, that's why it is so contrived. It's a simple integer converter, to hexadecimal and binary, on onkeyup for the text input, using a php script to do the converting. There's also a 'save' button that saves the numbers to a text file. All of this works well enough. I've also added a 'clear' button to clear the file--which isn't working. I'm using two GET variables. q carries the integer and r carries the indicator to the php script telling it what to do. The php script that clears the text file works if I visit it directly: https://crux.baker.edu/~bwarri01/cs332a/w4/ajax_project/script.php?r=c So I guess the request isn't being made by the JavaScript for some reason, or perhaps I'm not calling it properly. I don't know. I could use some advice. Thanks
  6. The way I exported it from phpmyadmin was, it gave me a text box with the sql in there. I copied it to a text file.
  7. Thanks discomatt. Magic_quotes_gcp = 1 That setting must have been the difference in my two setups. It looks like that was causing some other problems for me too.
  8. I exported some tables off a database using phpmyAdmin on my test environment, Apache on Win. I then imported it into the same kind of database on a Linux server. All the character such a slashes and apostrophes turned into question marks. Anyone know what's happening here?
  9. Thanks ProjectFear, I think my framework uses mysql_real_escape_string(). I'll give stripslashes() a try. Do you know why the slashes only appear on the Linux server?
  10. I run Apache on a Windows setup for testing but publish on a Linux server. I use a text area and text inputs to add information and create pages. On Windows/Apache I had it working fine. After moving it to Linux apostrophes were escaped in the output, and only if I typed them is. Pasting them, they were not escaped. Example: Bill's shows up as Bill/'s I'm not sure what code to show. I'm just loading the input value into a database, then outputing it into an html template. I've removed the filters to see if I had something funny in there, but no change. I'm thinking this must be something with how Linux treats text. Any ideas?
  11. But is a preg_match allowing only numbers, letters, and -'s thorough enough? It seems so.
  12. If you're using values from the url, should they be treated with security measures? Is just a if(preg_match*** thorough enough, like only letters numbers and '-' ?
  13. Yeah, I know what you mean. I couldn't get anywhere with this last night. Here it's half past six, and I've come up with something. It's similar to yours wildteen88 by using Smarty code - thanks. <ul> <li>{$test.0.breed_name} {assign var='categ' value=$test.0.breed_name} <ul> {foreach from=$test item=t} {if $categ != $t.breed_name} </ul> </li> <li>{$t.breed_name} <ul> {/if} <li><a href="{geturl action='preview'}?id={$t.article_id}}">{$t.breed_name}/{$t.url}</a></li> {assign var='categ' value=$t.breed_name} {/foreach} </ul> </li> </ul>
  14. OK public static function GetArticleArray($db) { $select = $db->select(); $select->from(array('a' => 'breed_articles'), array('a.article_id', 'a.breed_name', 'a.url')); $select->order('a.breed_name'); $data = $db->fetchAll($select); foreach ($data as $d) { $listing[$d['article_id']] = $d['breed_name']; } return $data; } I'm not sure explaining how the array is defined will help, but I'm passing the $data variable to a Smarty template. <ul> {foreach from=$test item=t} {if $categ != $t.breed_name} <li>{$t.breed_name}</li> {/if} <li><a href="{geturl action='preview'}?id={$t.article_id}}">{$t.breed_name}/{$t.url}</a></li> {assign var='categ' value=$t.breed_name} {/foreach} </ul> From this controller: public function indexAction() { $test = DatabaseObject_BreedArticles::getArticleArray($this->db); $this->view->test = $test; } I'm using Zend Framework. I'm just trying to figure an efficient way to make a nested ul out of this array. I think the first thing I need to do is figure out what kind of array will work best for making the ul, then figure out how to make the current array into it.
×
×
  • 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.