Jump to content

Spriced

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Spriced's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Here's what I use on my website: <form id="contact-form" action="send-mail.php" method="post"> <label for="name">Name</label> <input type="text" name="name" id="name" /> <label for="email">Email</label> <input type="text" name="email" id="email" /> <label for="message">Message</label> <textarea name="message" id="message" rows="5" cols="35"></textarea> <input type="submit" class="submit" value="Send" /> </form> <?php function validate_email($email) { return filter_var($email, FILTER_VALIDATE_EMAIL); } if (isset($_POST['name'])) { // The form was submitted $n = trim(stripslashes(strip_tags($_POST['name']))); $e = trim(stripslashes(strip_tags($_POST['email']))); $m = trim(stripslashes(strip_tags($_POST['message']))); $eol = "\r\n"; if (validate_email($e) && !empty($n) && !empty($m)) { // Form was filled in correctly $s = "Enquiry from $n"; // Subject $t = "YOUR EMAIL ADDRESS"; // Your email address $headers.= "To: YOUR NAME <$t>".$eol; $headers.= "From: $n <$e>".$eol; if(mail($t, $s, $m, $headers)) { // Everything went fine echo '<p class="response-good">You email has been sent, thanks.</p>'; } else { // Mail function failed echo '<p class="response-bad">There was a problem sending the email, please try again later.</p>'; } } else { // Email didn't validate or name or message fields were empty after processing echo '<p class="response-bad">Please fill out all fields & ensure that your email is valid.</p>'; } } else { // Form wasn't filled out echo '<p class="response-bad">Please fill out the form.</p>'; } ?> You can easily modify it to your needs.
  2. Also, on a side note, your code has a couple of other small errors : echo "<div id='piccontentalign' align='center'>"; echo "<td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td>"; echo "</div>"; // This closes the <div id='piccontentalign' align='center'>. But wrapping a table cell in a div isn't valid, I'm sure you don't need it } // end while echo "</tr></table></div>"; // The </div> is erroneous
  3. This should work: <?php $host = "localhost"; // $user = ""; //username to connect to database $pass = ""; //password to connect to database $db = ""; //the name of the database mysql_connect($host,$user,$pass) or die("ERROR:".mysql_error()); mysql_select_db($db) or die("ERROR DB:".mysql_error()); $max = 25; //amount of articles per page. $p = $_GET['p']; if(empty($p)) { $p = 1; } $limits = ($p - 1) * $max; //view the article! if(isset($_GET['act']) && $_GET['act'] == "view") { $id = $_GET['id']; $sql = mysql_query("SELECT * FROM 3dpics WHERE id = '$id'"); while($r = mysql_fetch_array($sql)) { $title = $r['title']; $url = $r['url']; echo "<div align='center'><img src='$url' width='500' height='500'><br />$title<br /><br /><a href='test.php'>Back</a></div>"; } } else { //view all the articles in rows $sql = mysql_query("SELECT * FROM 3dpics LIMIT ".$limits.",$max") or die(mysql_error()); //the total rows in the table $totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM 3dpics"),0); $totalpages = ceil($totalres / $max); // $numCols = 5; $counter = 1; // echo "<table name='myTable' cellpadding='5' cellspacing='5'>"; echo "<tr>"; //the table while($r = mysql_fetch_array($sql)) { $id = $r['id']; $title = $r['title']; $url = $r['url']; echo "<div id='piccontentalign' align='center'>"; echo "<td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td>"; // if ($counter % $numCols == false && $counter != $max) { echo "</tr>"; echo "<tr>"; } $counter++; // } echo "</tr></table></div>"; //close up the table for($i = 1; $i <= $totalpages; $i++) { //this is the pagination link echo "<a href='test.php?p=$i'>$i</a>|"; } } ?> The extra lines I added are in between empty comments. I also added an extra argument in the if statement to prevent an extra table row being added on the end. It should give you markup something like: <table name='myTable' cellpadding='5' cellspacing='5'> <tr> <!-- while loop --> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <!-- if statement --> </tr> <tr> <!-- end if statement --> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <!-- if statement --> </tr> <tr> <!-- end if statement --> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <div id='piccontentalign' align='center'> <td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td> <!-- endwhile loop --> </tr> </table>
  4. I forgot to add the counter incrementation to the end of the while loop : $numCols = 5; $counter = 1; echo "<table>"; echo "<tr>"; //the table while($r = mysql_fetch_array($sql)) { $id = $r['id']; $title = $r['title']; $url = $r['url']; echo "<td>Cell content</td>"; echo "<td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td>"; if ($resultNum % $numCols == false) { echo "</tr>"; echo "<tr>"; } // end if $counter++; // This line } // end while echo "</tr>"; echo "</table></div>";
  5. You need to use the modulus operator to add table rows. Something like this: <?php $numCols = 5; $counter = 1; echo "<table>"; echo "<tr>"; while(...) { echo "<td>Cell content</td>" if ($resultNum % $numCols == false) { echo "</tr>"; echo "<tr>"; } // end if } // end while echo "</tr>"; echo "</table>"; ?> I've simplified it a bit to try and make it clearer. Here is another very simple example of the modulus operator: <?php for ($i = 1; $i < 50; $i++) { echo "<p>$i</p>"; if ($i % 5 == false) { // This will appear every 5 lines echo "<b>++++++++++</b>"; } } ?> Make sure the counter doesn't start at 0 because then the code in if statement will run as it will be true. http://php.net/manual/en/language.operators.arithmetic.php
  6. Hi, How would you use the Amazon API to display recently read books, etc? I thought maybe all I'd need is the isbn to grab an image, text, link, etc through the API? Is this possible with the Amazon API? I'm new to APIs in general & have been searching around for a couple of days for tutorials but can't find anything! I've got an API key but don't know where to go next 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.