Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
I'm surprised your query isn't failing! You are trying to run the query in the variable $query - but it hasn't been defined. Instead you defined the query in the variable $sql. But, I am confused as to why you would be running mysql_num_rows() against the result since the query is to CREATE a table, so I don't see how there would be any rows returned.
-
Either I am not understanding you or you are making this more difficult than it needs to be. You are apparently alble to convert the time entered by the user to the appropriate UTC timestamp. The whole point of using UTC is to ensure you are storing the time in a mormalized format. So, when you need to query the database, just offset the timestamps you use as needed for the local time of the server.
-
get list of processes running on client machine
Psycho replied to dmikester1's topic in PHP Coding Help
In short no. I assume the PowerPoint is a prepatory document for the test and they are not supposed to refer to it during the test. Even if you could ensure they close the document or only made the content avaiable in a web page, you couldn't prevent the user from copying the content or taking screen captures of it. -
What do you mean by "...I am not getting anything.". Did you check that the query ran successfully? were there records returned? What? There is nothing in the code above that would DO anything. You need to echo/output the results in some way. Plus, the mysql_result() function above is trying to access the second record. Try the following: mysql_select_db($database_ballot, $ballot); $sql = "SELECT party, COUNT(party) as total FROM votes GROUP BY party"; $result = mysql_query($sql); if(!$result) { echo "The query failed: " . mysql_error(); } elseif() { echo "No results returned"; } else { while($row = mysql_fetch_assoc($result)) { echo "{$row['party']}: {$row['total']}<br />\n": } }
-
Not sure what you are trying to achieve really. Why are you wanting to change the timezone setting at runtime for different regions in the same script? As stated above, a timestamp is relative to UTC time. Is there some reason you need the date/time as a timestamp (i.e. in an integer format)? If not, just store the date/time as a string or a Date/Time value in the database, so it will not be relative to UTC.
-
Does no one read the manual anymore? So, if UTC is currently at 12:00:00 am and my local time is 5:00am and your local time is 7:00am, the timestamp returned by strtotime() would be exactly the same for both of us - since it is relative to UTC. If I waited until 7:00am my time to run strtotime() I woul dhave a timestamp that is 2 hours higher than the one you ran at 7am.
-
Why are you making the query so complicated? Just use COUNT() with a GROUP BY. Just follow normal process of connecting to the database (look up a tutorial if needed). SELECT Party, COUNT(Party) as total FROM votes GROUP BY Party
-
Crazy and odd, take a guess at this javascript issue.
Psycho replied to jimmyt1988's topic in Javascript Help
I suspect it is because your AJAX call is asynchronous? Not sure since I'm not going to try and decypher a 100 lines of code to understand what is calling what. The fact that you are putting in an alert gives enough time for the asynchonous process to complete before that block of code is executed. -
What Ignace is suggesting is using different submit buttons for the action to be taken. The problem with this approach is that pressing enter will submit a form and there will be no submit value to check on the receiving page. However, the only time you would even consider that is if you were using the same form fields for different operations. I can't believe you would be using the same form fields for a "reply" and a "delete". So the solution is as requinix suggested and have two separate forms. One form must be closed before you start another. <form name="reply"> // reply form goes here </form> <form name="delete"> // delete form goes here </form>
-
This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=316055.0
-
$input = "By rd, RaeAnn Martin, Emily Sheene and Ebony Alcorn.<br /><br /> <p>Danville High School students:"; $output = preg_replace('#<br \/>.*#', '', $input);
-
Wow, that's some pretty rough code. I can't even follow what you are doing in some places. For example: $keywords = $getrow['keywords']; I don't see $getrow defined anywhere. Anyway, I think the problem is the consrtuction of your WHERE clause. You could have validated this easily enough by simply echoing the query to the page. It looks as if you are using the counter as the seach term not the actual search terms. Plus, there is a problem in the logic if you were to have two consecutive spaces. But, you are making it much more difficuly than it needs to be with all those loops. $button = trim($_GET['submit']); $search_phrase = trim($_GET['search']); if(strlen($search_phrase)<2) { echo "Search term too short"; } else { echo "You searched for <b>$search_phrase</b><hr size=\"1\">\n"; mysql_connect("localhost", "root", "supersham"); mysql_select_db("carbreaker"); $keywords = $getrow['keywords']; //explode our search term $search_words = explode(" ", $search_phrase); $like_parts = array(); foreach($search_words as $word) { if($word<>'') { $like_parts[] = "keywords LIKE '%" . mysql_real_escape_string($word} . "%'"; } } $where_clause = (count($like_parts)>0) ? "WHERE ".implode(' OR ', $like_parts) : ''; //echo out construct $construct = "SELECT * FROM stock $where_clause"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if($foundnum==0) { echo "No Stock Found"; } else { echo "$foundnum results found<br />\n"; while($row = mysql_fetch_assoc($run)) { echo "<b>{$row['make']}</b> {$row['model']} {$row['year']} {$row['cc']} {$row['fuel']} {$row['doors']} {$row['body']} {$row['date']}<br />\n"; } } }
-
Creating a test script and htm page - not writing to table
Psycho replied to flickman's topic in PHP Coding Help
Two problems: One you are running the query twice. Once before the condition test and once inside the IF condition test mysql_query ($query); if (mysql_query($query)) { die('Error: ' . mysql_error()); } Second, your IF condition is backwards. The way you have, it there will only be an error message if the query successfully completes! Use this: //mysql_query ($query); if (!mysql_query($query)) { die('Error: ' . mysql_error()); } -
How to say it (select ... from where .... and ...)
Psycho replied to egturnkey's topic in PHP Coding Help
@blink359's code will work, but it is not good programming. If you are not going to use the records where name!='' then don't pull them from the database. Otherwis,e you are just wasting system resources on the server. I just did a test and the solution I provided works to exclude records that have a name value of NULL or an empty string: $result = mysql_query("SELECT * FROM info"); while ($row = mysql_fetch_array($result)) { echo "id: {$row['id']}, name: {$row['name']}, number: {$row['number']}<br />\n"; } -
How to say it (select ... from where .... and ...)
Psycho replied to egturnkey's topic in PHP Coding Help
I think it depends on whether the ones you want to exclude have an empty string value or a null value - there is a diffrence. Try this: select * from info where name <> '' Edit: Actually I don't think nulls will matter since they won't be included in the result set or the excluded set since you can't compare null to a non null value. -
Impossible for us to day. Why don't you ask the SQL server what the problem is? mysql_query($sql) or die(mysql_error());
-
No need to go remove the "+0000". That "string" can be easily converted to a timestamp using strtotime(). The +0000 is important and is used by strtotime() to convert the time based upon Greeenwich Mean Time (GMT) or UTC depending on what you like to call it. But, strtotime() will normalize the time according to the timezone of the server. If you remove the +0000 then the time is converted as if it was based in your timezone - which it isn't. So, removing the +0000 will result in the time being off by however many hours difference between GMT and the server's timezone: echo date('m-d-Y H:i:s', strtotime('Fri, 29 Oct 2010 11:22:58 +0000')); For me, that outputs 10-29-2010 06:22:58 because on October 29 there was a five hour difference between my timezone (Central Time) and GMT. However, if I ran that for today's date, there would be a 6 hour difference because we moved our clocks back one hour a week ago from daylight savings time to standard time.
-
Not quite sure what you are trying to say there. Are you saying that each upload will consist of several fields: one for the actual file upload and additional fields to describe the upload? If so, then all the fields should be defined as arrays. Example File 1: <input type="file" name="files[]" /> Type: <select name="filetype[]"><option>Avatar</option><option></option>thumb</select> Name: <input type="text" name="file_name" /> File 2: <input type="file" name="files[]" /> Type: <select name="filetype[]"><option>Avatar</option><option></option>thumb</select> Name: <input type="text" name="file_name" /> //etc... Then, on the processing page, to access the fields for the first image you would use: $_POST['files'][0], $_POST['file_type'][0], $_POST['file_name'][0] For the second image: $_POST['files'][1], $_POST['file_type'][1], $_POST['file_name'][1] etc.
-
First off a file upload field is not a text box - it is a file input that will include a browse button. Anyway, you can simply create your form with however many file input fields as you want. Then, using javascript, provide a method for the user to add more input fields. The key to this is to name the input fields as an array. Then you can reference the fields on the receiving page as an array <input type="file" name="files[]"
-
I would suggest not validating the "format" of the phone number and instead validate that the phone number has the correct number of digits. Then you can store just the numbers in your database and use a consistent manner in which to display the phone number. For example (using US numbers), I would allow the user to enter in any value that consisted of 10 numeric digits OR 11 digits if the first number was a 1: - 123-465-7890 - (123) 456-789 - 123.456.7890 - 1-123-456-7890 Sampe code for validating function validPhone($phone) { //Remove all non digits $phone = preg_replace('/[^\d]/', '', $phone); //Test number of digits if(preg_match('/^1?\d{10}$/', $phone) !=1 ) { return false; } return $phone; } That function will return false if the number doesn't contain a valid number of digits, else it returns just the digits of the number. So, if validation passes I store just the numeric digits of the entered value. Then, whenever I need to display the value on the page I would have a function to format the phone numbers in a consistent format. function formatPhone($phone) { if(!$phone) { return false; } $format = (strlen($phone)==10) ? '(\2) \3-\4' : '\1 (\2) \3-\4'; return preg_replace('/(\d)(\d{3})(\d{3})(\d{4})/', $format, $phone); }
-
No, I won't find that. I only have IE on my work PC and I refuse to test it at home on the basis that I might have to admit there is a problem with the code I submitted.
-
Well, to answer the question originally posed - it is absolutely possible to change the source of an included javascript source file. Done this before. You just use javascript to change the src attribute for the script object. The easiest way to do this is to include an ID in the script tag. Here are a few test files to illustrate how it works. html document: <html> <head> <script id="jsInclude" type="text/javascript" src="one.js"></script> <script type="text/javascript"> function changeJS(jsFile) { document.getElementById('jsInclude').src = jsFile; } </script> </head> <body> <button onclick="changeJS('one.js');">Use JS1 Include</button> <button onclick="changeJS('two.js');">Use JS2 Include</button> <br /><br /> <button onclick="test();">Run the test function</button> </body> </html> JS source file one.js function test() { alert('This is test in include 1.'); } JS source file two.js function test() { alert('This is test in include 2.'); }
-
Page stops responding when printing content
Psycho replied to SilverArrow's topic in PHP Coding Help
Or, the problem could also be in the construction of the page. If you are using a lot of nested tables or there is invalid markup it could cause the browser to hang. You can easily test this by loading a page in the browser and then saving it locally to the client PC. Then reopen the page from the local copy. If there is still a problem in the page displaying it is with the content and not the creation. -
displaying certain parts of a text file in text boxes
Psycho replied to AeriesIII's topic in PHP Coding Help
I see advantages and disadvantages to both methods. Personally, I like method #2 because you can use named indicies for the inner dimensions of the array to give your data more strucure array( 0 => array( 'fname' => "dave", 'lname' => "Roberts", 'phone' => "123-456-7890" ) 1 => array( 'fname' => "Jane", 'lname' => "Doe", 'phone' => "111-222-3333" ) ) With option #1 you could only identify each piece of data by it's position based on the tab delimiters The process to overwrite vs. add should be very similar for both. If you are overwriting, read the text file into an array [either using file() or unserialize()] then change the value of the selected record based upon the index: $dataArray[$indexToUpdate] = $newRecord; New record would either be a tab delimited string or an array based upon option #1 or #2. As for new records, you could add them to the end or you could save the records in some logical sorting order. To do that would be easiest if the data is in a multi-dimensional array. That would require an extra step with option #1. -
displaying certain parts of a text file in text boxes
Psycho replied to AeriesIII's topic in PHP Coding Help
I think you need to rethink how you are storing the information in the text file. You are basically build a "database" of storts. So you should be storing the raw data not trying to store formatted data (i.e. the line breaks, commas, etc.): $newentry = "$firstname $lastname\n\r $address\n\r $city, $state $zip\n\r $phone\n\r"; I would suggest one of two approaches. 1. Store the data tab delimited: $newentry = "$firstname\t$lastname\t$address\t$city\t$state\t$zip\t$phone\n\r"; You could them read the file using file() which will parse teh file into an array with each line of the file an element of the array. You would then use the position of each record as it's ID. Then when you need to update a record, just update the record at the index of the ID. New records would always be added at the bottom 2. Work with the data as a multi-dimensional array and serialize it when writing it and then unserialize when reading it. This would work pretty similar to #1, but with this approach you could give each piece of data a label. This would make the logic a little easier to work with in my opinion.