premiso
Members-
Posts
6,951 -
Joined
-
Last visited
-
Days Won
2
Everything posted by premiso
-
Why are you using nl2br on a statement that has no line breaks in it ??? echo "<h2>Your Data has been submitted to our Support Team </h2>" ; echo "<a href='http://www.getrecognized.co.uk'>Home</a>";
-
Calculating the difference between two timestamps
premiso replied to smithmr8's topic in PHP Coding Help
I only use it for COUNT queries or queries I only want 1 column returned from 1 row. Just better than assigning an array then the array to a value (granted I would just use the array) but yea. Most people tend to want to convert it to a value. It can be handy Dunno what to say. It should be retrieving the difference, maybe try using mysql_fetch_assoc instead of the mysql_result and see if that works. Given that you do not see an error message it seems that there were rows returned. Try this: <?php $sql = "SELECT SUBTIME(r.timestamp, t.timestamp) AS timeDifference FROM ticket AS t INNER JOIN response AS r ON (t.ID = r.ticket_ID) ORDER BY t.ID ASC LIMIT 1"; $result = mysql_query($sql) or die(mysql_error() . ": $sql"); if (mysql_num_rows($result) > 0) { $difference = mysql_fetch_assoc($result); echo "The difference is: " . $difference['timeDifference']; }else { echo "Your query returned not results. Sorry."; } ?> If the "The Difference is" is displayed, then I am not sure what is going on. And there is really no way for us to diagnose this issue for you as it could be as simple as there is no connecting ID's in your table. Make sure you have an id that matches the response and ticket field. If you do not this will obviously not return any records. -
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format $sql = "SELECT DATE_FORMAT(`datefield`, '%c') AS month FROM table_name";
-
Calculating the difference between two timestamps
premiso replied to smithmr8's topic in PHP Coding Help
Are you sure you have data in your table? It seems like you are missing it. <?php $sql = "SELECT SUBTIME(r.timestamp, t.timestamp) AS timeDifference FROM ticket AS t INNER JOIN response AS r ON (t.ID = r.ticket_ID) ORDER BY t.ID ASC LIMIT 1"; $result = mysql_query($sql) or die(mysql_error() . ": $sql"); if (mysql_num_rows($result) > 0) { $difference = mysql_result($result, 0, 0); echo $difference; }else { echo "Your query returned not results. Sorry."; } ?> If that echos "Your query returned no results..." then the issue lies within the data inside your database. Are you sure that there is a r.ticket_ID that matches a t.ID in your database at the moment? Yep. It is just causing an issue cause no rows were returned. -
explode $time = '2009-04-18 05:55:30'; $time = explode("-", $time); $month = $time[1]; echo $month; One way to do it. But if you are just getting the data out for the specific purpose, you can use the MySQL Date functions and just pull the month out in the query instead of having to use PHP to parse the data.
-
Calculating the difference between two timestamps
premiso replied to smithmr8's topic in PHP Coding Help
I would think so too...but you never know. Maybe I am just too used to doing SQL in Mysql < 4 versions (or Oracle 9i). As I know you cannot use AS for the table names in one of those I remember griping about that how it was stupid to not allow it. Try this: $sql = "SELECT SUBTIME(r.timestamp, t.timestamp) AS timeDifference FROM ticket t, response r WHERE t.ID = r.ticket_ID ORDER BY t.ID ASC LIMIT 1"; I have never been good with joins, but that seems to generally work for me Also since we do not know the exact structure, like mchl said, maybe the inner join was causing an issue.... But nevertheless my take on the issue now is just about all guess work. There are no error messages displaying? -
foreach ($_POST as $key => $val) { if (empty($_POST[$key])) { echo "{$key} was empty."; } } What might be better is to store the names of the fields you want to check in an array then use an in_array condition in the foreach loop above and check only the values you want to check.
-
Calculating the difference between two timestamps
premiso replied to smithmr8's topic in PHP Coding Help
I think the query has an error. $sql = "SELECT SUBTIME(r.timestamp, t.timestamp) AS timeDifference FROM ticket t INNER JOIN response r ON (t.ID = r.ticket_ID) ORDER BY t.ID ASC LIMIT 1"; I do not think that AS can be used to make an alias of a table name. Replace it with that and see if it works. If not something else is going on....what it is my super powers cannot see. -
Redirect from one folder to another using mod_rewrite
premiso replied to wiggst3r's topic in Apache HTTP Server
http://www.3ring.com/resources/3ring-blog/del-icio-us/301-redirects-redirecting-your-site-folders-and-pages redirectMatch 301 ^/home-insurance/(.+)$ http://www.example.com/insurance/home-insurance/$1 Should do it. -
Calculating the difference between two timestamps
premiso replied to smithmr8's topic in PHP Coding Help
The code that we provided is to replace your existing code...is it really not that obvious? Remove all the code you just posted here in the file. Replace it with this: <?php $sql = "SELECT SUBTIME(r.timestamp, t.timestamp) AS timeDifference FROM ticket AS t INNER JOIN response AS r ON (t.ID = r.ticket_ID) ORDER BY t.ID ASC LIMIT 1"; $result = mysql_query($sql) or die(mysql_error() . ": $sql"); $difference = mysql_result($result, 0, 0); echo $difference; ?> That is equivalent to the code you wrote, just simplified and written correctly. -
Calculating the difference between two timestamps
premiso replied to smithmr8's topic in PHP Coding Help
True, and we both forgot to add the LIMIT 1 to the query.... Wow we are off. $sql = "SELECT SUBTIME(r.timestamp, t.timestamp) AS timeDifference FROM ticket AS t INNER JOIN response AS r ON (t.ID = r.ticket_ID) ORDER BY t.ID ASC LIMIT 1"; -
Calculating the difference between two timestamps
premiso replied to smithmr8's topic in PHP Coding Help
lol. Yea, that is true. I guess it never really clicked till now it is "DATEDIFF" not "TIMEDIFF" *ashamed* goes and crawls back into his corner in fetal position muttering random shit to himself. -
[SOLVED] MySQL DELETE using auto-populated Drop Down
premiso replied to Hyperjase's topic in PHP Coding Help
Did you make sure you change the column name in this sql statement? $query = 'SELECT category_name FROM category WHERE id IN ('. implode(', ', $_POST['removecats']) .')'; To be what it actually is? -
Calculating the difference between two timestamps
premiso replied to smithmr8's topic in PHP Coding Help
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff <?php $sql = "SELECT DATEDIFF(r.timestamp, t.timestamp) AS timeDifference FROM ticket AS t INNER JOIN response AS r ON (t.ID = r.ticket_ID) ORDER BY t.ID ASC"; $result = mysql_query($sql) or die(mysql_error() . ": $sql"); $difference = mysql_result($result, 0, 0); echo $difference; EDIT: Well I trashed mine and just changed mchl's to use mysql_result since we are only grabbing 1 column from 1 row And to use DATEDIFF -
<input type="submit" name="Submit" value="Submit" /> PHP is CaSe SenSiTiVe on variable names and array indexes. Change the name in the input above to be all lowercase submit and the form should submit. <input type="submit" name="submit" value="Submit" />
-
To fix the white issue: <style type="text/css"> <!-- body,td,th { color: #FFFFFF; } body { background-color: #000000; } h2 { color #ffffff; } --> </style> As far as the form not submitting. It would be helpful to post the actual form code. And as far as "not submitting" does it not enter into the IF or do you not get an email? As they are two separate issues.
-
$error = array(); if (empty($name)) { $error[] = "name"; } if (empty($product)) { $error[] = "product"; } if (count($error) > 0) { header("Location: feedback.php?error=" . implode("+", $error)); }else { // do other processing } Hopefully you can configure it from what to be what you want.
-
[SOLVED] MySQL DELETE using auto-populated Drop Down
premiso replied to Hyperjase's topic in PHP Coding Help
An extra SQL Statement. <?php if (isset($_POST['removecat'])) { $query = 'SELECT category_name FROM category WHERE id IN ('. implode(', ', $_POST['removecats']) .')'; $result = mysql_query($query); $removed = array(); while ($row = mysql_fetch_assoc($result)) { $removed[] = $row['category_name']; // change this to be the column name } $query = 'DELETE from category WHERE id IN ('. implode(', ', $_POST['removecats']) .')'; echo $query;// debug mysql_query( $query ) or die (mysql_error()); echo "<html><head><meta http-equiv='refresh' content='5;url=admin.php?main'></head>"; echo "<p class='bigtext'>". implode(', ', $removed) ." removed from the database".$proceed; exit; } ?> -
$error = ""; if (empty($name)) { $error .= "name is missing<br />"; } if (empty($product)) { $error .= "product is missing<br />"; } if (!empty($error)) { header("Location: feedback.php?error={$error}"); }else { // do other processing } Is that what you were looking for?
-
It would not be done in SQL, it would be done before the value is entered into SQL or upon retrieving the value from SQL. <?php $string = "stripallalpha%$%2324numerics"; $string = preg_replace("~([a-z0-9])~i", "", $string); echo $string; die(); ?> Should leave you with %$%.
-
How would I restrict access to files on a website?
premiso replied to limitphp's topic in PHP Coding Help
I have not looked into this too much, but here is an example download script: http://www.zubrag.com/scripts/download.php You would use something like that to dish the file. What I would do is if the user bought it, you create a hash in your database for that user which points to the file they bought. Have the hash expire after 24 hours or something similar or require them to be logged in to access it. Then when they call download.php?file=hashcreated you would look up that hash, verify the user then dish out the file. If they are not a valid user or the hash is invalid then you do not deliver the file. You would use a CRON job to clean up the database of hashes older than x amount of time to prevent them from continually leeching/giving it away to someone else. -
Good Programming and Web Design Books Check out the above thread. I do not really know, I never used books or tutorials, I just always googled a script for what I wanted to create and looked at how it was done and then figured out a better way to do it. I also found new ways of doing different items by helping out in these forums.
-
The $variable->function() is used because $variable is an object (OOP Object Oriented Programming). So it is a function/method inside of that class. The first is normal function usage set $variable to the return of function(); Where as the $variable->function(); is making a call to that function. Hope that clears it up for you.
-
if (isset($_POST['Submit'])) { $user = isset($_POST['user'])?$_POST['user']:false; $pass = isset($_POST['pass'])?$_POST['pass']:false; $pass2 = isset($_POST['pass2'])?$_POST['pass2']:false; if(!$user || !$pass || !$pass2) That would solve your issue, by making sure the variables are set and have been sent. This is how you should check for any values being sent from a form. The ? and : are the ternary operators which is a shortened IF/ELSE statement. If the field user from the form inside of the superglobal $_POST has been set then set $user to be that value, else set it to false. This should be done with any value that is coming from the form that you want to access. As with register_globals being off, $user is not set until you explicitly set it. I would suggest reading on what exactly register_globals did to help you understand why you need to define the variables you are receiving from forms.
-
$_GET['error'] would be the variable that is populated. $error = isset($_GET['error'])?$_GET['error']:false; if ($error !== false) { echo "Your error was {$error}."; } isset to check if that variable exists. The ? and : are ternary operators which act like a shortened if/else statement.