Ken2k7
Members-
Posts
5,196 -
Joined
-
Last visited
Never
Everything posted by Ken2k7
-
My form validation is giving errors lots of them
Ken2k7 replied to redrabbit's topic in PHP Coding Help
Nah, I'm fine. Replace your function with this one. It was posted by mjdamato and it's one of the best for validating an e-mail address. function validate_email($email) { $formatTest = '/^[\w!#$%&\'*+\-\/=?^`{|}~]+(\.[\w!#$%&\'*+\-\/=?^`{|}~]+)*@[a-z\d]([a-z\d-]{0,62}[a-z\d])?(\.[a-z\d]([a-z\d-]{0,62}[a-z\d])?)*\.[a-z]{2,6}$/i'; $lengthTest = '/^(.{1,64})@(.{4,255})$/'; return (preg_match($formatTest, $email) && preg_match($lengthTest, $email)); } -
We have a CSS forum. This forum is for PHP coding help.
-
<div> <?php if(get_post_meta($post->ID, "image8_value", "image8alt_value", $single = true) !="") { ?> <a href="<?php the_permalink(); ?>"><img class="right" src="<?php bloginfo('url'); ?>/wp-content/themes/realestate/img_resize/timthumb.php?src=<?php echo get_post_meta($post->ID, "image8_value", $single = true); ?>&h=438&w=630&zc=1" alt="<?php echo get_post_meta($post->ID, "image8alt_value", $single = true); ?>" /></a> <?php } else { ?> <img class="right" src="<?php bloginfo('url'); ?>/wp-content/themes/realestate/images/image_placeholder.jpg" height="438" width="630" alt="Image Coming Soon" /> </div> You didn't close the else. What do you mean where? It was the first reply in this topic.
-
My form validation is giving errors lots of them
Ken2k7 replied to redrabbit's topic in PHP Coding Help
You forgot the if in front? That's also not a good regexp for an email address. Just saying. -
The better way would be to store the array values in a database table instead of an array.
-
Not every line is a select.
-
As you're new, read the rules, especially #4 of Forum DOs. Also, please do not post up entire code unless someone asks for it. Not many are willing to read through your mess. It helps to just post up the relevant parts. As for the issue, does it tell you what line the error is on?
-
Question, what does WHERE f.user_id IN = '$user->id' mean? Never seen that before. TeddyKiller, the f, us and u are aliases.
-
Matching multiple row data from one table with a single row of another table
Ken2k7 replied to KitCarl's topic in MySQL Help
I think you want GROUP_CONCAT. http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat -
My form validation is giving errors lots of them
Ken2k7 replied to redrabbit's topic in PHP Coding Help
sprintf. It's used to format a string. I personally like to keep variables separate from strings. I know people do this: $str = "here's some static text and here's a $variable"; I know of no other programming language that allows that other than PHP. And I can see why. I just don't like it. It looks tacky and you run into all sorts of variable interpolation issues, especially with SQL queries. Keeping them separate and clean looking allows you to look at the code easier. -
Give the form a name attribute and use: document.forms.<form_name>.submit(); So if your form name is "tracks", it would be: document.forms.tracks.submit();
-
My form validation is giving errors lots of them
Ken2k7 replied to redrabbit's topic in PHP Coding Help
Oh there is a comma at the last mysqli_real_escape_string. Just remove it. Here: <?php require_once('connectvars.php'); require_once('validate_email.php'); $msg_error = array(); $error = false; $output_form = true; /**Checks if the form is submitted and processes only when submit = true**/ if (isset($_POST['submit'])) { // Connects to the database $dbc = mysqli_connect('DB_HOST', 'DB_USER', 'DB_PASSWORD', 'DB_NAME') or die ('Error connecting to MYQSQL server.'); /**Retrieves the data entered into the registration form and stores them in variables**/ $title = $_POST['title']; $fname = trim($_POST['firstname']); $lname = trim($_POST['surname']); $country = $_POST['country']; $email1 = trim($_POST['email1']); $email2 = $dbc, trim($_POST['email2']); $address = trim($_POST['address']) ; $postcode = trim($_POST['postcode']); $phone = trim($_POST['phone']); $cellphone = trim($_POST['cellphone']); $pswd1 = $_POST['password1']; $pswd2 = $_POST['password2']; $output_form = false; /**Validates the form to determine for any errors b4 storing to the db**/ if (empty($title)) { $msg_error['title'] = "Please select your title"; } if (empty($fname)) { $msg_error['fname'] = "Please enter your firstname"; } if (empty($lname)) { $msg_error['lname'] = "Please enter your surname"; } if (empty($email1)) { $msg_error['email1'] = "Please enter your email"; } if (empty($email2)) { $msg_error['email2'] = "Please re-enter the same email"; } if (empty($address1)) { $msg_error['address'] = "Please enter your postal address"; } if (empty($postcode) || !is_numeric($postcode)) { $msg_error['postcode'] = "Post code cannot be empty and it must be numbers only."; } if (empty($phone) || !is_numeric($phone)) { $msg_error['phone'] = "Phone number cannot be empty and it must be numbers only."; } if (!empty($cellphone)) { if (!is_numeric($cellphone)) { $msg_error ['intcellphone'] = "Cell phone can only be numbers"; } } if (!empty($email1) && !empty($email2)) { if ($email1 == $email2) { if ($result = validate_email($email1)) { $msg_error['invalidemail'] = "You have entered an invalid email"; } else { $msg_error['mismatchemail'] = "Your emails do not match"; } } } if (empty($pswd1) || empty($pswd2)) { $msg_error['pswd'] = "Please enter a value for a password"; } else { if ($pswd1 == $pswd2) { $pswd = $pswd1; } else { $msg_error['mismatchpswd'] = "Your passwords do not match"; } } if (!empty($msg_error)) { $error = true; $output_form = true; } /** if there are no errors then it creates a new user in the database using the submitted details**/ if (empty($msg_error)) { $create_user = sprintf("INSERT INTO user (UserNr, Title, FirstName, LastName, Country, Email, PostalAddress, PostalCode, Phone, Cellphone) VALUES (0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');", mysqli_real_escape_string($dbc, $title), mysqli_real_escape_string($dbc, $fname), mysqli_real_escape_string($dbc, $lname), mysqli_real_escape_string($dbc, $country), mysqli_real_escape_string($dbc, $email1), mysqli_real_escape_string($dbc, $address), mysqli_real_escape_string($dbc, $postcode, mysqli_real_escape_string($dbc, $phone), mysqli_real_escape_string($dbc, $cellphone) ); $cu_result = mysqli_query($dbc, $create_user) or trigger_error('Error saving user profile'); $create_acct = sprintf("INSERT INTO account (AcctNr, AcctTypeID, Username, Password, UserNr, DateCreated) VALUES (0, 1, '%s', SHA1('%s'), 0, CURRENT_TIMESTAMP());", mysqli_real_escape_string($dbc, $email1), mysqli_real_escape_string($dbc, $pswd) ); $ca_result = mysqli_query($dbc, $create_user) or trigger_error('Error saving account profile'); if ($cu_result && $ca_result) echo 'You account has been created please check your email'; else echo 'An error occured and your information cannot be saved. Please try again later.'; $output_form = false; } } if($output_form) { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div id="form"> <table> <tr> <th>Title:</th> <td> <select name="title" value="<?php if (!empty($title)) echo $title; ?>" > <option value="null"></option> <option value="Mr.">Mr.</option> <option value="Mrs.">Mrs.</option> <option value="Miss">Miss</option> <option value="Ms.">Ms.</option> <option value="Dr.">Dr.</option> <option value="Prof.">Prof.</option> <option value="Rev.">Rev.</option> <option value="Other">Other</option> </select> </td> <td class="error">Required: <?php if (isset($msg_error['title'])) echo $msg_error['title']; ?></td> </tr> <tr> <th>First Name:</th> <td> <input type="text" name="firstname" class="medium" value= "<?php if (!empty($fname)) echo $fname; ?>" /> </td> <td class="error">Required: <?php if (isset($msg_error['fname'])) echo $msg_error['fname']; ?> </td> </tr> <tr> <th>Surname:</th> <td> <input type="text" name="surname" class="large" value="<?php if (!empty($lname)) echo $lname; ?>" /> </td> <td class="error"> Required: <?php if (isset($msg_error['lname'])) echo $msg_error['lname']; ?> </td> </tr> <tr> <th> Country:</th> <td> <select name="country" selected="South Africa"> <option value="Afghanistan" >Afghanistan</option> <option value="Albania" >Albania</option> <option value="Algeria" >Algeria</option> <option value="Andorra" >Andorra</option> <option value="Antigua and Barbuda" >Antigua and Barbuda</option> <option value="Argentina" >Argentina</option> <option value="Iraq" >Iraq</option> <option value="Japan" >Japan</option> <option value="Jordan" >Jordan</option> <option value="Lebanon" >Lebanon</option> <option value="Somalia" >Somalia</option> <option value="South Africa" selected="select" >South Africa</option> <option value="Spain" >Spain</option> <option value="Syria" >Syria</option> <option value="Taiwan" >Taiwan</option> </select> </td> </tr> <tr> <th>Postal Address:</th> <td> <input type="text" name="address" class="large" value="<?php if (!empty($address)) echo $address; ?>"/> </td> <td class="error">Required: <?php if (isset($msg_error['address'])) echo $msg_error['address']; ?> </td> </tr> <tr> <th> Postal Code: </th> <td> <input type="text" name="postcode" value="<?php if (!empty($postcode)) echo $postcode; ?>" /> </td> <td class="error">Required: <?php if (isset($msg_error['postcode'])) echo $msg_error['postcode']; ?> </td> </tr> <tr> <th> Phone Number: </th> <td> <input type="text" name="phone" value="<?php if (!empty($phone)) echo $phone; ?>"/> </td> <td class="error">Required: <?php if (isset($msg_error['phone'])) echo $msg_error['phone']; ?> </td> <th> Cellphone:</th> <td> <input type="text" name="cellphone" /> </td> <td class="error"> <?php if (isset($msg_error['cellphone'])) echo $msg_error['cellphone']; ?> </td> </tr> <tr> <th> Email: </th> <td> <input type="text" name="email1" class="medium" value="<?php if (!empty($email1)) echo $email1; ?>" /> </td> <td class="error">Required: <?php if (isset($msg_error['email1'])) echo $msg_error['email1']; ?> </td> </tr> <tr> <th> Re-Enter Email:</th> <td> <input type="text" name="email2" class="medium" value="<?php if (!empty($email2)) echo $email2; ?>" /> </td> <td class="error">Required: <?php if (isset($msg_error['email2'])) echo $msg_error['email2']; ?> </td> </tr> <tr> <th> Password:</th> <td> <input type="password" name="password1" class="medium" /> </td> <td class="error">Required: <?php if (isset($msg_error['pswd'])) echo $msg_error['pswd']; ?> </td> </tr> <tr> <th> Re-Enter Password:</th> <td> <input type="password" name="password2" class="medium" /> </td> <td class="error">Required: <?php if (isset($msg_error['pswd'])) echo $msg_error['pswd']; ?> <?php if (isset($msg_error['mismatchpswd'])) echo $msg_error['mismatchpswd']; ?> </td> </tr> <tr> <th> </th> <td> <input type="submit" value="submit"/> </td> </tr> </table> </form> </div> <?php } ?> <div class="boxed" id="footer"> <p> This is the footer area </p> </div> </div> </body> </html> As for the generous money, please send it as a donation phpfreaks to keep this site running. Go here: http://www.phpfreaks.com/page/donations -
Not that anyone care. If you're a staff member, you would still be in the group, not that people are allowed to PM any one specific member regarding help as said in the rules so it really doesn't matter much at all. Well yeah lol. I would personally like a change in my username. I don't see why I can modify my profile, signature, avatar to my liking but not my username. Nothing. I have no issues with someone calling themselves Ken2k7 after I change my username. How about this: you ban Ken2k7 (the username) and I create a new account?
-
It strips out all non-digit characters and return a string of the first 6 numbers. /[^0-9]/ is a regular expression. It matches all non-digit characters. The 0-9 just means numbers 0 to 9. The ^ is not.
-
Should be WHERE user_id IN ..., not WHERE user_id = ...
-
My form validation is giving errors lots of them
Ken2k7 replied to redrabbit's topic in PHP Coding Help
This should hopefully work: <?php require_once('connectvars.php'); require_once('validate_email.php'); $msg_error = array(); $error = false; $output_form = true; /**Checks if the form is submitted and processes only when submit = true**/ if (isset($_POST['submit'])) { // Connects to the database $dbc = mysqli_connect('DB_HOST', 'DB_USER', 'DB_PASSWORD', 'DB_NAME') or die ('Error connecting to MYQSQL server.'); /**Retrieves the data entered into the registration form and stores them in variables**/ $title = $_POST['title']; $fname = trim($_POST['firstname']); $lname = trim($_POST['surname']); $country = $_POST['country']; $email1 = trim($_POST['email1']); $email2 = trim($_POST['email2']); $address = trim($_POST['address']) ; $postcode = trim($_POST['postcode']); $phone = trim($_POST['phone']); $cellphone = trim($_POST['cellphone']); $pswd1 = $_POST['password1']; $pswd2 = $_POST['password2']; $output_form = false; /**Validates the form to determine for any errors b4 storing to the db**/ if (empty($title)) { $msg_error['title'] = "Please select your title"; } if (empty($fname)) { $msg_error['fname'] = "Please enter your firstname"; } if (empty($lname)) { $msg_error['lname'] = "Please enter your surname"; } if (empty($email1)) { $msg_error['email1'] = "Please enter your email"; } if (empty($email2)) { $msg_error['email2'] = "Please re-enter the same email"; } if (empty($address1)) { $msg_error['address'] = "Please enter your postal address"; } if (empty($postcode) || !is_numeric($postcode)) { $msg_error['postcode'] = "Post code cannot be empty and it must be numbers only."; } if (empty($phone) || !is_numeric($phone)) { $msg_error['phone'] = "Phone number cannot be empty and it must be numbers only."; } if (!empty($cellphone)) { if (!is_numeric($cellphone)) { $msg_error ['intcellphone'] = "Cell phone can only be numbers"; } } if (!empty($email1) && !empty($email2)) { if ($email1 == $email2) { if ($result = validate_email($email1)) { $msg_error['invalidemail'] = "You have entered an invalid email"; } else { $msg_error['mismatchemail'] = "Your emails do not match"; } } } if (empty($pswd1) || empty($pswd2)) { $msg_error['pswd'] = "Please enter a value for a password"; } else { if ($pswd1 == $pswd2) { $pswd = $pswd1; } else { $msg_error['mismatchpswd'] = "Your passwords do not match"; } } if (!empty($msg_error)) { $error = true; $output_form = true; } /** if there are no errors then it creates a new user in the database using the submitted details**/ if (empty($msg_error)) { $create_user = sprintf("INSERT INTO user (UserNr, Title, FirstName, LastName, Country, Email, PostalAddress, PostalCode, Phone, Cellphone) VALUES (0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');", mysqli_real_escape_string($dbc, $title), mysqli_real_escape_string($dbc, $fname), mysqli_real_escape_string($dbc, $lname), mysqli_real_escape_string($dbc, $country), mysqli_real_escape_string($dbc, $email1), mysqli_real_escape_string($dbc, $address), mysqli_real_escape_string($dbc, $postcode, mysqli_real_escape_string($dbc, $phone), mysqli_real_escape_string($dbc, $cellphone), ); $query_result = mysqli_query($dbc, $create_user) or trigger_error('Error querying database'); if ($query_result) echo 'You account has been created please check your email'; else echo 'Your information cannot be saved. Please try again later.'; $output_form = false; } } if($output_form) { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div id="form"> <table> <tr> <th>Title:</th> <td> <select name="title" value="<?php if (!empty($title)) echo $title; ?>" > <option value="null"></option> <option value="Mr.">Mr.</option> <option value="Mrs.">Mrs.</option> <option value="Miss">Miss</option> <option value="Ms.">Ms.</option> <option value="Dr.">Dr.</option> <option value="Prof.">Prof.</option> <option value="Rev.">Rev.</option> <option value="Other">Other</option> </select> </td> <td class="error">Required: <?php if (isset($msg_error['title'])) echo $msg_error['title']; ?></td> </tr> <tr> <th>First Name:</th> <td> <input type="text" name="firstname" class="medium" value= "<?php if (!empty($fname)) echo $fname; ?>" /> </td> <td class="error">Required: <?php if (isset($msg_error['fname'])) echo $msg_error['fname']; ?> </td> </tr> <tr> <th>Surname:</th> <td> <input type="text" name="surname" class="large" value="<?php if (!empty($lname)) echo $lname; ?>" /> </td> <td class="error"> Required: <?php if (isset($msg_error['lname'])) echo $msg_error['lname']; ?> </td> </tr> <tr> <th> Country:</th> <td> <select name="country" selected="South Africa"> <option value="Afghanistan" >Afghanistan</option> <option value="Albania" >Albania</option> <option value="Algeria" >Algeria</option> <option value="Andorra" >Andorra</option> <option value="Antigua and Barbuda" >Antigua and Barbuda</option> <option value="Argentina" >Argentina</option> <option value="Iraq" >Iraq</option> <option value="Japan" >Japan</option> <option value="Jordan" >Jordan</option> <option value="Lebanon" >Lebanon</option> <option value="Somalia" >Somalia</option> <option value="South Africa" selected="select" >South Africa</option> <option value="Spain" >Spain</option> <option value="Syria" >Syria</option> <option value="Taiwan" >Taiwan</option> </select> </td> </tr> <tr> <th>Postal Address:</th> <td> <input type="text" name="address" class="large" value="<?php if (!empty($address)) echo $address; ?>"/> </td> <td class="error">Required: <?php if (isset($msg_error['address'])) echo $msg_error['address']; ?> </td> </tr> <tr> <th> Postal Code: </th> <td> <input type="text" name="postcode" value="<?php if (!empty($postcode)) echo $postcode; ?>" /> </td> <td class="error">Required: <?php if (isset($msg_error['postcode'])) echo $msg_error['postcode']; ?> </td> </tr> <tr> <th> Phone Number: </th> <td> <input type="text" name="phone" value="<?php if (!empty($phone)) echo $phone; ?>"/> </td> <td class="error">Required: <?php if (isset($msg_error['phone'])) echo $msg_error['phone']; ?> </td> <th> Cellphone:</th> <td> <input type="text" name="cellphone" /> </td> <td class="error"> <?php if (isset($msg_error['cellphone'])) echo $msg_error['cellphone']; ?> </td> </tr> <tr> <th> Email: </th> <td> <input type="text" name="email1" class="medium" value="<?php if (!empty($email1)) echo $email1; ?>" /> </td> <td class="error">Required: <?php if (isset($msg_error['email1'])) echo $msg_error['email1']; ?> </td> </tr> <tr> <th> Re-Enter Email:</th> <td> <input type="text" name="email2" class="medium" value="<?php if (!empty($email2)) echo $email2; ?>" /> </td> <td class="error">Required: <?php if (isset($msg_error['email2'])) echo $msg_error['email2']; ?> </td> </tr> <tr> <th> Password:</th> <td> <input type="password" name="password1" class="medium" /> </td> <td class="error">Required: <?php if (isset($msg_error['pswd'])) echo $msg_error['pswd']; ?> </td> </tr> <tr> <th> Re-Enter Password:</th> <td> <input type="password" name="password2" class="medium" /> </td> <td class="error">Required: <?php if (isset($msg_error['pswd'])) echo $msg_error['pswd']; ?> <?php if (isset($msg_error['mismatchpswd'])) echo $msg_error['mismatchpswd']; ?> </td> </tr> <tr> <th> </th> <td> <input type="submit" value="submit"/> </td> </tr> </table> </form> </div> <?php } ?> <div class="boxed" id="footer"> <p> This is the footer area </p> </div> </div> </body> </html> -
In the Rules & TOS, it clearly states that I cannot request a name change or register more than 1 account. So is there a way to deactivate one account? I'm not liking my "Ken2k7" username. Surely I didn't think much of the name when I first registered. I didn't know if I would stick around or not so I just picked the first thing that came up. So what's so bad about changing a name? I highly doubt other people care unless it's an offensive name. Can't we have a rule like you have to be here for x amount of time (say 3 years minimum) and have a minimum of x posts to be allowed one name change per year or something similar? That may require a bit of maintenance so how about the option that the members in the Supporter group are allowed one name change? That can work out seeing as not many people are in that group at the moment. I only need it changed once and I've already picked out my new username. Currently, it's available.
-
Run each $_POST value through mysql_real_escape_string.
-
Huh?
-
My form validation is giving errors lots of them
Ken2k7 replied to redrabbit's topic in PHP Coding Help
$create_user = "Insert into user (UserNr, Title, FirstName, LastName, Country, Email, PostalAddress, " . "PostalCode, Phone, Cellphone)" . "Values (0, $title, $fname, $lname, $country, $email1, $address, $postcode, " . " $phone, $cellphone)"; You need to enclose each variable with single quotes. $create_user = "Insert into user (UserNr, Title, FirstName, LastName, Country, Email, PostalAddress, " . "PostalCode, Phone, Cellphone)" . "Values (0, '$title', '$fname', '$lname', '$country', '$email1', '$address', '$postcode', " . " '$phone', '$cellphone')"; You may want to escape $title and $country too. I see you did it for the others. -
How so? Just stick with preg_match and preg_replace.
-
My form validation is giving errors lots of them
Ken2k7 replied to redrabbit's topic in PHP Coding Help
You need to echo it. <?php echo $msg_error['title']; ?> -
My form validation is giving errors lots of them
Ken2k7 replied to redrabbit's topic in PHP Coding Help
I doubt it's the same error. You still have to pre-define the values like: $msg_error['title'] = ''; Or else, you get an error saying the index doesn't exist. -
Well, it sure helps to post in the correct forum, wouldn't it? This is PHP coding help, not SQL.