Jump to content

richard_PHP

Members
  • Posts

    79
  • Joined

  • Last visited

Everything posted by richard_PHP

  1. Hi all, I have a contact form on my website that I need help with. Fill out the form as usual, click submit and it sends an email with the info. Yes. But what happens should a necessary field get left out? Well then the email won't send yes? NO! I've worked on the server-side page for the sendmail but am now at a loss and am wondering where I've gone wrong. Basically there are 5 fields (name*, email*, business name, number* and message* (*=required)), got it HALF working, if one required field is entered then it sends the email. I want it if any field is left out then it says an error. Here's the code: $name = $_POST['name']; $email = $_POST['email']; $business = $_POST['business']; $number = $_POST['number']; $message = $_POST['message']; //leave the next 2 lines alone $headers .= "MIME-Version: 1.0rn"; $headers .= "Content-Type: text/html; charset=ISO-8859-1rn"; if ($name . $email . $number . $message == "") { echo "<p>You appear to not have filled in the necessary fields.</p>"; echo "<p>Please click <a href='contact.html'>here</a> to re-enter your information.</p>"; } Is there also a way to send the user back to the form (.html page) with all their information still entered? Many thanks!
  2. i love this forum! =D lol worked a treat, thanks for your help.
  3. hi all, ive made a page to update a 'blog' however, when i accidentally went on the processing page it added a blank entry into the blog. i want it so that if the page is accessed directly it wont add to the blog. ive tried adding the 'emtpy' syntax but it doesnt work. some of the code $date = $_POST['date']; $title = $_POST['title']; $text = $_POST['entry']; $sql = "INSERT INTO `*****`.`blog` (`entry_id`, `entry_date`, `entry_title`, `entry_text`) VALUES (NULL, '$date', '$title', '$text')"; $result = mysql_query($sql); if ($result) { echo "<p>The following entry:<br /><strong>$date - $title</strong><br /> was added into the database."; echo "<p>Click <a href='updateblog.html'>here</a> to add another entry</p>"; } if (empty($date)) { echo "<p>You have not entered any data. Blog not updated.</p>"; echo "<p>Click <a href='updateblog.html'>here</a> to add another entry</p>"; } else { echo "<p>There was a problem. <br /> $sql <br /> ".mysql_error()."</p>"; }
  4. thanks. implemented it and it seems simpler than what i did. many thanks again. =D
  5. got it working! that was easier than i first thought it was. looking back, i could have been a bit clearer with what i wanted. but here's the final code: <?php $random = rand(1,5); $conn = mysql_connect("xxxx", "xxx", "xxx"); mysql_select_db("xxx", $conn); $sql = "SELECT * FROM xxx WHERE id = '$random'"; $result = mysql_query($sql, $conn); $array = mysql_fetch_array($result); echo "<p><img src=".$array[thumb]." /><br />"; echo "<a href='info.php?id=$random'>".$array[title]."</a></p>"; ?> thanks for the help though! =D
  6. no no no! lol.. that bit of code was just to show what the database table contains. im trying to have a crack at it, ill let you know how it goes.
  7. back with, hopefully, the last problem for a while. scenario: im wanting to perform a php rand() function so that random projects are displayed in a page. im wanting to use the id number as the variable but i cant think on how to write it. what's in the database table: $sql = "SELECT 'id', 'img', 'thumb', 'url', 'title', 'description' FROM xxx ORDER BY id"; all im going to display is THUMB and TITLE, but as said i cannot for the life of me think of a way to write it!!! pre-thanks for your help.
  8. i love you michdd!!!! lol.. it works at last! lol thank you all for the help, sorry if it seemed a pain. just thank god its working now! cheers!!!
  9. tried all suggested methods and its still not working :'( :'(
  10. had a look into it and found that i needed '' instead of NULL for the id. doing this, it now says that the project was added to the database. when checking..... it isnt. heres the code as it stands at the moment: <?php // Start the connection to the database $conn = mysql_connect("xxx", "xxx", "xxx"); // Select the database to use mysql_select_db("xxx", $conn); // Assign the posted values as variables to use later $img = $_POST[img]; $thumb = $_POST[thumb]; $url = $_POST[url]; $title = $_POST[title]; $description = $_POST[description]; $type = $_POST[type]; // Create the MySQL command which adds the user's information into the database. $sql = "INSERT INTO xxx (`id`, `img`, `thumb`, `url`, `title`, `description`, `type`) VALUES ('', '$_POST[img]', '$_POST[thumb]' '$_POST[url]', '$_POST[title]', '$_POST[description]', '$_POST[type]')"; $result = mysql_query($sql); if (!$result) { echo "<p><strong>$title</strong> was added into the database. Would you like to:</p>"; echo "<p>- <a href='insert.html'>Add another</a></p>"; } else { echo "<p>There was a problem.</p>"; } ?>
  11. "Column count doesn't match value count at row 1"
  12. had it like that before and it didnt work, changed it back and it still doesnt work. and the error message that comes up is the else statement error.
  13. the worlds most easiest bit of code and it aint working!!!! ive checked the database, the page thats sending the information and een this one to make sure everything is the same but it keeps displaying the error message. code: <?php $conn = mysql_connect("xxx", "xxx", "xxx"); mysql_select_db("xxx", $conn); $img = $_POST[img]; $thumb = $_POST[thumb]; $url = $_POST[url]; $title = $_POST[title]; $description = $_POST[description]; $type = $_POST[type]; $sql = "INSERT INTO xxx VALUES ('', '$_POST[img]', '$_POST[thumb]' '$_POST[url]', '$_POST[title]', '$_POST[description]', '$_POST[type]')"; $result = mysql_query($sql); if ($result) { echo "<p><strong>$title</strong> was added into the database. Would you like to:</p>"; echo "<p>- <a href='insert.html'>Add another</a></p>"; } else { echo "<p>There was a problem.</p>"; } ?>
  14. change of brief now means that im using a database system, however thanks for the help. its here when i next need it. much appreciated!
  15. realised that a variable wasnt right. heres the ammended, still broke, code: <?php $path = "uploads/"; $new_name = $path, $_POST['files']; if (is_dir($path)) { if ($dh = @opendir($path) or die ("Directory failed to open.")) { while (($file = readdir($dh)) !== false) { if($file!="." && $file!=".." && $file!="thumbs.db"){ if (file_exists($path . $new_name)){ rename($file, $new_name); echo "File was successfully renamed."; } else { echo "Sorry, the file was not renamed due to an error. Please <a href='loggedphotos.php'>try again</a>."; } } } } } ?>
  16. didnt think there was one. lol oops!. added it and tweaked a bit but it comes up with a blank page (with the styling but no messages displayed). <?php $new_name = $_POST['files']; $path = "uploads/"; if (is_dir($dir)) { if ($dh = @opendir($dir) or die ("Directory failed to open.")) { while (($file = readdir($dh)) !== false) { if($file!="." && $file!=".." && $file!="thumbs.db"){ if (file_exists($path . $new_name)){ rename($file, $new_name); echo "File was successfully renamed."; } else { echo "Sorry, the file did not delete properly. Please try again."; } } } } } ?>
  17. hello all back again with another problem with my dissertation. im wanting to rename a file, but its in the directory and not a database. here it is live: http://scape-pictures.110mb.com/loggedphotos.htm so when the filename in the textbox is altered, so far it says file was renamed. but it hasnt been. code: loggedphotos.php <form action="rename.php" method="post" name="list"> <?php // define directory path $dir = "uploads"; // iterate through files // look for JPEGs if (is_dir($dir)) { if ($dh = @opendir($dir) or die ("Directory failed to open.")) { while (($file = readdir($dh)) !== false) { if($file!="." && $file!=".." && $file!="thumbs.db"){ if (preg_match("/.jpg/", $file)) { // get thumbnail // link to full image echo "<p><img src='".$dir."/".$file."' class='thumb' border='2' /> <input name='files' type='text' width='300' value=".$file." /></p>"; } } } closedir($dh); } } echo "<p><input name='submit' type='submit' value='Rename File' /></p>"; ?> </form> rename.php <?php $new_name = $_POST['files']; $path = "uploads/"; if (file_exists($path . $new_name)){ move_uploaded_file($path . $new_name); echo "File was successfully renamed."; } else { echo "Sorry, the file did not delete properly. Please try again."; } ?>
  18. anyone care to help with this one?
  19. hello all, back with a new problem. scenario: im wanting to display clickable thumbnails of jpegs located in a directory. ive found some code for it but after testing it, found it doesnt work and displays the following message: heres the code: <?php // define directory path $dir = "uploads/"; // iterate through files // look for JPEGs if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if (preg_match("/.jpg/", $file)) { // read Exchangeable Image File (EXIF) headers for info $exif = exif_read_data($file, 0, true); echo "<tr>"; // get thumbnail // link to full image echo "<td valign=top><a href=$dir/$file><imgsrc=thumbnail.php?file=$file></a><td>"; echo "<td valign=top><font size=-1>"; // get file name echo "File: <b>" . $exif['FILE']['FileName'] . "</b><br/>"; // get timestamp echo "Timestamp: " . $exif['IFD0']['DateTime'] . "<br/>"; // get image dimensions echo "Dimensions: " . $exif['COMPUTED']['Height'] . " x " . $exif['COMPUTED']['Height'] . " <br/>"; // get camera make and model echo "Camera: " . $exif['IFD0']['Model']; echo "</font></td>"; echo "</tr>"; $image = exif_thumbnail($dir . "/" . $_GET['file']); header("Content-Type: image/jpeg"); echo $image; } } closedir($dh); } } ?> i appreciate all help and also if anyone has working code i would appreciate (and will reference) the code. many thanks!
  20. well the database i have was pre made by the lecturer and i dont think hed take too kindly for token tables appearing so im gonna hazard a guess at the clients computer and inserted in the cart code?
  21. yeyy it works! thank you! right, next up the sessions. im not really a pro and nor do i have much of a clue on how to work with them. tried the w3 schools tut on them but am still clueless. i have the session_start(); at the beginning of each php file (before <html>). when a link is clicked to view the cart, its empty. heres the script from the list of radios in case you need it: <?php if ($_GET[make] == '') { $where = ""; } else { $where = " WHERE make = '".$_GET[make]."'"; } $conn = mysql_connect("***", "***", "***"); mysql_select_db("***", $conn); $sql = "SELECT * FROM ****" . $where; $result = mysql_query($sql, $conn) OR die ("Cannot read from DB " . mysql_error($conn)); $rows = mysql_num_rows ($result) or die ("No entries yet."); echo "<div align='center'><b>There are $rows radios in the DB</b></div>\n"; ?> <table border="0" cellspacing="5"> <?php while ($row = mysql_fetch_array ($result)) { echo "<tr><td><input type='hidden' name=".$row["id"]." value=".$row["id"]."></td><td>".$row["make"]."</td><td>".$row["model"]."</td><td>".$row["description"]."</td><td>£".$row[price]."</td><td><a href='cart1.php?id=$row[id]'>Add to Cart</a></td></tr>\n"; } ?> The cart code as pasted before this.
  22. okay. tried it but it now comes up with: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ******** on line 31 checked code and all seems fine, no typos or anything like that.. >
  23. back again this time with a pain in the bum one. no matter how hard i try i just get that infinite script of doom business going on. scenario: try and make a basic shopping basket and add ajax on for extra features. that bits fine, only when you click ADD TO CART then the code just has the '$make - $model' repeated over and over in that loop. helpings please! CODE: <?php $conn = mysql_connect("***", "***", "***"); mysql_select_db("***", $conn); $sql = "SELECT * FROM *** WHERE id = '".$_SESSION['id']."'"; $result = mysql_query($sql, $conn); $row = mysql_fetch_array($result); while ($row) { echo "<p>Item: $row[make] - $row[model]</p>"; } ?> also, there is a box in the top corner of the browser windw where you can view the current basket at any time. only it doesnt display, my conclusion is that i dont know much about sessions but tried to use them to no avail. get this infinite thing stopped first!
  24. got it working. had to change a session elsewhere
×
×
  • 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.