i prefer the functions, to make form fields, or make SQL query with a list of (mysql) fields name.
here is an example to a form processor with php... think, how to create a fuction to make these form elements... 🙂(default values of course printed with $_POST... )
<form name="form1" method="post" action="?">
Email1: <input type="text" name="email1"><br>
Email2(not required!): <input type="text" name="email2"><br>
Password<input type="password" name="password"><br>
Message: <input type="text" name="message"><br>
<input type="submit" name="Submit" value="Submit">
</form>
<?php
include("connect.php");
function sqlstring($table,$fields){
$sql="INSERT INTO $table (";
$sql1="";
$sql2="";
global $warning;
$fields=explode(",",$fields);
foreach($fields AS $key)
{
$required=explode(":",$key);
$key=$required[0];
$req=$required[1];
$properties=$required[2];
if(strstr($properties,"email"))
{
$rexp_string_filter="^[^0-9][A-z0-9_-]+[@][A-z0-9_-]+([.][A-z0-9_-]+)*[.][A-z]{2,4}$";
if(!ereg($rexp_string_filter, $_POST["$key"]))
$warning.="$key field must be an email...<br>";
}
if($req==1 AND empty($_POST[$key]))
$warning.="$key field must be filled/selected...<br>";
if(empty($_POST[$key]))
$_POST[$key]="";
$sql1.=" $key,"; //this is the field name..
if(strstr($properties,"pass"))
$sql2.="'".md5(stripslashes($_POST[$key]))."',";
else
$sql2.="'".mysql_real_escape_string(stripslashes($_POST[$key]))."',";
// print $key."<br>";
}
$sql.=$sql1.") VALUES (".$sql2;
$sql.=");";
$sql=str_replace(",)",")",$sql);
$sql=str_replace("',)" , "')",$sql);
return ($sql);
}
if(!empty($_POST))
{
$warning="";
/* list the field names, and add with a : sign if it is required,
for example the second email is not required, but must be an email :)
if a field is not required to fill, set 0 into the secont property...
if it is a password, add a property pass ...
just for fun, you can required an email as a password - field_name:1:passemail !
and it gives back the warning in $warning variable...
*/
$sql=sqlstring("table_suggest","email1:1:email,email2:0:email,message:1,password:1:pass");
if($warning=="")
{
print $sql; //test its value before use it
// include("connect.php");
// $result=mysql_query($sql) or die(mysql_query(). $sql);
}
else
print $warning."<br>";
}
?>