Jump to content

UCWORDS to format text going into mysql table


barniegilly

Recommended Posts

This is all the PHP

 

<?php
 	// 2. NEW USER REGISTRATION<br />
	include_once ("../includes/form_functions.inc.php");

	// START FORM PROCESSING FOR A NEW REGISTRATION
	if (isset($_POST['newvenue'])) { // Form has been submitted.
	$errors = array();

	// perform validations on the form data
	$required_fields = array('ven_name', 'town', 'ven_website');
	$errors = array_merge($errors, check_required_fields($required_fields, $_POST));

	$fields_with_lengths = array('ven_name' => 100, 'street' => 60,'area' => 50, 'town' => 30,  
								'post_code' => 10,  'ven_website' => 100);

	$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));

	$ven_name = trim(ucwords(mysql_prep($_POST['ven_name'])));
	$street = trim(ucwords(mysql_prep($_POST['street'])));
	$area = trim(ucwords (mysql_prep($_POST['area'])));
	$town = trim(ucwords (mysql_prep($_POST['town'])));
	$area = trim(ucwords (mysql_prep($_POST['area'])));
	$county_id = mysql_prep($_POST['county_id']);
	$post_code = trim(mysql_prep($_POST['post_code']));
	$ven_contact = trim(ucwords(mysql_prep($_POST['ven_contact'])));
	$ven_email = trim(mysql_prep($_POST['ven_email']));
	$ven_website = trim(strtolower(mysql_prep($_POST['ven_website'])));
	$ven_telno = (mysql_prep($_POST['ven_telno']));
	$userid = $_POST['user_id'];

	if ( empty($errors) ) {
		$query = "INSERT INTO venue (ven_name, street, area, town, county_id, 
									 post_code, ven_contact, ven_email, ven_website, 
									 ven_telno, user_id) 
				  VALUES ('{$ven_name}', '{$street}', '{$area}', '{$town}', '{$county_id}',
						  '{$post_code}', '{$ven_contact}', '{$ven_email}','{$ven_website}', 
						  '{$ven_telno}', '{$userid}' )";
		$result = mysql_query($query, $connection);
		if ($result) {
			$message = redirect_to("controlpanel.php");


		} else {
			$message = "I am sorry but the venue could not be created.";
			$message .= "<br />" . mysql_error();
		}
	} else {
			/* this counts the number of errors and informs the user of how many fields were
			incorrectly entered*/
		if (count($errors) == 1) {
			$message = "There was 1 error in the form.";
		} else {
			$message = "There were " . count($errors) . " errors in the form.";
		}
	}
} else { // Form has not been submitted.

	$ven_name = "";
	$street = "";
	$area = "";
	$town = "";
	$area = "";
	$county_id = "";
	$post_code = "";
	$ven_contact = "";
	$ven_telno = "";
	$ven_email = "";
	$ven_website = "";
	$userid = "";
}
?>

 

 

This is the form

 

 

   				<form id="newvenue" action="newvenue.php" method="post">
  					<?php if (!empty ($message)) {echo "<p class=\"message\">" . $message . "</p>";}?>
					<?php if (!empty ($errors)) {display_errors($errors); }?><br />
      					<table id="neweventdisplay" cellpadding="5"  border="0"> 
                            <tr>
                                <td></td>
                                <td></td>
                                <td><input type="hidden" name="user_id"  value="<?php echo $url_userid ['user_id']; ?>" /></td>
                            </tr>
                            <tr>
                                <td><span class="compuls">*</span></td>
                                <td class="heading">Venue Name</td>
                                <td><input class="input50px" id="ven_name" name="ven_name" type="text" value="<?php echo htmlentities($ven_name); ?>" /></td>
                            </tr>
</table>

 

I have checked my CSS and cannot see any code that would be changing anything

ucwords will only affect the first letter of each word, so if you have other uppercase letters, they will remain so unless you transform everything to lowercase, and then apply ucwords:

 

combine ucwords with strtolower:

 

$ven_name = ucwords(strtolower(mysql_prep(trim($_POST['ven_name']))));

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.