herghost Posted September 22, 2009 Share Posted September 22, 2009 Hi All, First, apologies if this should be in the ajax section. below is my registration form, everything works fine: <?php session_start(); include ('include/dbconnect.php'); $member_list = array('I Have a Problem', 'I Solve Problems'); // filter incoming values $username = (isset($_POST['username'])) ? trim($_POST['username']) : ''; $password = (isset($_POST['password'])) ? $_POST['password'] : ''; $first_name = (isset($_POST['first_name'])) ? trim($_POST['first_name']) : ''; $last_name = (isset($_POST['last_name'])) ? trim($_POST['last_name']) : ''; $email = (isset($_POST['email'])) ? trim($_POST['email']) : ''; $city = (isset($_POST['city'])) ? trim($_POST['city']) : ''; $state = (isset($_POST['state'])) ? trim($_POST['state']) : ''; $member = (isset($_POST['member']) && is_array($_POST['member'])) ? $_POST['member'] : array(); if (isset($_POST['submit']) && $_POST['submit'] == 'Register') { $errors = array(); // make sure manditory fields have been entered if (empty($username)) { $errors[] = 'Username cannot be blank.'; } // check if username already is registered $query = 'SELECT username FROM users WHERE username = "' . $username . '"'; $result = mysql_query($query, $conn) or die(mysql_error()); if (mysql_num_rows($result) > 0) { $errors[] = 'Username ' . $username . ' is already registered.'; $username = ''; } mysql_free_result($result); if (empty($password)) { $errors[] = 'Password cannot be blank.'; } if (empty($first_name)) { $errors[] = 'First name cannot be blank.'; } if (empty($last_name)) { $errors[] = 'Last name cannot be blank.'; } if (empty($email)) { $errors[] = 'Email address cannot be blank.'; } if (count($errors) > 0) { echo '<p><strong style="color:#FF000;">Unable to process your ' . 'registration.</strong></p>'; echo '<p>Please fix the following:</p>'; echo '<ul>'; foreach ($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } else { // No errors so enter the information into the database. $query = 'INSERT INTO users (user_id, username, password) VALUES (NULL, "' . mysql_real_escape_string($username, $conn) . '", ' . 'PASSWORD("' . mysql_real_escape_string($password, $conn) . '"))'; $result = mysql_query($query, $conn) or die(mysql_error()); $user_id = mysql_insert_id($conn); $query = 'INSERT INTO users_info (user_id, first_name, last_name, email, city, state, member) VALUES (' . $user_id . ', ' . '"' . mysql_real_escape_string($first_name, $conn) . '", ' . '"' . mysql_real_escape_string($last_name, $conn) . '", ' . '"' . mysql_real_escape_string($email, $conn) . '", ' . '"' . mysql_real_escape_string($city, $conn) . '", ' . '"' . mysql_real_escape_string($state, $conn) . '", ' . '"' . mysql_real_escape_string(join(', ', $member), $conn) . '")'; $result = mysql_query($query, $conn) or die(mysql_error()); $_SESSION['logged'] = 1; $_SESSION['username'] = $username; header('Refresh: 2; URL=index.php'); ?> <html> <head> <title>Register</title> </head> <body> <p><strong>Thank you <?php echo $username; ?> for registering!</strong></p> <p>Your registration is complete! You will be redirected shortly, <a href="index.php">click here</a>.</p> </body> </html> <?php die(); } } ?> <html> <head> <title>Register</title> <style type="text/css"> td { vertical-align: top; } </style> </head> <body> <form action="register.php" method="post"> <table> <tr> <td><label for="username">Username:</label></td> <td><input type="text" name="username" id="username" size="20" maxlength="20" value="<?php echo $username; ?>"/></td> </tr><tr> <td><label for="password">Password:</label></td> <td><input type="password" name="password" id="password" size="20" maxlength="20" value="<?php echo $password; ?>"/></td> </tr><tr> <td><label for="email">Email:</label></td> <td><input type="text" name="email" id="email" size="20" maxlength="50" value="<?php echo $email; ?>"/></td> </tr><tr> <td><label for="first_name">First name:</label></td> <td><input type="text" name="first_name" id="first_name" size="20" maxlength="20" value="<?php echo $first_name; ?>"/></td> </tr><tr> <td><label for="last_name">Last name:</label></td> <td><input type="text" name="last_name" id="last_name" size="20" maxlength="20" value="<?php echo $last_name; ?>"/></td> </tr><tr> <td><label for="city">City:</label></td> <td><input type="text" name="city" id="city" size="20" maxlength="20" value="<?php echo $city; ?>"/></td> </tr><tr> <td><label for="state">State:</label></td> <td><input type="text" name="state" id="state" size="4" maxlength="2" value="<?php echo $state; ?>"/></td> </tr><tr> <td><label for="member">Membership Type:</label></td> <td><select name="member[]" id="member" multiple="multiple"> <?php foreach ($member_list as $members) { if (in_array($members, $member)) { echo '<option value="' . $members . '" selected="selected">' . $members . '</option>'; } else { echo '<option value="' . $members . '">' . $members . '</option>'; } } ?> </select></td> </tr><tr> <td> </td> <td><input type="submit" name="submit" value="Register" class="button"/></td> </tr> </table> </form> </body> </html> The bit I am interested in is this: <html> <head> <title>Register</title> </head> <body> <p><strong>Thank you <?php echo $username; ?> for registering!</strong></p> <p>Your registration is complete! You will be redirected shortly, <a href="index.php">click here</a>.</p> </body> </html> basically I use ajax to open a external page in a <div> so when this piece of code is displayed it displays on a new page and not in my nice css's template in the main div. How would I: a, change this to appear in my div on my main page? or b, have this appear in a popup box, which autocloses after 2 seconds and takes me back to index.php? or c, redirect straight to to index.php and show a message that registration is complete? What do you think would be the easiest solution? I am guessing c, but dont know how to go about it! many thanks Quote Link to comment https://forums.phpfreaks.com/topic/175084-solved-form-help/ Share on other sites More sharing options...
ozestretch Posted September 22, 2009 Share Posted September 22, 2009 I would opt for this: css - Add to the header of your output to include the .css so your nice css site is represented throughout refresh - add meta refresh to redirect after 2 seconds to the index page (or where ever) <head> <title>Register</title> <link rel="stylesheet" type="text/css" href="pretty_me_up.css" /> <meta http-equiv="refresh" content="2;url=http://www.me.com/index.php"> </head> Quote Link to comment https://forums.phpfreaks.com/topic/175084-solved-form-help/#findComment-922780 Share on other sites More sharing options...
herghost Posted September 22, 2009 Author Share Posted September 22, 2009 Spot on mate, thanks Quote Link to comment https://forums.phpfreaks.com/topic/175084-solved-form-help/#findComment-922784 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.