To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
Code CritiqueHaving someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.
<?php
include "http://www.streetfreaks.nl/includes/db.php";
#----------------------------Verklaring-------------------------------------------#
#vb. nick("user_level=3","<br>"); #
#vb. nicklogin("20","<br>"); 20 staat voor het aantal echo's #
#vb. verjaardag(); stuurt altijd mail naar een persoon die jarig is op dat moment.#
#---------------------------------------------------------------------------------#
function nick($a,$b)
{
$sql = mysql_query("SELECT nicknaam FROM users WHERE ".$a);
while ($row = mysql_fetch_object($sql))
{
echo $row->nicknaam.$b;
}
mysql_free_result();
mysql_close();
}
function nicklogin($a,$b)
{
$sql = mysql_query("SELECT nicknaam FROM users SORT BY last_visit LIMIT $a");
while ($row = mysql_fetch_object($sql))
{
echo $row->nicknaam.$b;
}
mysql_free_result();
mysql_close();
}
function verjaardag()
{
$sql = mysql_query("SELECT email_adres FROM users WHERE geb_datum=date(j-n-Y)");
$check = mysql_num_rows($sql);
if ($check > 0)
{
while ($row = mysql_fetch_object($sql))
{
$to = $row->email_adres;
$sub = "Gefeliciteerd";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Streetfreaks.nl <streetfreaks@streetfreaks.nl>\r\n";
$message = "
Gefeliciteerd !!
<img src=\"http://www.streetfreaks.nl/images/verjaardag.jpg\">
";
mail($mailto, $subject, $message, $headers);
}
}
mysql_free_result();
mysql_close();
}
?>
Well, personally when I'm making functions, or just using any variables, there's a meaning behind the naming of the variable. Sure, you may have to type a couple extra letters(oh my!), but at least I know what each one is. The whole $a and $b thing just doesn't work. Also, you may want to show an example of how these will work. SELECT nicknaam FROM users WHERE ".$a means you're not just passing a name to the function, but also a fieldname, and some formatting.
No checking of vars for malicios input before you use them in queries?
Calling mysql_close() on a connection that, from what I've seen, hasn't even been opened?
Ugly indents ( but that might just be the forum )?
I personally hate functions that just echo() data too, its nicer if they return; it so that I can manipulate it later and its a little more reusable, but thats just a matter of prefernece.