Jump to content

wright67uk

Members
  • Posts

    454
  • Joined

  • Last visited

Everything posted by wright67uk

  1. $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Restaurant' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".html'>" . $nt[$i] . "</a>" . "<br/>"; $FileName = str_replace(' ','_',$nt[$i]) . ".html"; $FileHandle = fopen($FileName, 'w') or die("cant open file");} fclose($FileHandle); ?> When a page is opened using fopen i would like the file menu.php to be written to the file created. To do this would I need to do somthing like; $FileHandle = fopen($FileName, 'w', include ("menu.php")) or die("cant open file");} Im not sure about the correct use of syntax here. Any ideas?
  2. Ive just tried to use fopen for the first time, but ive been denied access. Im trying to create a new page. $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Restaurant' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value){ $i++; echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".html'>" . $nt[$i] . "</a>" . "<br/>";} $FileName = str_replace(' ','_',$nt[$i]) . ".html"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); fclose($FileHandle); Warning: fopen(Indian.html) [function.fopen]: failed to open stream: Permission denied in D:\Hosting\######\html\1pw\b.php on line 40 cant open file. The hosting company I use say in their help forum; "If a file is outside of the paths defined by open_basedir, PHP will refuse to open it" Is there a query I can run to find out which paths are defined by open_basedir and is it possible to edit open_basedir?
  3. This works really well, thankyou very much for your help. I can see one problem that Ive caused. echo "<a href='" . $nt[$i] . ".html'>" . $nt[$i] . "</a>";} say for example if a result from my database was Fried Chicken, then I would output somthing like; <a href="Fried Chicken.html">Fried Chicken</a> Obviously this would produce a broken link. Is there a way to factor out the space between Fried and Chicken within the link, but to keep the space in the anchor text?
  4. $query = mysql_query("SELECT name FROM business WHERE type ='Restaurant' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) { $i++; echo $nt[$i]."<br/>";} Now im trying to swap the last line; echo $nt[$i]."<br/>";} for somthing more like echo "<a href="$nt[$i].html">$nt[$i]</a>";} My syntax seems to be shot to pieces, and i recieve errors. any ideas welcome? The error i receive is "Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' " Many thanks.
  5. Hi, i got the below code to work in the end; $query = mysql_query("SELECT name FROM business WHERE type ='Restaurant' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; echo "$nt[0]<br>$nt[1]<br>$nt[2]<br>"; where ive put echo "$nt[0]<br>$nt[1]<br>$nt[2]<br>"; is it possible for php to count how many results are to be output and then provide the right amount of variables? for example... for four results php would display; echo "$nt[0]<br>$nt[1]<br>$nt[2]<br>$nt[3]"; but if i only had 2 results then; echo "$nt[0]<br>$nt[1]";
  6. Thanks for the replys, here is what I am trying to achieve; Say for example SELECT name gave me two results; nameone and nametwo I would want; $field1 = nameone $field2 = nametwo where as at the moment im getting; $field1 = nameone nametwo
  7. Why would the code below display all of the results from my sql query opposed to just the first field? ie. echo $field1 <?php mysql_connect(###"); mysql_select_db("###") or die("Unable to select database"); $result = mysql_query("SELECT name FROM business WHERE type ='Restaurant' ORDER BY name"); $numrows = mysql_num_rows($result); for($x=0;$x<$numrows;$x++){ $result_row = mysql_fetch_row($result); $field1 = $result_row[0]; $field2 = $result_row[1]; $field3 = $result_row[2]; echo $field1; } ?> many thanks for any help.
  8. Hello, Im trying to display some results from mysql database, however none display. Can anyone tell me where im going wrong please? </head><body> <div id="listhold"> <div class="list"> <a href="Restaurants.html">Restaurants</a><br /> <?php mysql_connect("","",""); mysql_select_db("") or die("Unable to select database"); $result = mysql_query("SELECT name FROM business WHERE type ='restaurant' ORDER BY name"); $number_of_results = mysql_num_rows($result); $results_counter = 0; if ($number_of_results != 0) {while ($array = mysql_fetch_array($result)) $results_counter++; if ($results_counter >= $number_of_results);} ?> </div>
  9. Hello im receiving the error code, <?php mysql_connect("","business",""); mysql_select_db("business") or die("Unable to select database"); $result = mysql_query("SELECT subtype FROM business WHERE type ='restaurant' ORDER BY name"); $number_of_results = mysql_num_rows($result); $results_counter = 0; if ($number_of_results != 0) {while ($array = mysql_fetch_array($result) //THIS IS LINE 58 IN MY CODE $results_counter++; if ($results_counter >= $number_of_results); ?> Firstly do you know why I would get this error? and secondly how do i call my results. I basically want to return my results and then later on format them into lists. I would also like each result to have a different variable name. eg. result1 = $result1 result 2 = $result2 result3 = $result3 etc. any guidance much appreciated. Im a bit lost.
  10. Would anybody be able to offer advice on a syntax isssue I have? $headers = 'From: me@me.com' . "\r\n" . 'Reply-To: me@me.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; $companyname = $_GET['companyname']; $doornumber = $_GET ['doornumber']; $street = $_GET ['street']; $town = $_GET['town']; $postcode = $_GET['postcode']; $useremail = $_GET ['useremail']; $telephone = $_GET['telephone']; $shortcode = substr($postcode,0,2); $query =mysql_query ("SELECT useremail FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3"); echo mysql_error(); echo "<p>The email addresses you have requested are;</p>"; while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; echo "$nt[0]<br>$nt[1]<br>$nt[2]<br>"; $message = "$firstname $lastname, from $town has searched for your details.\r\nYou may contact them on $telephone.\r\nThankyou."; $subject = "You Showed Up In The Tree Directory!"; $email = "$nt[0],$nt[1],$nt[2]"; $to = "$email"; mail( "$to", "$subject","$message", "$headers"); $message = "Thankyou for using the Tree Directory!\r\nThe email addresses that you have requested are;\r\n$nt[0]\r\n$nt[1]\r\n$nt[2]\r\n"; $email = "$useremail"; $to = "$useremail"; $subject = "Your Tree Directory Search Results"; mail( "$to", "$subject","$message", "$headers"); $query =mysql_query ("INSERT INTO customers ($firstname, $lastname, $doornumber, $street, $town, $postcode, $useremail, $telephone) (firstname, lastname, doornumber, street, town, postcode, useremail, telephone) ") ; echo mysql_error(); ?></body></html> My error message is; 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 '678, hbkjh, vgvi, EN7 6PX, edward_t_wright@hotmail.co.uk, 879086767869hv) (fir' at line 2 This refers to random input which I have typed into my html form. I can assume this error is in relation to; $query =mysql_query ("INSERT INTO customers ($firstname, $lastname, $doornumber, $street, $town, $postcode, $useremail, $telephone) (firstname, lastname, doornumber, street, town, postcode, useremail, telephone) ") as I have just added it. Please can anyone advise me as to how my syntax should look?
  11. Would anybody be able to offer advice on a syntax isssue I have? $headers = 'From: me@me.com' . "\r\n" . 'Reply-To: me@me.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; $companyname = $_GET['companyname']; $doornumber = $_GET ['doornumber']; $street = $_GET ['street']; $town = $_GET['town']; $postcode = $_GET['postcode']; $useremail = $_GET ['useremail']; $telephone = $_GET['telephone']; $shortcode = substr($postcode,0,2); $query =mysql_query ("SELECT useremail FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3"); echo mysql_error(); echo "<p>The email addresses you have requested are;</p>"; while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; echo "$nt[0]<br>$nt[1]<br>$nt[2]<br>"; $message = "$firstname $lastname, from $town has searched for your details.\r\nYou may contact them on $telephone.\r\nThankyou."; $subject = "You Showed Up In The Tree Directory!"; $email = "$nt[0],$nt[1],$nt[2]"; $to = "$email"; mail( "$to", "$subject","$message", "$headers"); $message = "Thankyou for using the Tree Directory!\r\nThe email addresses that you have requested are;\r\n$nt[0]\r\n$nt[1]\r\n$nt[2]\r\n"; $email = "$useremail"; $to = "$useremail"; $subject = "Your Tree Directory Search Results"; mail( "$to", "$subject","$message", "$headers"); $query =mysql_query ("INSERT INTO customers ($firstname, $lastname, $doornumber, $street, $town, $postcode, $useremail, $telephone) (firstname, lastname, doornumber, street, town, postcode, useremail, telephone) ") ; echo mysql_error(); ?></body></html> My error message is; 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 '678, hbkjh, vgvi, EN7 6PX, edward_t_wright@hotmail.co.uk, 879086767869hv) (fir' at line 2 This refers to random input which I have typed into my html form. I can assume this error is in relation to; $query =mysql_query ("INSERT INTO customers ($firstname, $lastname, $doornumber, $street, $town, $postcode, $useremail, $telephone) (firstname, lastname, doornumber, street, town, postcode, useremail, telephone) ") as I have just added it. Please can anyone advise me as to how my syntax should look?
  12. $query =mysql_query ("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' AND confirmed = 'Yes' ORDER BY companyName LIMIT 3"); Ive had a syntax issue since Ive added AND confirmed = 'yes' I want to return results if the value in my column named 'confirmed' reads the value 'yes' How should I put this into my query?
  13. Im a bit stuck with the syntax on my query line. Im a newbie looking for some help or advice. Should i put brackets around the actual query? Many thanks. $confirm = $_GET['Id']; echo $confirm; echo "<p>complete</p>"; $query =mysql_query "UPDATE treesurgeons SET confirmed = 'Yes' WHERE Id = $confirm"; echo mysql_error(); ?></body></html>
  14. Huge apologies, after a long delay Ive just recieved another email with the correct code, sorry guys.
  15. Yes, the number being stored in mysql database //1st value is different to the number appearing in my <a href ... //2nd value I can see that this is probably because $confirm = genRandomString(); causes a new random number to be assigned each time I use $confirm. However Im unsure as what to do about it.
  16. Good evening, Im using GenRandomString, and wondered how I can get $confirm to keep its first value throughout my script. I have put comments on the lines that use $confirm. Do I need to change $confirm to a constant and how can I go about this? $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; $companyname = $_GET['companyname']; $doornumber = $_GET ['doornumber']; $street = $_GET ['street']; $town = $_GET['town']; $postcode = $_GET['postcode']; $useremail = $_GET ['usermail']; $telephone = $_GET['telephone']; $shortcode = substr($postcode,0,2); function genRandomString() { $length = 10; $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = ""; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))];} return $string;} $confirm = genRandomString(); //creating a random number $query =mysql_query ("INSERT INTO treesurgeons (firstname, lastname, companyname, doornumber, street, town, postcode, useremail, telephone, Id) VALUES ('$firstname', '$lastname', '$companyname','$doornumber', '$street', '$town', '$postcode', '$useremail', '$telephone', '$confirm')");//1st Value echo mysql_error(); echo "<p>Thankyou for submiting your details.\r\n Please check your inbox and click on your confirmation link.</p>"; $message = "The following details have been submited to the tree directory and are awaiting confirmation; \r\n Please click on the link below to confirm these details are correct\r\n '$firstname', '$lastname', '$companyname','$doornumber', '$street', '$town', '$postcode', '$usermail', '$telephone' <a href='http://www.mywebsite.co.uk/confirmed.php?Id=$confirm'>"; //2nd Value $subject = "Your tree directory details"; $to = "$useremail"; $email = "$emailad"; mail( "$to", "$subject","$message", "$headers"); ?></body></html> I havent really played around with constants before, so please an advice appreciated! Im guessing im using DEFINE but im unsure how I would combine this with GenRandomString in my code.
  17. Thankyou, i have managed to get the below code to generate a random number; <html><body><?php function genRandomString() { $length = 10; $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = ""; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; } echo genRandomString(); ?></body></html> Do you know how I can now assign this random number to a variable. i would like to be able to go; <p>This is your random number; $random , thankyou</p>
  18. Im sure ive missed somthing from the code below! I get no error codes, but nothing displays. Just a frustrating blank white screen! Any idea? The eventual result im after is to generate a random 10 digit number to use as a customer ID number, for use within a confirmation link. I thought this would be stage 1. <html><body><?php function genRandomString() { $length = 10; $characters = ’0123456789abcdefghijklmnopqrstuvwxyz’; $string = (”; ) //brackets put here to stop phpfreaks.com displaying numbers for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))];} return $string;} echo "$string"; ?></body></html> Many thanks.
  19. I want to do an sql query, but I want it to happen only after my user has clicked on a confirmation link. The link will be sent to their email address. What is the usual procedure for this? For the time being Ive chucked what ive got into 1 php file, but I pressume I will need a couple of php files, and some how pass some variables from 1 page to the next??? $first = $_GET['first']; $last = $_GET['last']; $age = $_GET['age']; $$emailad = $_GET ['emailad'] $query =mysql_query ("INSERT INTO treesurgeons (FirstName, LastName, Age) VALUES ('$first', '$last', '$age')"); echo mysql_error(); echo "<p>Thankyou for submiting your details.\r\n Please check your inbox and click on your confirmation link.</p>"; $message = "The following details have been submited to the tree directory and are awaiting confirmation; $first $last, $age. \r\n Please click on the link below to confirm these details are correct"; //Do I include a link to an html file or php file? $subject = "Your tree directory details"; $to = "$email"; $email = "$emailad"; mail( "$to", "$subject","$message", "$headers"); //How do I trigger this email upon confirmation ?></body></html>
  20. I was unsure of which forum to post this in as it's not directly about your website, nor is it asking for coding help, but here goes anyway; Whilst learning php (ive a long way to go), it occured to me that I'm going against what the so called self-help books say about web development. Many books that I have read, say that I should learn html, css and javascript, before learning PHP. Lets say for examples sake, I was a php guru and there wasnt anything I didnt know about the php language. Would there be anything I could cover using javascript, that I was unable to cover with PHP?
  21. Please would somebody be able to show me or give me some tips as to how I go about getting an email to send in my php code? $headers = 'From: me@me.com' . "\r\n" . 'Reply-To: me@me.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $first = $_GET['first']; $last = $_GET['last']; $town = $_GET['town']; $telephone = $_GET['telephone']; $code = $_GET['postcode']; $shortcode = substr($code,0,2); $query =mysql_query ("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3"); echo mysql_error(); echo "<p>The email addresses you have requested are;</p>"; while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; echo "$nt[0]<br>$nt[1]<br>$nt[2]<br>"; $message = "$first . $last, from $town has searched for your details.<br>You may contact them on $telephone. <br> Thankyou."; $subject = "You Showed Up In The Tree Directory!"; $email = "$nt[0],$nt[1],$nt[2]"; $to = "$email"; mail( "$to", "$subject","$message", "$headers"); ?></body></html>
  22. Hi Sasa, your code works really well, thankyou to everyone that has helped me. Where was i going wrong Sasa? I noticed the $nt[] = $ntx[0]; ... what is happening here?
  23. Hi BH, i tried the code that you showed me. I like how the list function works, it's new to me. However if I go to use eg. $thirdmail elsewhere in my script, it doesn't appear to hold a value? $code = $_GET['postcode']; $shortcode = substr($code,0,2); $query =mysql_query ("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3"); echo mysql_error(); echo "<p>The email addresses you have requested are;</p>"; while(list($firstmail, $secondmail, $thirdmail)=mysql_fetch_row($query)){echo "{$firstmail}{$secondmail}{$thirdmail}<br>";} echo "<br>the third email address found in your query is $thirdmail"; //my html result displays nothing in place of $thirdmail when I echo it on this line? ?></body></html>
  24. What would be the correct way to use returned sql results as variables. I have tried the way in my script, but Im unsure of how I can echo just one of the $nt variables further on in my script. $code = $_GET['postcode']; $shortcode = substr($code,0,2); $query =mysql_query ("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3"); echo mysql_error(); echo "<p>The email addresses you have requested are;</p>"; while($nt=mysql_fetch_row($query)){echo "$nt[0],$nt[1],$nt[2]<br>";} echo "<p>please use $nt[2] if you ever want to contact me</p>"; //this line doesnt work for me ?></body></html> is there is a way to assign variables such as; $nt[0] = $firstemail $nt[1] = $secondemail $nt[2] = $thirdemail this way I could use each of my sql values, just as I would any other variable?
  25. Hi Ken, thankyou for showing me your code, the html output is; <html><body><h2>Business Names:</h2><br>Thank you for using our mail form.</body></html> and the email message reads; message here code <br>email1@1.com<br>email2@2.com<br>email3@3.com<br> maybe I could change the code somewhere along the line? i was thinking maybe I could do something like, case 0:$value1 = $row['Email']; break; case 1:$value2 =$row['Email']; break; case 2:$value3 =$row['Email']; break; and have each sql value as a unique variable. Do you think this would be easier to work with?
×
×
  • 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.