Jump to content

Fearpig

Members
  • Posts

    195
  • Joined

  • Last visited

Everything posted by Fearpig

  1. Hi guys, I've got a problem that must be dead easy to solve I've just been looking at it for too long! I'm generating an e-mail based on a php form. I'm trying to include all the fields into the body of the e-mail. So far I have: [code]<?php $email = 'someone@domain.co.uk'; $subject = 'literature request'; $message =  $HTTP_POST_VARS['Name']; if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {   echo "<h4>Invalid email address</h4>";   echo "<a href='javascript:history.back(1);'>Back</a>"; } elseif ($subject == "") {   echo "<h4>No subject</h4>";   echo "<a href='javascript:history.back(1);'>Back</a>"; } elseif (mail($email,$subject,$message)) {   echo "<h4>Thank you for sending email</h4>"; } else {   echo "<h4>Can't send email to $email</h4>"; } ?>[/code] So far it validates the e-mail address and subject but only passes one one of te fields ($message =  $HTTP_POST_VARS['Name'];). How would I change this single field to: [code]foreach ($_POST as $part => $qty){    echo "$part - $qty<br>"; }[/code] This code just grabs all of the variables passed on by the page before. I need to do it this way as the fields are generated by a database and I won't know field names untill the page is generated. I'd really appreciate any help from you guys!  ;D Cheers Tom
  2. Hi Daniel0, FER-MAIL is the name of my MS Exchange server, how do I confirm that this is the correct address for SMTP mail?
  3. Hi Guys, I'm still having real problems sending a basic text e-mail through PHP. Could someone take a look at my code and settings and hopefully point me in the right direction?  :) PHP.ini [code][mail function] ; For Win32 only. SMTP = FER-MAIL.ferroli.local; for Win32 only smtp_port = 25 sendmail_from= Ferroli_IT@Ferroli.co.uk ; for Win32 only[/code] HTML Form [code]<form name="LiteratureRequestForm" method="post" action="Process_Request_Form2.php"> <fieldset> <legend class='Body3'>CONTACT DETAILS</legend> <table width="400" border="0" cellspacing="0" cellpadding="4" class="Body2">     <tr>       <td width="157" align="right"><div align="right">*Name:</div></td>       <td width="4">&nbsp;</td>       <td width="215"><input name="Name" type="text" id="Name"></td> </tr></table></fieldset> <table width="400" border="0" cellspacing="0" cellpadding="4" class="Body2">     <tr>       <td colspan="2" align="right" class="BodyText1">         <div align="right">           <input type="reset" name="Submit2" value="Clear Form">         </div></td>       <td><input type="submit" name="Submit" value="Submit"></td>     </tr>   </table> </form>[/code] ...and here's the processing page [code]<?php /* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */ $email = 'someone@mydomain.co.uk'; $subject = 'literature request'; $message =  $HTTP_POST_VARS['Name']; /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */ if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {   echo "<h4>Invalid email address</h4>";   echo "<a href='javascript:history.back(1);'>Back</a>"; } elseif ($subject == "") {   echo "<h4>No subject</h4>";   echo "<a href='javascript:history.back(1);'>Back</a>"; } /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */ elseif (mail($email,$subject,$message)) {   echo "<h4>Thank you for sending email</h4>"; } else {   echo "<h4>Can't send email to $email</h4>"; } ?>[/code] This  is the error message that I get popping up: Warning: mail() [function.mail]: Failed to connect to mailserver at "FER-MAIL.ferroli.local" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\Intranet v3\e-mail_test\Process_Request_Form2.php on line 25 Can't send email to someone@mydomain.co.uk Any help would be REALLY appreciated as I've been stuck  ??? on this for days now!! Cheers Tom
  4. Right then - I've had a look at my 'Default SMTP Virtual Server' on exchange on my e-mail server and... - TCP port is set to 25 - the Relay open to all - connections are allowed by all - anonymous, basic authentication and integrated windows authentication are all allowed I've had a look on IIS on the webserver and... - under 'Default SMTP Virtual Server' all the settings match the exchange server - under the domain name 'Allow incoming mail...' has been ticked I've had a look at the PHP.ini file and have the following details for the mail function... [code][mail function] ; For Win32 only. SMTP = 200.10.10.20; for Win32 only smtp_port = 25 ;sendmail_from= me@localhost.com ; for Win32 only ; For Win32 only. sendmail_from = me@mydomain.co.uk ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i"). ;sendmail_path = ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(), even in safe mode. ;mail.force_extra_parameters =[/code] Can anyone see where I am going wrong? As far as I can see this should all now be working. [i]Please Help!!!![/i]  :-\
  5. Hi Guys, My form to e-mail script is giving me the following error: [code]Warning: mail() [function.mail]: Failed to connect to mailserver at "fer-mail" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\Intranet v3\Process_Request_Form2.php on line 25 Can't send email[/code] How do I go about confirming that the details are correct? I'm using PHP 5, IIS, Exchange, Windows Server 2003. Any help would be appreciated.  :)
  6. Thanks for that Argo Squirrel!  ;D I've gone over the code as you suggested and its up and running now.
  7. Huggiebear to the rescue!  ;D Thank you. Now I just have to work out how to send that as an e-mail.
  8. Hi guys, This isn't a coding problem more of a method problem... I've set up a page where people can request literature in volumes of 1, 25, 50 or a box. The page scans a database and for each bit of literature it creates a new set of radio buttons so that you can tick either 1, 25, 50 or box for each bit of literature. I then wanted to submit this form as an e-mail to the person responsible. Unfortunately I don't know which variables are going to be passed to the processing page as that depends on which manuals are listed on the form (by which ones are in the database). The form works correctly but I have no idea how to process it as of yet. Can anyone suggest a moethod or tutorial? This has been bugging me for a couple of days now. :-\ [code] <p class="Body2">Documentation Request Form </p> <form name="LiteratureRequestForm" method="post" action="ProcessingPage.php"> <?php $sql="SELECT * FROM BR_01_PRODF_0001 WHERE Product_Group = 'Literature'"; $result=odbc_exec($conn,$sql); if (!$result)       {exit("Error in SQL");} echo "<table width=250 border=0 class='Body3'>\n"; echo "<tr><th class='Body2' align=center bgcolor=#CCCCCC><b>Manuals</b></th></tr>\n"; while (odbc_fetch_row($result)) { $PartNo=odbc_result($result,"BR_PR_PARTNO"); $Description=odbc_result($result,"BR_PR_StockFullDescr"); echo "<tr><td><fieldset> <legend>$Description</legend> <input type='radio' name='$PartNo' value='1' id='1'>1 <input type='radio' name='$PartNo' value='25' id='25'>25 <input type='radio' name='$PartNo' value='50' id='50'>50 <input type='radio' name='$PartNo' value='Box' id='Box'>Box </fieldset></td></tr>\n"; } echo "</table>\n"; ?> </form>[/code] Any help would be appreciated.  ;D
  9. Hi Guys, I'm tring to change my code from a MySQL database to an SQL database. The code below should list the members of each department under the department heading. The code below just lists the name of the first department 12 times (there are 13 departments in total if that helps). [code] include("../ConnectSQL2005.php"); $sql="SELECT * FROM tbl_department"; $result=odbc_exec($conn,$sql); if (!$result)       {exit("Error in SQL");}   $DeptID=odbc_result($result,"Dept"); $Department_Name=odbc_result($result,"Description"); while (odbc_fetch_row($result)) { echo "<table>\n"; echo "<tr><td><b class='Body2'>$Department_Name</b></td></tr>"; $sub_sql="SELECT * FROM qry_Full_Employee_Details"; $subresult=odbc_exec($conn,$sub_sql); if (!$subresult)       {exit("Error in SQL");} $Department=odbc_result($subresult,"Department");        $First_Name=odbc_result($subresult,"First_Name"); $Last_Name=odbc_result($subresult,"Last_Name");  while (odbc_fetch_row($subresult)) {                                   if ($DeptID == $Department) { echo "<tr><td>$First_Name $Last_Name</td></tr>"; }                 } echo "</table>\n";                 echo '<br><br>'; } [/code] I'd expect this to show as: [b]Department 1[/b] Joe Bloggs Paul Smith John Doe [b]Department 2[/b] Random Guy Jane Doe [b]Department 3[/b] Someone Else Yet Another Can anyone suggest where I am going wrong? I have had this working from an MySQL database and this is the final straw stopping me from putting the SQL based site on-line! Any help would be appreciated.  :) Cheers Tom
  10. Hi Guys, I'm tring to change my code from a MySQL database to an SQL database. The code below should list the members of each department under the department heading. The first block works fine and outputs in the format that I want... the second one just lists the name of the first department 12 times (there are 13 departments in total if that helps). Working MySQL. [code]include("../ConnectMySQL.php"); $result = mysql_query("SELECT * FROM tbl_department",$db); $subresult = mysql_query("SELECT * FROM tbl_telephonenumbers",$db); while ($row = mysql_fetch_array($result)) { echo "<table width='250' border=0 class='Body2'>\n";     printf("<tr><td align=center bgcolor=#CCCCCC><b class='Body2'>%s</b></td></tr>", $row["Department"]);     $subresult = mysql_query("SELECT * FROM tbl_telephonenumbers",$db); echo "</table>"; echo "<table width='250' border=0 class='Body2'>\n"; while ($row2 = mysql_fetch_array($subresult)) {         if ($row['ID'] == $row2['Department']) {             printf("<tr><td width='150'>%s %s</td> <td width='50'>%s</td> <td width='50'>%s</td></tr>", $row2["First_Name"], $row2["Last_Name"], $row2["DDI"], $row2["Mobile_SD"]); }     } echo "</table>\n";     echo '<br><br>'; } [/code] Broken SQL. [code] include("../ConnectSQL2005.php"); $sql="SELECT * FROM tbl_department"; $result=odbc_exec($conn,$sql); if (!$result)       {exit("Error in SQL");}   $DeptID=odbc_result($result,"Dept"); $Department_Name=odbc_result($result,"Description"); while (odbc_fetch_row($result)) { echo "<table>\n"; echo "<tr><td><b class='Body2'>$Department_Name</b></td></tr>"; $sub_sql="SELECT * FROM qry_Full_Employee_Details"; $subresult=odbc_exec($conn,$sub_sql); if (!$subresult)       {exit("Error in SQL");} $Department=odbc_result($subresult,"Department");        $First_Name=odbc_result($subresult,"First_Name"); $Last_Name=odbc_result($subresult,"Last_Name");  while (odbc_fetch_row($subresult)) {                                   if ($DeptID == $Department) { echo "<tr><td>$First_Name $Last_Name</td></tr>"; }                 } echo "</table>\n";                 echo '<br><br>'; } [/code] Can anyone see where the problem is? Any help would be appreciated. Cheers Tom
  11. Thanks Huggie you're a diamond!! ;D
  12. OK.... I thought I had Globals turned off, so I've gone back and turned them off now but one of my pages has stopped working The address in the browser address bar shows: http://fer-post/test/Spares/List_Boiler_Components.php?id=19 So the id variable is being passed from the page before but I'm getting the error message: Notice: Undefined variable: id in D:\Intranet v3\TEST\Spares\List_Boiler_Components.php on line 36 Here's the script I'm using, can you see any errors in this one? Thanks again for all your help. [code] //Use ID=2 if no id present if (!isset($_GET['id'])){   $id = "2"; } $sql2="SELECT * FROM tbl_parts WHERE ID='$id'"; $result2=odbc_exec($conn,$sql2);   if (!$result2)     {exit("Error in SQL");} $Model2=odbc_result($result2,"Model");  echo "<span class='Body2'><b>Current Boiler Model: $Model2"; echo "</b></span>"; echo "<br><br><table width='350' class='Body2' border=1 cellspacing='0'>\n"; echo "<tr bgcolor=#CCCCCC><td width='200' align='center'><b>Description</b></td><td width='150' align='center'><b>Part No.</b></td></tr>\n"; $Air_Pressure_Switch=odbc_result($result2,"Air_Pressure_Switch");  echo "<tr><td>Air Pressure Switch</td><td>$Air_Pressure_Switch</td></tr>\n"; echo "</Table>";[/code]
  13. Thanks yet again HuggieBear!! If I had Globals turned off would something like this do the job?: [code]//Use ID=2 if no id present if (!isset($_GET['id'])){   $id = "2"; }[/code]
  14. Hello HuggieBear... Here's the form to pass the search string on... [code]echo "<table width=450 border='1'> "; echo "<tr><td width='428' bgcolor='#CCCCCC' class='Body2'><strong>Match part number to boilers.</strong></td></tr>"; echo "<tr align='center'><td class='Body2'>"; echo "<P align=left class='Body2'></P>"; echo "<form method='GET' action='Match_Parts.php'>"; echo "<input type=text name='PartsSearch' maxlength=255>"; echo "<input type=submit  value='Submit'>"; echo "</form>"; echo "</td></tr></table>";[/code] I don't have any code that processes the GET, I'm converting it from a MySQL page where it worked without one. I hope thats enough info for you.
  15. Hi Guys, Could someone have a quick look at this for me.... There seems to be an error in matching the field types in my query. I am tying to match a variable entered by a user into a text box ($PartsSearch) with a field on an SQL server (Air_Pressure_Switch - data type "ntext"). Here is the code I am using followed by the error message I recieve. [code] $conn=odbc_connect('Intranet','sa','password'); if (!$conn)   {exit("Connection Failed: " . $conn);} echo "<p class='Body2'>This part may be used with the following boilers:</p>"; $sql="SELECT * FROM tbl_parts WHERE Air_Pressure_Switch=$PartsSearch"; $result=odbc_exec($conn,$sql);   if (!$result)     {exit("Error in SQL");} while (odbc_fetch_row($result)) {           $Model=odbc_result($result,"Model");   echo "<b class='Body2'>$Model</b><br>"; } [/code] Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Operand type clash: ntext is incompatible with int, SQL state 22005 in SQLExecDirect in D:\Intranet v3\TEST\Spares\Match_Parts.php on line 45 Error in SQL Can anyone suggest a solution? Cheers Tom
  16. hi thedarkwinter, I've tried you suggestions and you've fixed it!!  ;D Thank you guys! ;D ;D
  17. It all works seperately but when i link the two files it errors out in the second column. When I remove the link in Main_Page.php it will create a table with a column for each engineer. I can run Job_List.php up on its own with a constant instead of the $User_ID variable and it runs fine. When the link is in place it creates a table with two columns the first one contains the first engineer and his job list the second column contains the error: "Warning: odbc_fetch_row(): 11 is not a valid ODBC result resource in D:\Intranet v3\TEST\Service\test.php on line 15" From the data I would expect four columns each with an engineer and his job list.
  18. Hello everyone, Could someone take a look at my code for me and suggest where I'm going wrong? Main_Page.php [code] <?php $conn=odbc_connect('OU_PROD','ou_dba','dba'); if (!$conn)       {exit("Connection Failed: " . $conn);} $sql="SELECT * FROM person WHERE person_group = 'ENGINEER'"; $rs=odbc_exec($conn,$sql); if (!$rs)       {exit("Error in SQL");} echo "<Table cellspacing='0' cellpadding='0' border='1'><tr>"; //echo "$day<br>"; while (odbc_fetch_row($rs)) {     $User_ID=odbc_result($rs,"user_id");     echo "<td>$User_ID";     include 'Job_List.php';     // ------------ This is where the script breaks ---------     echo "<td>"; } echo "</tr></table>"; odbc_close($conn); ?> [/code] Job_List.php [code] <?php $day=0; //sets the day value back to 0 - days run 0,1,2,3,4,5,6, $startdate=date("Y/m/d"); //sets the initial date to the current date echo "<Table border=1 width=200>"; //echo "<p>$day<br>"; //echo "$startdate<p>"; while ($day < 7) {             $selectdate = date( "Ymd", mktime(0, 0, 0, date("m"), date("d")+$day, date("y")) );       //increase $startdate by the current value of $day       $formatdate = date("l - d/m/Y",strtotime("$selectdate"));       $conn=odbc_connect('OU_PROD','ou_dba','dba');       if (!$conn)             {exit("Connection Failed: " . $conn);}       $sql="SELECT * FROM assignment WHERE promised_begin_dt = '$selectdate' and person_id = '$User_ID'";       $rs=odbc_exec($conn,$sql);       if (!$rs)             {exit("Error in SQL");}       echo "<tr bgcolor=#CCCCCC align=center class='Body2'><th><b>$formatdate</b></th></tr><tr><td>";   //echo "$day<br>";     while (odbc_fetch_row($rs))     {           $Request=odbc_result($rs,"request_id");           echo "<a href=Result_ByRequest.php?Request=$Request class='Body2'>$Request</a><br>";     } $day++; //fairly sure that this won't work as it refers to itself! } echo "</td></tr></Table>"; odbc_close($conn); ?> [/code] If I comment out the line "include 'Job_List.php';" on the main page then the table of engineers names is created correctly with a new column for each engineer. When the Job_List.php is included it writes the first column correctly but then gives the error shown below: Warning: odbc_fetch_row(): 11 is not a valid ODBC result resource in D:\Intranet v3\TEST\Service\Main_Page.php on line 15 Line 15 is: "while (odbc_fetch_row($rs))" If anyone can spot where its breaking down I would appreciate it as this is the most complex thing I've attempted and so far I've failed at the very last hurdle!! Cheers Tom
  19. Thanks Huggiebear! I'll have a play with that and see what I can do. (It always seems to be you or Wildteen that helps me!)
  20. Hello, Bit of a vague question for someone!  ??? I'm trying to loop some PHP so that it displays a set of results, increases one of the parameters and displays the next set. It needs to stop looping on the 7th pass! Basically I need it to list todays jobs, then list the next days jobs ... up to a week. I can't just order by date as I need them grouped and not just in a list. Here's a rough idea of the code but there are lots of errors... could someone point me in the right direction or send me a link to a tutorial.  :) <?php $day=0 //sets the day value back to 0 - days run 0,1,2,3,4,5,6, $startdate=date("Y/m/d") //sets the initial date to the current date while ($day < 7) { //not sure if I can write conditions like this!             $selectdate = date( "Ymd", mktime(0, 0, 0, date("m"), date("d")+$day, date("y")) );       //increase $startdate by the current value of $day       $conn=odbc_connect('OU_PROD','ou_dba','dba');       if (!$conn)             {exit("Connection Failed: " . $conn);}       $sql="SELECT request_id, date FROM assignment WHERE date = '$selectdate'";       $rs=odbc_exec($conn,$sql);       if (!$rs)             {exit("Error in SQL");}       echo "$selectdate<br>";     while (odbc_fetch_row($rs))     {           $Request=odbc_result($rs,"request_id");           echo "$Request<br>";     } $day = ($day +1) //fairly sure that this won't work as it refers to itself! } ?> Any help would be appreciated as this will remove a load of nearly identical pages. Cheers Tom
  21. Hello everyone, I've run into a problem trying to install the GD2 extension. I have the following lines in the php.ini file: [code] ; Directory in which the loadable extensions (modules) reside. extension_dir = "C:\PHP" extension=php_gd2.dll [/code] I have the php_gd2.dll file in C:\PHP, I have restarted my web server. At this point there is still no sign of GD2 using phpinfo(); I am running PHP 5.1.4, IIS 6 on a Windows 2003 Server. Can anyone see or suggest where I'm going wrong? Cheers Tom.
  22. Hi Guys, I'm having some problems with the code below. Could someone take a look and point me in the right direction. Basically I have a list of news articles and I want to display the top three by date in descending date order. The code below works fine untill I include the "TOP 3" part of the SQL query at which point I get the following error message: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Intranet v3\TEST\News\Top_3_Articles.php on line 25 [code] $result = mysql_query("SELECT TOP 3 * FROM tbl_news ORDER by Date DESC",$db); echo "<p class='Body2'>Select news article to display...</p>"; echo "<table width=80% border=1>\n"; echo "<tr class='Body2' bgcolor=#CCCCCC><th>Date</th><th>Heading</th></tr>\n"; //colum names while ($myrow = mysql_fetch_array($result)) { printf("<tr><td>%s</td><td><a href=\"%s?id=%s\" class='Body2'>%s</a></td></tr>\n", //lay out results 2 in the first column and 1 in the second $myrow["Date"], "Result_ByArticle.php", $myrow["ID"], $myrow["Title"]); } echo "</table>\n"; [/code] Any help would be appreciated as I just can't see where this is going wrong!
  23. Just like that.... Cheers Huggiebear  ;D
  24. OK that's really confused me!! I've added the code you mentioned but now when I refresh the page it just says "Array" (which is NOT one of the file names). Could one of you take a look and see if I've implemented the code incorrectly? [code] $thefiles = array(); //initialize if ($handle = opendir('.')) {   while (false !== ($file = readdir($handle))) {       if ($file != "." && $file != ".." && $file != "index.php" && $file != "test.php" && !is_dir($file)) {             //use filesystem functions to get the filesize and other attributes RTFM             $thefiles[] = array('filename' => $file);             //used this way, it just adds the new item to the end of the array             // it is creating an array of arrays       }   }   closedir($handle); } //at this point the $thefiles array contains all the file info //access it using 2 indexes like this  echo $thefiles[0]['filetype']; //use array functions to sort $thefiles array to your pleasure RTFM //use the foreach() to cycle through the $thefiles array and echo the files and other attributes out krsort($thefiles); //arrange descending by filename $number_holder = count($thefiles) - 1;  echo $thefiles[$number_holder]; [/code]
  25. Hello everyone, Could someone take a quick look at my code for me? I'm trying to scan a folder and list the highest file (by filename) as a link to that file. I've managed to list them in descending order but when I add the array_shift() function it removes the top value instead of all the others. eg. I can list files called "f4.pdf, b5.pdf, a3.pdf, c1.pdf" in the order "f4.pdf, c1.pdf, b5.pdf, a3.pdf" and make them links to the relevant files, but I need it limit the results to the top value "f4.pdf". With the code below I get "c1.pdf, b5.pdf, a3.pdf". Hope thats not too confusing! [code] $thefiles = array(); //initialize if ($handle = opendir('.')) {   while (false !== ($file = readdir($handle))) {       if ($file != "." && $file != ".." && $file != "index.php" && $file != "test.php" && !is_dir($file)) {             //use filesystem functions to get the filesize and other attributes RTFM             $thefiles[] = array('filename' => $file);             //used this way, it just adds the new item to the end of the array             // it is creating an array of arrays       }   }   closedir($handle); } //at this point the $thefiles array contains all the file info //access it using 2 indexes like this  echo $thefiles[0]['filetype']; //use array functions to sort $thefiles array to your pleasure RTFM //use the foreach() to cycle through the $thefiles array and echo the files and other attributes out krsort($thefiles); //arrange descending by filename array_shift($thefiles); foreach ($thefiles as $singlefile) { $Doc = $singlefile['filename'];     echo "<a class='Body2' href='$Doc'>$Doc</a><br>"; } [/code]
×
×
  • 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.