Jump to content

ifis

Members
  • Posts

    60
  • Joined

  • Last visited

    Never

Posts posted by ifis

  1. I found a script to validate a form by getElementsByTagName .  I have the validation set up to validate <input>s , but I want to add <textarea>s .  I'm not too up on javascript and have tried to do some playing around without any sucess.  Here is the code:

    function validate() { 
    var str = ""; 
    var elements = document.getElementsByTagName('input'); 
    
    // loop through all input elements in form 
    for(var i = 0; i < elements.length; i++) { 
    
       // check if element is mandatory; ie has a pattern  
       var pattern = elements.item(i).getAttribute('pattern'); 
       if (pattern != null) { 
         var value = elements.item(i).value; 
    
         // validate the value of this element, using its defined pattern 
         var offendingChar = value.match(pattern); 
    
         // if an invalid character is found or the element was left emtpy 
         if(offendingChar != null || value.length == 0) { 
    
           // add up all error messages 
           str += elements.item(i).getAttribute('errorMsg') + "\n" ; 
    
           // notify user by changing background color, in this case to red 
           elements.item(i).style.background = "yellow";  
         } 
       } 
    }  
    
    if (str != "") { 
       // do not submit the form 
       alert("ERROR ALERT!!\n" +str);  
       return false; 
    } else { 
       // form values are valid; submit 
       return true; 
    } 
    }
    

    the scipt picks out pattern and errorMsg from the HTML code:

    <input pattern='[^A-Za-z]' errorMsg='You are missing Answer 1 for question $q' name='aanswer$q' type='text' id='aanswer$q' size='95' />

    Thanks for the help!

  2. You can do something like this to send an e-mail to everyone:

    <?php
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    
    $content=$_POST['content']
    $subject=$_POST['subject']
    //content and subject of e-mail posted from form
    $sql = "SELECT * FROM Members";
    $result=mysql_query($sql);
    while($row = mysql_fetch_array($result))
    {
    $address = $row[email];
    $name=$row[firstName] ." ". $row[lastName];
    
      //send email
    $emess= "<html>
    $content
    </html>";
    
    $headers= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From:xxxx@php.com';
    
    
    $mailsnd=mail("$address","$subject","$emess","$headers");
    
    echo "Email send to $name at $address.<br />";
    }

     

  3. I'm trying to pull up an external website within my iframe, but the address has a varaible in it ($FILE) that is messing it up.  It works in straight HTML; is there anyway to get this to work easily?

      <?php
      $read=$_GET['read'];
      switch($read)
      {
      case 'AC61-25f':
      echo "<iframe src='http://rgl.faa.gov/Regulatory_and_Guidance_Library/rgAdvisoryCircular.nsf/0/c9461c4231acdc7d86256f1c006f8fce/$FILE/ac60-25f.pdf'
    frameborder='no' width='100%' height='680'></iframe>";
    break;
    case 'Learning Statement Reference Guide':
    echo "<iframe src='http://www.faa.gov/education_research/testing/airmen/media/LearningStatementReferenceGuide.pdf'
    frameborder='no' width='100%' height='680'></iframe>";
    break;
    default:

    thanks

  4. OK, now I got an error: Cannot inset into Endorsementlog table. MySQL Returned: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Endorsement='Private Pilot Practical Test (Single-Engine)',Date='2008/02/27'' at line 1

    here is the code I updated:

    mysql_query("UPDATE Endorsementlog SET end='$dorse',end1='$dorse1',end2='$dorse2' WHERE Student='$student',Endorsement='$lic',Date='$today'")or die("Cannot inset into Endorsementlog table. MySQL Returned: ".mysql_error());

  5. I have a mysql_error() and it does not show anything.  Maybe there is a better way to do it.  Here is the code I have:

    mysql_query("UPDATE Endorsementlog SET end='$dorse' AND end1='$dorse1' AND end2='$dorse2' WHERE Student='$student' AND Endorsement='$lic' AND Date='$today'") or die("Cannot inset into Endorsementlog table. MySQL Returned: ".mysql_error())

    as far as echo the queary, how would I do that just

    echo "mysql_query('UPDATE Endorsementlog SET end='$dorse' AND end1='$dorse1' AND end2='$dorse2' WHERE Student='$student' AND Endorsement='$lic' AND Date='$today'') or die('Cannot inset into Endorsementlog table. MySQL Returned: '.mysql_error())";

    ?

  6. I unset the variables because I am connecting to a different database and did not want the original variables that I used to connect to the first database to interfere with the connection with my second database.  Basically, I want to get a string that is saved in one database, update the strings variables with inputs from a form and then save the resulted in another database.  The script runs without an error message, but does not write anything to the MySQL database.  Here is the first part of it

    //get data
    $make=$_POST['make'];
    $lic = $_POST['lic'];
    $student=$_POST['student'];
    $sex = $_POST['sex'];
    $CFI=$_POST['CFI'];
    $expireip=$_POST['expireip'];
    $firstName=$_POST['firstName'];
    $lastName=$_POST['lastName'];
    $limitations=$_POST['limitations'];
    $departure=$_POST['departure'];
    $destination=$_POST['destination'];
    $route=$_POST['route'];
    $airport=$_POST['airport'];
    $airspace=$_POST['airspace'];
    $landingair=$_POST['landingair'];
    $seldate=$_POST['seldate'];
    $pilotcertificate=$_POST['pilotcertificate'];
    $pilotnumber=$_POST['pilotnumber'];
    
    include("endorsement.inc");
    

  7. I am trying to update a table with a result from another database based off a users selection.  I am having a problem updating the table though.  The scipt does not produce an error message, but I can't figure out why it does not work.

    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    //Convert male/female to he/she
    if ($sex == 'Male'){
    $preposition= he;
    }
    If ($sex == 'Female'){
    $preposition= she;
    }
    
    $sql = "SELECT * FROM Endorsements WHERE lic='$lic'";
    $result=mysql_query($sql);
    
    //get the first entry from the result
    $row = mysql_fetch_array($result);
    
    $find = array("\$student","\$make","\$preposition","\$firstName","\$lastName","\$CFI","expire","limitations","departure","destination","\$route","\$airport","landingair","\$airspace","seldate","pilotcertificate","pilotnumber");
    $replace = array($student,$make,$preposition,$firstName,$lastName,$CFI,$expireip,$limitations,$departure,$destination,$route,$airport,$landingair,$airspace,$seldate,$pilotcertificate,$pilotnumber);
    
    $dorse =str_replace($find,$replace,$row['end']);
    $dorse1 =str_replace($find,$replace,$row['end1']);
    $dorse2 =str_replace($find,$replace,$row['end2']);
    echo "$dorse</br>";
    echo "$dorse1</br>";
    echo "$dorse2</br>";
    
    unset($host);
    unset($username);
    unset($password);
    unset($db_name);
    
    include("endorsementlog.inc");
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $today=date("Y/m/d");
    
    mysql_query("UPDATE Endorsementlog SET end='$dorse' AND end1='$dorse1' AND end2='$dorse2' WHERE Student='$student' AND Endorsement='$lic' AND Date='$today'") or die("Cannot inset into Endorsementlog table. MySQL Returned: ".mysql_error());
    
    mysql_close();

    It's probably something stupid, but I'm stuck.  Thanks

  8. I have a form the needs to search one database to set information for the output that I want, but then I want to write the result of that into the users database.  Here is what I have:

      <?php
    
    
    //get data
    $make=$_POST['make'];
    $lic = $_POST['lic'];
    $student=$_POST['student'];
    $sex = $_POST['sex'];
    $CFI=$_POST['CFI'];
    $expireip=$_POST['expireip'];
    $firstName=$_POST['firstName'];
    $lastName=$_POST['lastName'];
    $limitations=$_POST['limitations'];
    $departure=$_POST['departure'];
    $destination=$_POST['destination'];
    $route=$_POST['route'];
    $airport=$_POST['airport'];
    $airspace=$_POST['airspace'];
    $landingair=$_POST['landingair'];
    $seldate=$_POST['seldate'];
    $pilotcertificate=$_POST['pilotcertificate'];
    $pilotnumber=$_POST['pilotnumber'];
    
    include("endorsement.inc");
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    //Convert male/female to he/she
    if ($sex == 'Male'){
    $preposition= he;
    }
    If ($sex == 'Female'){
    $preposition= she;
    }
    
    $sql = "SELECT * FROM Endorsements WHERE lic='$lic'";
    $result=mysql_query($sql);
    
    //get the first entry from the result
    $row = mysql_fetch_array($result);
    
    $find = array("\$student","\$make","\$preposition","\$firstName","\$lastName","\$CFI","expire","limitations","departure","destination","\$route","\$airport","landingair","\$airspace","seldate","pilotcertificate","pilotnumber");
    $replace = array($student,$make,$preposition,$firstName,$lastName,$CFI,$expireip,$limitations,$departure,$destination,$route,$airport,$landingair,$airspace,$seldate,$pilotcertificate,$pilotnumber);
    
    $end =str_replace($find,$replace,$row['end']);
    $end1 =str_replace($find,$replace,$row['end1']);
    $end2 =str_replace($find,$replace,$row['end2']);
    echo "$end</br>";
    echo "$end1</br>";
    echo "$end2</br>";
    
    mysql_close();
    
    include("endorsementlog.inc");
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $today=date("Y/m/d");
    
    mysql_query("INSERT INTO Endorsementlog (end, end1, end2) VALUES ('$end','$end1','$end2') WHERE Student='$student' and Date='$today' and Endorsement='$lic'") or die("cannot inset into Endorsementlog table");
    
    mysql_close();
    ?>

      I get the die message from the INSERT INTO query.  Any ideas?

  9. I think you might also look at using a switch statement.  With the switch statement you could set a default view.

     

    switch ($view)
    {
    case 'view 1':
    echo ' ....';
    break;
    case 'view 2':
    echo ' ....';
    break;
    default:
    echo 'default view';
    }

     

    but you will have to set the view variable first.

     

  10. Hey guys, I'm having trouble with joining two tables in a SELECT.  Here is the code:

    $sql = "SELECT*FROM member JOIN blog";
    $result=mysql_query($sql);		
    while($row = mysql_fetch_array($result)){
        echo" <tr>
              <td><h3>$row[firstName] $row[lastName]</h3></td>";
        echo "<td>$row[Date]</td>
              <td>$row[Title]</td>
            </tr>";
    		}
        echo "</table>";

    I get the error:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource.

    Any ideas?  I'm sure it is something simple that I am just missing.  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.