Jump to content

Form data formatting


tutorialstuff

Recommended Posts

Well I'm working on a form that eventually will have the data submitted to a database. I have everything working properly and  the wa I want it to for now, it just seems like I have taken the long way around to get to where I want. Can anybody look at my php code and tell me how I can clean it up? Thanks!

 

 

<?php
include'../../connections/townnews.php';
mysql_select_db("tdn_com",$db);

function safe($val){
if (is_array($val)){
	foreach($val as $key => $v)
		$val[$key] = safe($v);
	return $val;
} else {
	if (get_magic_quotes_gpc())
		$val = stripslashes($val);
	return mysql_real_escape_string($val);
}
}

$_POST = safe($_POST);
$_GET = safe($_GET);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" src="calendarDateInput.js"></script>
</head>

<body>
<?php 
$section = htmlspecialchars(stripslashes($_POST['section']));
$name = htmlspecialchars(stripslashes($_POST['name']));
$assignmentdate = htmlspecialchars(stripslashes($_POST['assignmentdate']));
$wording = htmlspecialchars(stripslashes($_POST['wording']));
$wording = str_replace("rn", "<br />", $wording);
print "
$section<br />
$name<br />
$assignmentdate<br />
$wording"; 
?>
<form action="index.php" method="post">
<select name="section">
<?php
$announcement_type_query = mysql_query("SELECT * FROM `announcment_type` ORDER BY `section` ASC");
while($announcement_type_results=mysql_fetch_assoc($announcement_type_query)){
	print"<option value=\"$announcement_type_results[announcment_type_id]\">$announcement_type_results[section]</option>";
}
?>
</select>
<input type="text" name="name" value="" />
<script>DateInput('assignmentdate', true, 'MM/DD/YYYY')</script>
<textarea name="wording"></textarea>
<input type="submit" value="submit" />

</form>


</body>
</html>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.