Hello friends,
I'm creating a website where i've 2 tables called areas and profiles. In the areas table i've the ID and name of area where i can add, update or delete any area.
My problem starts with the profiles table. It has a column called areas alongwith other columns/fields. Now i've an html table where the user can put all the fields for the profiles tables. The areas field in this table is a checkbox array that is pulled from the areas table. I can pull the data from the areas table and make checkboxes for each area in the html table for profiles, but i need to know how can i be able to add or update or delete the data into/from the profiles table.
Here is my code for the profiles table for adding data:
<?php
include('../dbconn.php');
if( !empty($_POST) )
{
$sql = "INSERT INTO attorney_profiles (firstname,lastname,email,password,biography,practice_areas)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[password]','$_POST[biography]','$_POST[practice_areas]')";
// exit(print($sql));
if (!mysql_query($sql,$mysql_link))
{
die('Error: ' . mysql_error());
}
else
{
header("Location: add_profile.php");
}
if(!$sql)
{
echo "No data.";
}
}
?>
<html>
<head>
</head>
<body>
<script language="Javascript">
function checkForm(form)
{
if(form.firstname.value=="")
{
alert("Please enter a First Name!!");
form.firstname.focus();
return(false);
}
if(form.lastname.value=="")
{
alert("Please enter a Last Name!!");
form.lastname.focus();
return(false);
}
if(form.email.value=="")
{
alert("Please enter an E-Mail address!!");
form.email.focus();
return(false);
}
if(form.password.value=="")
{
alert("Please enter a Password!!");
form.password.focus();
return(false);
}
}
</script>
<form name="form" action="add_profile.php" method="POST" onSubmit="return checkForm(this)">
<table border='0'>
<tr>
<td>
<b>First Name* :</b> <br>
<input type="text" name="firstname" value="<?php print($firstname);?>" />
</td>
</tr>
<tr>
<td>
<b>Last Name* :</b> <br>
<input type="text" name="lastname" value="<?php print($lastname);?>" />
</td>
</tr>
<tr>
<td>
<b>E-Mail Address* :</b> <br>
<input type="text" name="email" value="<?php print($email);?>" />
<i>(e.g., abc@xyz.com)</i>
</td>
</tr>
<tr>
<td>
<b>Password*:</b> <br>
<input type="password" name="password" value="<?php print($password);?>" />
</td>
</tr>
<tr>
<td>
<b>Biography:</b> <br>
<TEXTAREA name="biography" class="biography"><?php print($biography);?></TEXTAREA></td>
</tr>
<tr>
<td>
<b>Practice Areas:</b> <br>
<?php
$sql1 = mysql_query("SELECT DISTINCT(area_name) FROM practice_areas ORDER BY area_name"); ?>
<?php
while($row1 = mysql_fetch_array($sql1))
{
echo "<input type=\"checkbox\" name=practice_areas[] />$row1[0]<br />";
}
?>
</tr>
</table>
<br>
<input type="submit" value="Add" id="submit" name="submit" />
</form>
</body>
</html>
The following part of the above code pulls the data from the areas table and makes them checkboxes for the html table for profiles table....
table i've the ID and name of area where i can add, update or delete any area.
My problem starts with the profiles table. It has a column called areas alongwith other columns/fields. Now i've an html table where the user can put all the fields for the profiles tables. The areas field in this table is a checkbox array that is pulled from the areas table. I can pull the data from the areas table and make checkboxes for each area in the html table for profiles, but i need to know how can i be able to add or update or delete the data into/from the profiles table.
Here is my code for the profiles table for adding data:
[code=php]
<?php
include('../dbconn.php');
if( !empty($_POST) )
{
$sql = "INSERT INTO attorney_profiles (firstname,lastname,email,password,biography,practice_areas)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[password]','$_POST[biography]','$_POST[practice_areas]')";
// exit(print($sql));
if (!mysql_query($sql,$mysql_link))
{
die('Error: ' . mysql_error());
}
else
{
header("Location: add_profile.php");
}
if(!$sql)
{
echo "No data.";
}
}
?>
<html>
<head>
</head>
<body>
<script language="Javascript">
function checkForm(form)
{
if(form.firstname.value=="")
{
alert("Please enter a First Name!!");
form.firstname.focus();
return(false);
}
if(form.lastname.value=="")
{
alert("Please enter a Last Name!!");
form.lastname.focus();
return(false);
}
if(form.email.value=="")
{
alert("Please enter an E-Mail address!!");
form.email.focus();
return(false);
}
if(form.password.value=="")
{
alert("Please enter a Password!!");
form.password.focus();
return(false);
}
}
</script>
<form name="form" action="add_profile.php" method="POST" onSubmit="return checkForm(this)">
<table border='0'>
<tr>
<td>
<b>First Name* :</b> <br>
<input type="text" name="firstname" value="<?php print($firstname);?>" />
</td>
</tr>
<tr>
<td>
<b>Last Name* :</b> <br>
<input type="text" name="lastname" value="<?php print($lastname);?>" />
</td>
</tr>
<tr>
<td>
<b>E-Mail Address* :</b> <br>
<input type="text" name="email" value="<?php print($email);?>" />
<i>(e.g., abc@xyz.com)</i>
</td>
</tr>
<tr>
<td>
<b>Password*:</b> <br>
<input type="password" name="password" value="<?php print($password);?>" />
</td>
</tr>
<tr>
<td>
<b>Biography:</b> <br>
<TEXTAREA name="biography" class="biography"><?php print($biography);?></TEXTAREA></td>
</tr>
<tr>
<td>
<b>Practice Areas:</b> <br>
<?php
$sql1 = mysql_query("SELECT DISTINCT(area_name) FROM practice_areas ORDER BY area_name"); ?>
<?php
while($row1 = mysql_fetch_array($sql1))
{
echo "<input type=\"checkbox\" name=practice_areas[] />$row1[0]<br />";
}
?>
I hope you guys can help me out with this. I need to finish this project very soon.
Thanks.