Jump to content

hoogie

Members
  • Posts

    54
  • Joined

  • Last visited

    Never

Posts posted by hoogie

  1. You won't be able to do this in one query.  The query you currently have will either return duplicate records for all comments and wall posts (assuming there's at least one in each table), or nothing at all (if one of the tables is empty).

     

    What I would do is have two queries, one for the comments section and one for the wallposts section.  Put the records from both of those queries into an array.  Include the dtime field so that you can then sort the array by time.

     

    Then loop the results into your tables.

  2. Kickstart is right.  The problem is with this page, not the one we were looking at originally.

     

    Your input needs to be inside of your <form> tags otherwise it's not included in the form.  And the name of the input is the name of the variable that's passed.  So your input named 'textfield' becomes $_POST['textfield'].  If you want to use $_POST['customer_id'] instead, you need to rename this input to 'customer_id'.

     

    Your code should look something like this (starting at the body tag)

     

    <body>
    
    <p><img src="../images/mahapitiya 1.jpg" width="1024" height="139" />
    </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p>
    <form id="form1" name="form1" method="post" action="approve_account.php">
      <label>Customer ID </label>
      <label>
        <input type="text" name="customer_id" id="textfield" />
      </label>
    </p>
      <label>
        <input type="submit" name="button" id="button" value="Search" />
      </label>
    </form>
    <p> </p>
    <p>   </p>
    </body>
    </html>

  3. @ hoogie,

     

    customer_id is the primary key of customer table and it was set to be auto incremented. But there is no separate form which submits customer_id. This is the structure of the customer table.

      customer (customer_id, full_name, name_with_initials, address, contact_number, gender)

     

    When the supervisor wants to search the records of customer table, he should be able to do it with the use of customer_id..... 8)

     

    I understand this.  I'm not communicating very well.

     

    What I'm asking has nothing to do with the database.

     

    Maybe a better way of asking the question is, say the supervisor wants to look up records for the id number 55514.  Where does he type in "55514" to see if there are any matches?  Is it somewhere on this page, or is it on another page?

  4. I don't think the problem is the way the data is put into the database, I think the problem is with the page that sends the customer_id to your form form.

     

    This is POST data, right?  Which means that there is another page with a form that has an input named "customer_id", and when you submit that form, it takes you to this page that we're working on.  Does that make sense?  I think we need to look at the code that is sending the customer_id, not the page that is receiving it.

  5. Ok, I'm bored.  Let's do this.

     

    First of all, you need to test to see if your id number is coming through.  Make a backup of this form we've been working on so you can restore it later if you need to.  Then erase everything in there and just put in this code:

    <?php echo $_POST['customer_id']; ?>

     

    Now try it out and see if it displays the id number.  If you submitted the form with the id number, and this page is blank, or gives you an error message, then you know that the problem is not with this page, but with the page that is submitting the customer_id.  Open that page instead and make sure that your inputs have the correct names and values.

     

    Once you are SURE that the customer_id is coming through correctly, and has the correct name, this is the way I would write this page:

    <?php
    $connect=mysql_connect("localhost","root","");
    mysql_select_db("bank",$connect) or die ("could not select database");
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    #apDiv4 {
    position:absolute;
    width:776px;
    height:598px;
    z-index:3;
    left: 206px;
    top: 300px;
    }
    #form1 {
    font-size: 18px;
    font-weight: bold;
    }
    body,td,th {
    font-size: 18px;
    }
    -->
    </style>
    </head>
    
    <body>
    
    
       
    <div id="apDiv4">
      <form action="" method="post" name="form1" id="form1">
        <fieldset>
          <legend class="cap"> Customer Details</legend>
          <table width="85%" height="350" border="0" align="center" cellpadding="5" cellspacing="0">
          <?php
          
          //initilize variables
          
          $var_nic = '';
          $var_full_name = '';
          $var_name_with_initials = '';
          $var_address = '';
          $var_contact_number = '';
          $var_gender = '';
          
          
               if(isset($_POST['customer_id'])){ 
            $customer_id=$_POST['customer_id']; 
    	   		   
              $query = "select * from customer where customer_id=" .$customer_id;
    	   $result = mysql_query($query) or die(mysql_error());
    	   
    	   if(mysql_num_rows($result) < 1) {
                   echo 'The record could not be found.';
                   }
           else {   
    	   while ($row=mysql_fetch_array($result)){
    	   
    	   // replace blank variables with variables from the database
    	   
    	  $var_nic = $row['nic'];
        		  $var_full_name = $row['full_name'];
        		  $var_name_with_initials = $row['name_with_initials'];
        		  $var_address = $row['address'];
        		  $var_contact_number = $row['contact_number'];
        		  $var_gender = $row['gender'];  
    	   }
                 }
    } 
    	  
      ?>
          
            <tr>
              <td> </td>
              <td class="title02"> </td>
              <td> </td>
              <td> </td>
            </tr>
            <tr height="30">
              <td width="2%" height="35"> </td>
              <td width="46%" class="title02" align="left">National ID</td>
              <td width="50%" class="attribute1" align="left"><input type="text" name="nic" size="30"   class="attribute1" value="<?php echo $var_nic; ?>"></td>
              <td width="2%"> </td>
            </tr>
            <tr height="30">
            <td height="33"> </td>
            <td width="46%" class="title02" align="left">Full Name</td>
            <td width="50%" class="attribute1" align="left"><input type="text" name="full_name" size="30"   class="attribute1" value="<?php echo $var_full_name; ?>"></td>
              <td width="2%"> </td>
            </tr>
            <tr height="30">
              <td height="34"> </td>
              <td class="title02" align="left">Name With Initials</td>
              <td width="50%" class="attribute1" align="left"><input type="text" name="name_with_initials" size="30"   class="attribute1" value="<?php echo $var_name_with_initials; ?>"></td>
            </tr>
            <tr height="30">
              <td width="2%"> </td>
              <td width="46%" class="title02" align="left">Address</td>
              <td width="50%" class="attribute1" align="left"><label>
                <textarea name="address" id="textarea" cols="45" rows="5"><?php echo $var_address; ?></textarea>
              </label></td>
              <td width="2%"> </td>
            </tr>
            <tr height="30">
              <td width="2%"> </td>
              <td width="46%" class="title02" align="left">Contact Number</td>
              <td width="50%" class="attribute1" align="left"><input type="text" name="contact_number" size="30" class="attribute1" value="<?php echo $var_contact_number; ?>"></td>
              <td width="2%"> </td>
            </tr>
            <tr height="30">
              <td width="2%"> </td>
              <td width="46%" class="title02" align="left">Sex</td>
              <td width="50%" class="attribute1" align="left"><p>
    	   <select name="gender" id="jumpMenu" >
              <option selected="selected"><?php echo $var_gender; ?></option>
                
                <option>Male</option>
                <option>Female</option>
              </select>          
              <td width="50%" class="attribute1" align="left"> </td>
                
                <br />
              </p></td>
              <td width="2%"> </td>
            </tr>
            
          </table>
          <p align="center"> </p>
          <p align="center">
            <label>      </label>
            <label>
              <input name="button" type="submit" id="button"  value="Approve Account"  />
                    </label>
            <label> <a href="accsup_help.php">
              <input name="button" type="submit"  id="button"   value="Help"  />
            </a></label>
            </td>
          </p>
        </fieldset>
        <td width="5%"> </td>
        </tr>
        <tr>
          <td> </td>
          <td> </td>
          <td> </td>
        </tr>
        <tr>
          <td> </td>
          <td align="center"> </td>
          <td> </td>
        </tr>
        <tr>
          <td> </td>
          <td><font color="red" size="1" ></font></td>
          <td> </td>
        </tr>      
        </table>
      </form>
    </div>
    <img src="../images/mahapitiya 1.jpg" width="1024" height="139" />
    </body>
    </html>

     

    This should make it so you see a form no matter how you get to the page, but if you get to the page with an id number, it will pull the data and populate the form.  Otherwise the form will be blank.

     

    I didn't test it so I might have forgotten a ; here or there.  I always do that.

  6. @hoogie thanks for the reply! That makes sense :) I should probably think of a way to automatically create a non-existing variable.

     

    @kenrbnsn, I'm trying to send URL requests to some websites but their URL may vary in parameters. One might be ...somesite.com?existing_var=1234

     

    or somesite.com?existing_var=1234&another_var=789

     

    so I'm trying to figure if I can add for example, ?my_var=345 at the end of any link without getting script errors and successfully using GET on the sites I added the new parameter.

     

    You can do this, but you won't be able to do anything with the my_var variable unless you also control somesite.com.  Does that make sense?  You can pass any sort of variable to any site you want to, but unless you also control the site you're passing the variable to, it will just ignore it.

  7. You can add as many variables to a url as you want.  The only danger is unknowingly using a variable that is already being used for something else.  If you are developing this website yourself, you should make sure you do your research and find out all the variables that it uses before you add more.  If the website is being developed by someone else, you should talk to them to make sure your variable isn't going to interfere with what they're doing.

  8. I'm just trying to understand exactly what you want this page to do.

     

    Say someone comes to the page, but has not submitted a POST['customer_id'].  Do you want them to see a blank page, or an empty form?

     

    Your code in your first post would result in a blank form if there is no customer_id set, and also a blank form if there IS a customer_id set.

     

    The code suggested by jcbones would result in a blank page (no form or anything) if there is no customer_id, and a form populated with data from your database if there IS a customer_id.

     

     

    Are either of those what you are going for?  Or do you want it to display a blank form if there's no customer_id, and a filled out form if there is one?

     

    In either case, it sounds like you have another problem somewhere.  Do some tests to make sure that the $_POST['customer_id'] variable is actually being passed to the page (just put an echo $_POST['customer_id'] somewhere and see if it displays the correct information).  It could be a problem with not being connected to the database, or it could be a misnamed variable.  Check those things first.

  9. Thanks.  I did change the From: to the server domain, but it didn't seem to help. 

     

    I was hoping that I wouldn't have to deal with their System Admin people, as I've talked to them about this problem before and they don't seem to even know where to find the settings for their mail server, but I guess I may have to try again.

  10. Thanks for your response.

     

    I know the address is correct because I can send mail to it successfully from my personal e-mail address.  In fact, the temporary workaround I have in place is to have the form send the e-mail to me, and I have a filter that bounces it out to the correct address.  So I know the problem isn't the e-mail address and I've checked it many many times.

  11. I've put together an application form that dumps the results into an e-mail and sends it to an e-mail address at the company I'm building the site for.  I've tested it with three of my personal e-mail addresses (gmail, hotmail, and my work address, which is on an Exchange server), and it works on all of them.

     

    When I set it to the final address, however, it bounces it back to me, giving me the message "User not found".

     

    I don't know much about the e-mail server this company is using, but I have talked to them about the problem and they don't seem to know much about it either  :-)  They don't know why it's being denied or what they could do to fix it.

     

    So my question is twofold.  1)  Is there something I can do with my code to make it more likely that the e-mail will make it past their filters, and 2) Are there any suggestions I could give them for changes to make on their server that would allow my e-mails through?

     

    Thanks in advance.

     

    Here's the code:

    $mail_to = 'xxxxx@company.com';
    $mail_subject = 'Application from xxxxx Website';
    $mail_headers = "MIME-Version: 1.0" . "\r\n";
    $mail_headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    // the $s_email variable comes from the form that has been submitted.
    // It has already been validated and sanitized
    $mail_headers .= 'Reply-To: <'.$s_email.'>'. "\r\n"; 
    $mail_headers .= 'Return-Path: <'.$s-email.'>' . "\r\n"; 
    $mail_headers .= 'From: Bethesda Home Website <my_email@myserver.com>' . "\r\n";
    $mail_body = 'body';
    
    mail($mail_to, $mail_subject, $mail_body, $mail_headers);
    

  12. I assume you have one file that you use to connect your database and you just include that file in your other pages when you need to connect?

     

    If so, I think it would be easier just to keep separate connect files - one on your development PC at home and one on the live server.

     

    It is probably possible to write a conditional statement to change the connection information depending on which server you're on, but I think it would be simpler and less confusing just to have two separate files.

  13. Maybe you figured this out already, but I'm home now and can actually test my solutions before posting them. :)

     

    This has been working for me:

    function getAll() {
      require_once('../../../moodle2_connect.php');
      $query = "select username from moodle2_user";
      $result = mysql_query($query) or die(mysql_error());
      $items = array();
      while ($row = mysql_fetch_array($result)) {
        $items[] = $row['username'];
      }  
      return  $items;
    }
    

     

    And to display:

    foreach (getALL() as $item) {
        echo $item;
    }
    

  14. Yes, now you're getting the last result because every time you loop, you are assigning a different value to $items.  The first time through, it assigns the first value.  The second time, it overwrites the first value with the second value, so now all that $items contains is the second value.  Does that make sense?

     

    So what you need to do is store the results in an array, which can store more than one variable at a time.

     

    I haven't done this before, but try this:

     

    function getAll() {
      require_once('../../../moodle2_connect.php');
      $query = "select username from moodle2_user";
      $result = mysql_query($query) or die(mysql_error());
      $items = mysql_fetch_array($result)
       return  $items;
    }
    

     

    Now to display your results you'll need to do this:

     

    $items_array = getALL(X);
    
    foreach ($items_array as $item) {
        echo $item;
    }
    

     

    As I said, I haven't tried this.

  15. I believe that a function terminates as soon as you give it the "return" command.  So this function would terminate after returning the first result.

     

    A different way of doing this that might solve your problem is to use the while loop to put all of the results into a list or an array, and then when the loop completes, return that list or array.

  16. This one doesn't make any sense.

     

    I've been using this code to take $date (a date returned from a database) and add one day to it:

     

    <?php
    $nextdate = date("Y-m-d H:i:s", strtotime($date)+((60*60)*24));
    ?>
    

     

    This works - I've put probably 6 months worth of data through it with no problem.

     

    But when the date from the database is 2007-11-4, it only adds 23 hours.  I get 2007-11-4 23:00:00 back instead of 2007-11-5.

     

    I've tested with many other dates including Nov. 4 from other years, and it works perfectly except for November 4, 2007.

     

    I can get around this by adding 25 hours instead of 24 (I don't use the time, just the date, so it doesn't matter), but I'm just really wondering what's going on here?  Is this a bug in PHP?

     

    I'm running:

    XAMPP for Linux 1.6.5a

    PHP 5.2.5

    MySQL 5.0.51

×
×
  • 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.