Forum Moderators: coopster
yes it is, mysql keeps track of the last num and the next is always greater than the last one it used, I just leave it as is and let it take care of things
there is a way to reset it but then you run the risk of errors because of attempted dupe entries
>> The trips are out of order.
order doesn't matter when you select them you can put them in any order you want based on a certain criteria using ORDER BY
example
SELECT * FROM tripreport ORDER BY TSpickYear DESC
this will order tham by the year in descending order. You can even use more than one column in the ORDER BY clause and also use ASC for ascending order
rows in the db don't need an order, as we can sort them however we want when we select
sorting rows [dev.mysql.com]
using ORDER BY in a SELECT [dev.mysql.com]
Here is my code to check out:
<html>
<head>
<title>Trip Report List</title>
<meta http-equiv="pragma" content="no-cache">
</head>
<body>
<div>
<?
$host = "";
$user = "";
$pass = "";
$dbname = "";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
$sql = 'SELECT * FROM tripreport ORDER BY TSpickYear, TSpickMonth, TSpickDay ASC';
$result = mysql_query($sql) or die ('<p>select died: ' . mysql_error());
echo '<center><strong>Trip Reports</strong></center><br>';
echo '<br>';
while ($row = mysql_fetch_array($result)) {
$startdate = $row['TSpickMonth'] . ' ' . $row['TSpickDay'] . ', ' . $row['TSpickYear'];
$enddate = $row['TFpickMonth'] . ' ' . $row['TFpickDay'] . ', ' . $row['TFpickYear'];
echo '<strong><a href="report.php?trip=',$row['trip_id'],'">',$row['triplocation'],'</a></strong> - ', $startdate,'<br>';
if ($enddate!= $startdate) echo ' to ',$enddate,'<br>' ;
}
echo '<br>';
echo '<br>';
echo '<a href="javascript:history.back(1)">
Back</a>';
?>
</div>
</body>
</html>
echo '<strong><a href="report.php?trip=',$row['trip_id'],'">',$row['triplocation'],'</a></strong> - ', $startdate;
if ($enddate!= $startdate) echo ' to ',$enddate;
echo '<br>';
for the refreshing thing I am really not sure, something must be funny with the logic
first thing, I would try it in another browser than IE (firefox or mozilla) to see if that is the problem. If the behaviour is the same then the script is doing something funny.
your html looks like it is all present and accounted for now though ;)
as far as login goes, now you are breaching a whole new topic
try this library thread
[webmasterworld.com...] msg3 and be sure to follow the link to peer code review as well
the error logic would work something like this
1. check each field
this could be empty checks as we have done before, or type checks
2. for each validation problem add an error message to a string so the user can fix that field
3. reinclude the original form
4. echo the error message at the top of your form
5. echo previously entered values in the value="" portion of your form
make sense?
<!--
var date = new Date();
function validate(screen) {
if (screen=="Submit") {
return true;//overrides the validation...
var errmsg = "";
with (document.forms[0]) {
if (!triplocation.value) errmsg += "\nYour trip report has no <title>.";
if (!author.value) errmsg += "\nPlease identify the report <author>.";
if (!report.value) errmsg += "\nPlease fill in the report <body> section.";
}
if (errmsg) {
alert("Sorry...\nYou have not filled out the form completely.\n" + errmsg + "\n\nPlease complete the form and 'SUBMIT' again...");
return false;
}
}
return true;
}
//-->
<html>
<head>
<title>Submit a Trip Report</title>
<script type="text/javascript">
<!--
var date = new Date();
function validate(screen) {
if (screen=="Submit") {
return true;//overrides the validation...
var errmsg = "";
with (document.forms[0]) {
if (!triplocation.value) errmsg += "\nYour trip report has no <title>.";
if (!author.value) errmsg += "\nPlease identify the report <author>.";
if (!repot.value) errmsg += "\nPlease fill in the report <body> section.";
}
if (errmsg) {
alert("Sorry...\nYou have not filled out the form completely.\n" + errmsg + "\n\nPlease complete the form and 'SUBMIT' again...");
return false;
}
}
return true;
}
//-->
</script>
</head>
<body>
<!--UNIQUE PAGE CONTENT-->
<form method="post" action="/tct/submit.php">
<TABLE WIDTH="273">
<TR>
<td valign="top">
<p>
<input id="Submit" type="submit" style="font-size:smaller;width:7em;" name="screen" value="Submit" onclick="self.clicked=this.value" />
</td>
</tr>
</table>
</form>
<!--END OF UNIQUE CONTENT-->
</body>
</html>
Since drupal is written in PHP, modifying it (or any other large package like it) is also a good way to learn a lot of PHP. The templating system uses very simple PHP, and then some components get fairly complex. You can get deeper and deeper in as your confidence grows.
you can do either, my preference is to have it as a seperate script and include the original form on error or forward using the header function on success.
>> My goodness what a lot of work for nothing!
I seldom find learning an excercise in futility.
The process that outdoorxtreme1 is learning is fairly basic and lays out a lot for continued development in php and mysql.
you can do either, my preference is to have it as a seperate script and include the original form on error or forward using the header function on success.
Ditto. Among other things, it makes double submissions less likely (to prevent entirely takes additional measures). Generally, the flow for me would be
1. If there's data, send it on to be validated and processed.
2. If the validation/processing succeeded, redirect to a success page or some such.
3. If validation fails, stay where I am and show the form again and repost the data submitted by the user so she doesn't have to type it all back in.
There are exceptions. The site that's open in the other tab of my browser has no purpose but to enter/edit data. In that case, it just goes back to the same page.
I seldom find learning an excercise in futility.
That's because like most of us who frequent this place, we tend to think "I could do this by hand in an hour and I'll never do it again, but I wonder if I could write a script that would do this automatically." Bleery-eyed and finally looking up at midnight, you have this nice little smile and think "Wow, how cool is that? Glad I didn't just do that by hand!" Many folks, though, would rather be up and running ASAP.
That's why I initially asked if outdoorextreme's goal is first and foremost to learn PHP or first and foremost to get his trip report thing running. I did not mean it as a rhetorical question, but just trying to figure out what his priorities are.
I want to get it going but I don't really have a time frame.
Ha! I've got a lot of those projects!
I'm not jatar_k, but the code in your last seems fine as far as PHP and HTML. I wouldn't purport to say anything one way or the other on the Javascript without testing since I don't "sight read" javascript ;-)
Is something not working?
[edit]
if (!repot.value) errmsg += "\nPlease fill in the report <body> section.";
I'm guessing that's a typo?
[/edit]
Don't mean to hijack outdoor's thread, but maybe I could ask a quick question. I'm doing something similar to outdoor's results page, but I start with a case statement, then break down my queries depending on what the form results were. When I stuff everything into a var (for example...
<?php
$graphic = $row['id'],' ',$row['some_stuff'],' ',$row['other_stuff'],' ',$row['even_more_stuff'],'<br>';
?>
<inHtmlCodeSomewhere>
<?php echo ($graphic);?>
...it bombs. Yet when I take the exact same query, and replace the var $graphic with echo, it works (albeit at the top of my page, where I don't want it).
Should I be using a different function than echo, or maybe a better way of doing this?
Any tips in the right direction greatly appreciated!
Daniel
you need to call the js function somehow either by using the onsubmit event or changing your submit button to a regular button and using the onclick event
Welcome to WebmasterWorld danielNorge
if you are putting all those vars into another var you can't use the comma you must use the concatenation operator like so
$graphic = $row['id'] . ' ' . $row['some_stuff'] . ' ' . $row['other_stuff'] . ' ' . $row['even_more_stuff'] . '<br>';
the comma can only be used with echo
<input id="Submit" type="submit" style="font-size:smaller;width:7em;" name="screen" value="Submit" onclick="self.clicked=this.value" />
though it looks like it should work, not really sure. You may want to post that to the javascript forum [webmasterworld.com] and see if someone can help with that. My js is way too rusty to be right.
maybe just post what you have in message 74.
Anyway, I have something similar with a function called submitForm in a separate file with all my other JS. In my case, it's not for validation, but it checks whether data has been changed and, if so, submits the form when the user clicks on the "next" and "previous". I'm not sure if "return false;" stops a form submission in the same way that it stops a link, but I assume it does.
So, a few things
- I assume you fixed the typo I mentioned?
- unless you are registering the event somewhere (in an onload script), you are not firing the validate function and, even if it is registered, I guess it would get overridden by the action you define in the onclick.
I would have something like this
<input id="Submit" type="submit" name="screen" value="Submit" onclick="validate()" />
Then for the function itself, I've had better luck with assigning an ID to every form element (usually just use the same as the name) and using getElementById like this:
var errmsg = "";
var elTriploc = getElementById('triplocation');
var elAuthor = getElementById('author');
var elReport = getElementById('report');if (!elTriploc.text)
{
errmsg += "\n *Trip Location.";
}
if (!elAuthor.text)
{
errmsg += "\n *Report author.";
}
if (!elReport.text)
{
errmsg += "\n *Trip report.";
}if (errmsg)
{
alert("Sorry...\nYou have not filled out the form completely.
The following required fields are missing:\n"
+ errmsg + "\n\nPlease complete the form and 'SUBMIT' again...");return false;
}return true;
This should stop the submit (return false) on error and allow the submit to go through otherwise.
For users with JS turned off, you'll want to do PHP validation server side and bump them back to the form if there's a problem (we sort of hit on that further up RE where to submit).
If you want to just not permit users with JS turned off to user your form, then you would make the submit button and make it a non-functional button that merely fires the JS function and then you would use the submit method in JS as in
var myForm = getElementById('myForm');
myForm.submit;
before returning true.
A few notes
- I don't know about the this.value. Shouldn't that always be "Submit" in which case your conditional at the top is always true and it always submits? This version doesn't use it.
- I use the .text because I have had bad luck with the .value property always returning NULL (undefined) in some browser (can't remember if it was IE or Firefox).
- I use the getElementById('myId') form because it has been more cross-browser friendly for me than using the collection of elements from the form.
I hope that gets it sorted, but if not, head over to the JS forum and come back here if you have more questions on the PHP side.
[edited by: ergophobe at 8:57 pm (utc) on Oct. 28, 2005]