barniegilly Posted September 2, 2011 Share Posted September 2, 2011 Hi I have the following for an input form, I was under the impression that ucwords would format the text into Initial Characters, but this does not do that? What have I done wrong? $ven_name = trim(ucwords(mysql_prep($_POST['ven_name']))); Quote Link to comment https://forums.phpfreaks.com/topic/246300-ucwords-to-format-text-going-into-mysql-table/ Share on other sites More sharing options...
Pikachu2000 Posted September 2, 2011 Share Posted September 2, 2011 What was the $_POST['ven_name'] string's value before and after that processing is done? Quote Link to comment https://forums.phpfreaks.com/topic/246300-ucwords-to-format-text-going-into-mysql-table/#findComment-1264879 Share on other sites More sharing options...
barniegilly Posted September 2, 2011 Author Share Posted September 2, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/246300-ucwords-to-format-text-going-into-mysql-table/#findComment-1264883 Share on other sites More sharing options...
WebStyles Posted September 2, 2011 Share Posted September 2, 2011 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'])))); Quote Link to comment https://forums.phpfreaks.com/topic/246300-ucwords-to-format-text-going-into-mysql-table/#findComment-1264889 Share on other sites More sharing options...
barniegilly Posted September 2, 2011 Author Share Posted September 2, 2011 Hi thank you for that, it now works Quote Link to comment https://forums.phpfreaks.com/topic/246300-ucwords-to-format-text-going-into-mysql-table/#findComment-1264890 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.