Mxb_Design Posted December 17, 2008 Share Posted December 17, 2008 Okay, so I have this code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Email Subscibe for Dafmusic</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $con = mysql_connect("localhost","USERNAME","PASSWORD"); if (!$con) { die('Could not connect: ' . mysql_error()); } else { echo "<h2>Connection Successful</h2><br /><br />"; } mysql_select_db("havens2_EmailSubscribe", $con); $result = mysql_query("SELECT * FROM Details ORDER BY UserID"); if (!$result) { echo "<br /><h4>Connection Unsuccessful When Accessing DB</h4><br />"; } /*while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; }*/ echo "<h4> Database</h4><br />"; echo "<table border='1'> <tr> <th>UserID</th> <th>FirstName</th> <th>Email</th> <th>JoinDate</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['UserID'] . "</td>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['Email'] . "</td>"; echo "<td>" . $row['JoinDate'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); echo "<br /><h4>Form</h4><br />"; echo "<form action=\"insert.php\" method=\"post\">"; echo "First Name: <input type=\"text\" name=\"FirstName\" /> "; echo "Email Address: <input type=\"text\" name=\"Email\" /><br /><br />"; echo "<input type=\"submit\" /><br />; echo "<br /><h4>Admin Commands</h4><br />"; ?> </body> </html> and insert.php: <?php $con = mysql_connect("localhost","havens2_webmast","Hex5Forty6"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("havens2_EmailSubscribe", $con); $sql="INSERT INTO Details (FirstName, Email, JoinDate) VALUES ('$_POST[FirstName]','$_POST[Email]','".date("Y-m-d")."')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } else { echo "Thank you- your details have now been added to our database. Look out for your newsletter soon! <br /> <br /> <a href=\"http://giftedhaven.net/PHP/MySQLTest.php\">Take me back</a> "; } mysql_close($con); ?> My question is A, how do I make it so that a user cannot enter empty values, as one of them is. I guessed it would be some kind of if statement, but, I don't know where to put it, and any help books I have have been quite unhelpful. And B, how do I create a mailto link that sends to multiple people from a database? any help? Thanks awfully Link to comment https://forums.phpfreaks.com/topic/137427-solved-mailto-links-and-empty-values/ Share on other sites More sharing options...
phpian Posted December 17, 2008 Share Posted December 17, 2008 there are many ways to perform validation on required fields. many people use isset and strlen > 0. i just like to go: if ($_REQUEST['FirstName'] == '') { //some error handling code } else { //it's all good code } for creating a mailto link, well i don't think that's possible and even if it is i don't think you would want to do it like that. lookup the php mail() function. you use that to send out emails Link to comment https://forums.phpfreaks.com/topic/137427-solved-mailto-links-and-empty-values/#findComment-718121 Share on other sites More sharing options...
Mxb_Design Posted December 17, 2008 Author Share Posted December 17, 2008 I did wonder if there was another function for it- thanks yuppers, that code works XD Thanks again Link to comment https://forums.phpfreaks.com/topic/137427-solved-mailto-links-and-empty-values/#findComment-718126 Share on other sites More sharing options...
phpian Posted December 17, 2008 Share Posted December 17, 2008 no probs Link to comment https://forums.phpfreaks.com/topic/137427-solved-mailto-links-and-empty-values/#findComment-718128 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.