Jump to content

retro

Members
  • Posts

    42
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

retro's Achievements

Member

Member (2/5)

0

Reputation

  1. Oops! I just noticed that I hadn't set the id in the HTML! :-\ It works now - id="btnToggle", same as name. However, when I use $b = $_POST['btnToggle'] after submitting the form, $b doesn't return anything. How can I get around this? *edited* think I'm half asleep today!
  2. Hi, I am a complete newbie at JavaScript, so apologies for this more than likely easy-to-answer question! I took a simple script that toggles a button's value based on whether an option box was enabled or disabled (the button also toggled this) and stripped the option box out. Here is what I came up with: <script type="text/javascript" language="javascript"> function toggle() { if (document.getElementById("btnToggle").value == "OFF") { document.getElementById("btnToggle").value="ON" return } if (document.getElementById("btnToggle").value == "ON") { document.getElementById("btnToggle").value="OFF" return } } </script> I then used a SWITCH statement to give $c a value of "OFF" or "ON" based on a field in a table. I then made the button: <input type="button" name="btnToggle" value="<?php echo $c ?>" onclick="toggle()" /> When the page is loaded, the button correctly displays ON or OFF depending on the field. However, nothing happens when I click the button. I am sure this is in the .value == "OFF" part. How can I remedy this? Thanks in advance for any help offered!
  3. Apologies if there is a glaringly obvious answer to this - I am still a relative beginner with PHP! I have used DATEDIFF in a MySQL query to determine when a date in a db (`date`) falls on the same day as an entered date ($DelDate), but they have to be fortnightly ranges. The query used: This will show fortnightly results, e.g. if `date` was 2008-06-12 (Thursday 12 June) then when $DelDate is 2008-06-12 or 2008-06-26, it would return results, but not if it were 2008-06-19. I now want to be able to do the same thing in PHP - determine whether a date falls on a fortnightly range of another date. I don't know whether it would help, but you could see it as the original date being on an A week, with the weeks alternating A or B, and so I want to determine whether a date is in an A week. (Incidentally, I have already filtered all results to be on that day of the week, so the rest of the week is irrelevant). Can anyone suggest anything? Thanks in advance for any information offered - it is greatly appreciated!
  4. Ahh, never mind... I was thinking too complex! I achieved it with the following: if ($id != '') { } else { $id = $insert; } ?> <meta http-equiv="refresh" content="0;url=contact.php?id=<? echo $id ?>" /> <?
  5. I have a page with a form for entering or editing customer details. This is controlled by using $_GET['id'] and therefore determining whether to create a blank record or edit an existion one (calling the `id` field from the database). This form actions save.php, the code of which is as follows: <?php header("Location: ./"); ?> <? //Connect to DB & check for errors include("dbinfo.inc.php"); $connection = mysql_connect($server,$username,$password); if (!$connection) { echo mysql_errno().": ".mysql_error()."<br/>"; exit; } if(!mysql_select_db($database)) { echo("Database not found<br>"); } //retrieve post data $id = $_POST["id"]; $FirstName = $_POST["firstname"]; $MiddleName = $_POST["middlename"]; $LastName = $_POST["lastname"]; $Town = $_POST["town"]; $Street = $_POST["street"]; $PostCode = $_POST["postcode"]; $houseno = $_POST["houseno"]; $MobilePhone = $_POST["mobilephone"]; $HomePhone = $_POST["homephone"]; $OfficePhone = $_POST["officephone"]; $Email = $_POST["email"]; $Homepage = $_POST["homepage"]; if ($id != '') { //Edit current record $query = "UPDATE customers SET firstname='" . $FirstName . "',middlename='" . $MiddleName . "',lastname='" . $LastName . "', town='" . $Town . "',street='" . $Street . "',postcode='" . $PostCode . "',houseno='" . $houseno . "', mobilehone='" . $MobilePhone . "',homephone='" . $HomePhone . "',officephone='" . $OfficePhone . "', email='" . $Email . "',homepage='" . $Homepage . "' WHERE id=" . $id; } else { //Add new record $query = "INSERT INTO customers(firstname,middlename,lastname,town,street,postcode,houseno,mobilephone,homephone,officephone,email,homepage) VALUES ( '" . $FirstName . "', '" . $MiddleName . "', '" . $LastName . "', '" . $Town . "', '" . $Street . "', '" . $PostCode . "', '" . $houseno . "', '" . $MobilePhone . "', '" . $HomePhone . "', '" . $OfficePhone . "', '" . $Email . "', '" . $Homepage . "' )"; } //Update DB $result = mysql_query ($query) or die("SQL Error: " . mysql_error()); mysql_close(); ?> What I want to do is open up the record once it has been saved. To do this, I need to open the page: contact.php?id=x Where x is the id number. As the id number has not been generated yet (it is an auto increment field in the database), I assume I would have to put $insert = mysql_insert_id(); after the $result at the end. Indeed, when I tried echoing this with the header disabled, it gave me the correct id. However, I cannot get it to redirect to the correct page. I tried using both of the following: header("Location: ./contact.php?id=" . $insert . ""); header('Location: ./contact.php?id='.$insert); And both times, it redirected to contact.php?id= (i.e. it didn't fill in the id number). Is this because $insert is not defined until the end of the document? I tried moving the header code to the end of the document, but it did not like this, giving the following error: Can anyone suggest how I could get this working as intended? Thanks in advance for any advice offered!
  6. Never mind, I sorted it myself. The first part was a simple spelling error, and the second part can be solved with mysql_insert_id(). I have an issue with the second part, but I'll mark this resolved and start again with that!
  7. I have a page, new.php, which either adds a new user to a database, or edits an existing user (depending on how you accessed it.. it uses $_GET['id]). It has various input boxes, as you'd expect for name, address etc. The action for the form is save.php. Here is the content of save.php: <?php header("Location: ./"); ?> <? //Connect to DB & check for errors include("dbinfo.inc.php"); $connection = mysql_connect($server,$username,$password); if (!$connection) { echo mysql_errno().": ".mysql_error()."<br/>"; exit; } if(!mysql_select_db($database)) { echo("Database not found<br>"); } //retrieve post data $id = $_POST["id"]; $FirstName = $_POST["firstname"]; $MiddleName = $_POST["middlename"]; $LastName = $_POST["lastname"]; $Town = $_POST["town"]; $Street = $_POST["street"]; $PostCode = $_POST["postcode"]; $houseno = $_POST["houseno"]; $MobilePhone = $_POST["mobilephone"]; $HomePhone = $_POST["homephone"]; $OfficePhone = $_POST["officephone"]; $Email = $_POST["email"]; $Homepage = $_POST["homepage"]; if ($id != '') { //Edit current record $query = "UPDATE customers SET firstname='" . $FirstName . "',middlename='" . $MiddleName . "',lastname='" . $LastName . "', town='" . $Town . "',street='" . $Street . "',postcode='" . $PostCode . "',houseno='" . $houseno . "', mobilehone='" . $MobilePhone . "',homephone='" . $HomePhone . "',officephone='" . $OfficePhone . "', email='" . $Email . "',homepage='" . $Homepage . "' WHERE id=" . $id; } else { //Add new record $query = "INSERT INTO customers(firstname,middlename,lastname,town,street,postcode,houseno,mobilephone,homephone,officephone,email,homepage) VALUES ( '" . $FirstName . "', '" . $MiddleName . "', '" . $LastName . "', '" . $Town . "', '" . $Street . "', '" . $PostCode . "', '" . $houseno . "', '" . $MobilePhone . "', '" . $HomePhone . "', '" . $OfficePhone . "', '" . $Email . "', '" . $Homepage . "' )"; } //Update DB $result = mysql_query ($query) or die("SQL Error: " . mysql_error()); mysql_close(); ?> I have two problems... 1. Creating a new user works fine. Editing a user puts their details into the input boxes, which can be altered. However, clicking save doesn't update the record. It seems to perform fine (going back to the home page) with no errors, but the records haven't updated. 2. I want to have it so that once the page has been submitted, it goes to the order page (order.php), filling in the customer details automatically. I can do this on an existing contact by using a button with onclick="window.location.href='order.php?id=<?php echo $id ?>'" However, as the ID field (auto incrementing) has not been created in the database, I cannot do this within save.php (or I would edit the header location). Could anyone make any suggestions on either of these problems? Thanks in advance for any advice!
  8. Sorry, that's what I meant. Agreed, this should work. I would imagine it is a file location problem, e.g.: If this script is: ./script.php then the picture would need to be: ./pallettown.jpg or if the script is: ./subdir/script.php then the picture would be: ./subdir/pallettown.jpg If you're on a Linux server, it may bitch about case too - make sure it isn't .JPG instead of .jpg. I would personally use double quotes for an img src location, but the single one should work. Do the pokemon images work?
  9. You need to tell it you're using PHP.... <?php echo("<img src=\"dir1/dir2/" . $row["username"] . "/images/image.jpg /\">"); ?> or <a href="dir1/dir2/<? echo($row["username"]); ?>/images/image.jpg" />
  10. 1. Is it the same picture that would display where it echos "You just found a Rattata"? 2. Does the picture show up there? If yes to the above, note that you are using pallettown.jpg where it does not work, but Pallet_town.jpg where it works!
  11. OOH! That has returned 3 results, missing out record id 4! Thanks very much for the help!
  12. If I choose May 5th, it gives: string(10) "2008-05-08" If I choose May 15, it gives: string(10) "2008-05-15" etc.
  13. Certainly. I'll use phpMyAdmin (incidentally, phpMyAdmin 2.10.0.2, MySQL Server version: 5.0.51a, MyISAM) Query: SELECT * FROM orders LEFT JOIN customers ON ( customers.id = orders.customer ) WHERE ( recur =1 AND DAYOFWEEK( date ) = DAYOFWEEK( '2008-05-08' ) ) OR ( recur =2 AND DATEDIFF( date, '2008-05-08') %14 =0 ) AND date <= '2008-05-08' AND '2008-05-08' NOT BETWEEN holdstart AND holdend Result: As you can see, I substituted $DelDate with 2008-05-08, which is the value for holdend in order id 4.
  14. they are DATE. Yes, the point is that I want any date that isn't between a range. So my thinking was that if holdstart = "" and holdend = "", then everything should be NOT BETWEEN them, i.e. it would ignore that part of the query. I'll try to (over)simplify: Name: John Smith Fred Bloggs Bert Jones Del. Day: Mondays Tuesdays Mondays Holiday: 24-31 May 2008 n/a n/a If I were to run my query for 19 May 2008, it should tell me that John Smith and Bert Jones have deliveries due that day. If I were to run my query for 26 May 2008, it should tell me that only Bert Jones has a delivery. I guess I'm not interpreting how NOT BETWEEN will work correctly. In the above example, I'd feed in 2008-05-26 and it would determine that this lies between 2008-05-24 and 2008-05-31 and not display that record. As this won't work, can you suggest how I can either tweak this, or another way to accomplish the same thing? Thanks!
×
×
  • 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.