A mysql table with 8 field, which 4 value i want to take from a form and other 4 value from initializing variable. My code is here…
1st field is auto increment, all value is inserting in table except initialized variable $cat and $subcat…
[I]
<?php
$cat = "aits";
$subcat = "asdf";
if (isset($_POST[‘name’]) && isset($_POST[‘body’])) {
$ret = add_to_database();
if (!$ret) {
print “”;
} else {
print “Thank you for submission”;
}
} else {
write_form();
}
//functions
function write_form() {
$self =$_SERVER[‘PHP_SELF’];
echo <<<EOT
<form action=“$self” method=“POST”>
<table>
<tr>
<td width=“50”>Cell 1</td>
<td width=“350”><input type=“text” name=“name” style=“width:100%”/></td>
</tr>
<tr>
<td>Cell 3</td>
<td><textarea name=“body” cols=“41” rows=“5” name=“des”>
</textarea></td>
</tr>
<tr>
<td>Cell 3</td>
<td><input type=“text” name=“url” style=“width:100%”/></td>
</tr>
<tr>
<td>Cell 3</td>
<td><input type=“text” name=“email” style=“width:100%”/></td>
</tr>
</table>
</br>
<input type=“submit” style=“margin-left:200px” value=“submit”/>
</form>
EOT;
}
echo “$cat”;
echo “</br>”;
echo “$subcat”;
function add_to_database() {
$name = trim($_POST[‘name’]);
$body = trim($_POST[‘body’]);
$url = trim($_POST[‘url’]);
$email = trim($_POST[‘email’]);
echo “$cat”;
echo “</br>”;
echo “$subcat”;
$date=date("Y-m-d");
mysql_connect("localhost","root", "mdismail") or die("Couldn't connect to server");
mysql_select_db("test");
$sql = "INSERT INTO submit VALUES (' ','$name','$body','$url','$email','$cat','$subcat','$date')";
mysql_query($sql);
mysql_close();
return true;
}
echo “$cat”;
?>[/I]
please give me a solution