Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. A couple of things...did you say that when you go to this page you dont see the form? Make sure you are not just refreshing because you'll probably get the warning that you will be submitting information again(certainly if you are using Firefox or IE). You might have to close your browser and navigate back to the page. Also, where are you defining $work?
  2. Can you modify and put in the code tags...makes it a lot easier to follow
  3. Well it is quite easy if you had all the content on the same page and weren't trying to use two separate php pages, because you can use isset() : [code] <php if(isset($_POST['subscribe'])){ //all of the php for subscribing } if(isset($_POST['unsubscribe'])){ //all of the php for unsubscribing } ?> [/code] If it is possible to do that, it will be far easier, otherwise you are going to have to pass all of the form input to the othe php page, either by get or by post using cURL.
  4. No, your other form is set up fine. Because when you first load the page, the form has not been submitted. Therefore the contents inside the curly braces after this line if(!isset($_POST['submitbutton'])) Are still executed, because the form has not been submitted.
  5. Can you post the code again as it is now?
  6. Why not actually have two differant forms? [code] <form action="page1.php"> All the code for page1 including the submit button </form> <form action="page2.php"> All the code for page2 including the submit button </form> [/code]
  7. No problem. And one further note, from looking at your other post. you can also use isset() in the following way: [code] <?php //all your php code here if(!isset($_POST['submitbutton']))//note the ! { ?> show form <?php } ?> [/code] By doing this, you would only show the form if it has not been submitted. Sometimes this is desirable, othertimes it is not. So the use of it would depend on the situation.
  8. [code] <?php function parsedate($date){   $str = strtotime($date);   $today = date('Y-m-d');   $todaystr = strtotime($today);   $diff = $todaystr-$str;   $newdate = date('l jS \of F Y',time()- $diff);   return $newdate; } ?> [/code] Im not sure if it is necessary to use this:   $today = date('Y-m-d');   $todaystr = strtotime($today); Perhaps i could have simpy used the time() function, but i wasn't sure if i may run into problems given that the format of the date being passed to the function is the Y-m-d and as such will not include the time for any hours during that day.
  9. Perhaps an example of not using isset might help... [code] <?php $var = $_POST['var']; if(empty($var){ echo 'You did not provide any data'; }else{ echo "You variable was $var"; } ?> <form action="page.php method="post> <input type="text name="var" /><br /> <input type="submit" name="submitbutton" /> </form> [/code] If you try that, then the first time you visit the page, [b]before[/b] you have submitted the form, you will get 'You did not provide any data', which is obviously undesirable because it may confuse the user because they havn't tried to provide the data as yet. Also, if you consider the if statement to be: [code] <?php if(empty($var){ echo 'You did not provide any data'; exit; } ?> [/code] Then the script would also exit, meaning the user would never ever see the form. So, by putting isset() back in, we fix all of this: [code] <?php if(isset($_POST['submitbutton']){ $var = $_POST['var']; if(empty($var){ echo 'You did not provide any data'; }else{ echo "You variable was $var"; } } ?> <form action="page.php method="post> <input type="text name="var" /><br /> <input type="submit" name="submitbutton" /> </form> [/code] Hope that helps :)
  10. Just change this line: mysql_query ("UPDATE `workorder` set Purchase = '$Purchase', Comment = '$Comment' WHERE work = '$Work'") or die(mysql_error()); For the code i posted.
  11. No, what it means is: if the form has been submitted, then do everything between the curly braces, e.g. process the form, update the database etc. I dont quite understand what you mean by the curly braces being at opposite ends of the code, but if you mean this: if($var == 'foo'){ //code } instead of: if($var == 'foor') { //code } Then they are identical. It is a matter of personal taste as to which people use.
  12. When you say it wont add them to the database, i can only assume that you mean this query: mysql_query ("UPDATE `workorder` set Purchase = '$Purchase', Comment = '$Comment' WHERE work = '$Work'") or die(mysql_error()); Because there is no INSERT query any where. As far as i can see, your use of isset() is fine, but try this with the query: $sql ="UPDATE `workorder` set Purchase = '$Purchase', Comment = '$Comment' WHERE work = '$Work'"; mysql_query($sql)or die(mysql_error()); echo $sql; So you can see what the query is actually doing. There may be no errors in it, but perhaps one of the variables isn't right.
  13. isset() by example: [code] <?php if(isset($_POST['submitbutton'])){ //process form } ?> //all your html <form action="page.php" method="post"> //all your form fields <input type="submit" name="submitbutton" /> </form> [/code] This is by far the most common use of the isset() function. The reason why it is used here is because the first time the page is loaded, the form would not have been submitted. Therefore, it is unnecessary to process the form and will likely lead to odd content shown to the user. So, by using isset() you only attempt to process the form if it has been submitted. Another common use is if you have a form with multiple submit buttons for differant actions. For instance, you might have a form on a forum such as this where you can post or preview, if you then imagine the following code: [code] <?php if(isset($_POST['postreply']){ //post the reply } if(isset($_POST['preview']){ //preview the reply } ?> [/code] you can see that by using isset, you can break up your code to only do the partiular actions relevant to the submit button that was pressed. Hope thats all clear
  14. Well i would guess the error is on the other query then [code] <?php if ($type == "All") {     $sql= "SELECT * FROM phones WHERE manufacturer='$catmode' ORDER by model ASC";   $queryphones = mysql_query($sql) or die("mysql_error() Sql:$sql");     $temp1 == "";   } elseif (!$type == "All") {     $temp1 == $type;     $sql = "SELECT * FROM phones WHERE manufacturer='$catmode' AND special='$type' ORDER by model ASC";   $queryphones = mysql_query($sql) or die("mysql_error() Sql:$sql");   } ?> [/code]
  15. Oh i see, sorry. I guess the string is not explicit enough. You could try last 01 July or something, but again, that might be too ambiguous. You could try: [code] <?php $month = date('m'); if($month >= 6){ $year = date('Y'); }else{ $year = date('Y') -1; } $lastjuly = strtotime("01 July $year"); echo $lastjuly; echo date("m/d/Y", $lastjuly); ?> [/code]
  16. Try adding an or die statement. Also, separating the query out will help so you can echo the query string:   $sql = "SELECT * FROM phones WHERE manufacturer='$catmode' AND special='$type' ORDER by model ASC";   $queryphones = mysql_query($sql) or die("mysql_error()<br />Sql:$sql"); while($phones = mysql_fetch_array($queryphones)) { }
  17. I for one havn't really got a clue what you are asking, perhaps it is just me. Also, enclose your code in full php tags(<?php ?>) So we can see it with syntax highlighting. Makes it a lot easier on the eye.
  18. because you are echoing both the timestamp and the the formatted version?
  19. Oh i think i see what you are asking? If you leave it blank then it still displays results? This is due to the search being this: LIKE '%$trimmed%' This searches for the $trimmed variables with any amount of any character before and after it. So, if you leave it blank, it will return all the results. You have two choices here really; do you need to use like? Or are you only expecting to get one result back? If so, change it to: $query = "SELECT * FROM test WHERE test= '$trimmed' ORDER BY test"; If you do need to use like, just add a simple test before hand: [code] <?php if(empty($trimmed)){ echo 'You did not provide a search term'; exit; } ?> [/code]
  20. No problem. What do you mean by still displays the table value? Can you show the code that you are currently using? And enclose it in [code*][/code*] tags and full php tags(<?php ?>) so we can see it highlighted, makes it a lot easier to look at.
  21. I expect it means there was something wrong with your query. Try this: $result = mysql_query($query) or die(mysql_error()); This will give more information on any error that could be in the query.
  22. [code] <?php $var = $_GET['form'] ; // get the query for the search engine $trimmed = trim($var); //trim whitespace from the stored variable $con = mysql_connect("localhost","3d","pass"); if(!$con){   die('Error:'.mysql_error()); } $selectdb = mysql_select_db("3d",$con); if(!$selectdb){   die('Error:'.mysql_error());   } $query = "SELECT * FROM tablename WHERE test LIKE '%$trimmed%' ORDER BY test";//as said, you had the table as $test which wasn't defined $result = mysql_query($query); $num =mysql_num_rows($result);//number of matching rows if($num > 0){//at least one match   while($row =mysql_fetch_assoc($result){//to loop through all of the matches echo $row[fieldname]; echo '<br />'; }   }   else{   echo "no matches found";   } mysql_close($con); ?> [/code] You cant just echo the result of the query ($result = mysql_query()) because that gives a resource id of the query.
  23. [code] <?php $image = "<a href='test.php'><img src='images/standards/".$row[lam_number]-$row[lam_name]."_40.gif' alt='$row[1am_name]' /></a>"; ?> [/code] Give that a try, im not quite sure if your use of {} was causing a problem. I also replaced the escaped double quotes with singles to make it a bit easier to see if there was a problem
  24. You would be using the fwrite() function.
×
×
  • 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.