djlfreak Posted May 26, 2010 Share Posted May 26, 2010 Hi all, Sorry I'm asking so many questions, but I'm under REAL pressure, this one will be the last and I'd say it's something simple. I just can't see it. You know when your stressed and tired, you miss the obvious. It's a registration form. It's logging me in but not taking the info into the database. Files- cms transact user: 76-109 cms user account : has the registration form Thanks again. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/202940-sign-up-form-not-sending-info-to-db/ Share on other sites More sharing options...
Adam Posted May 26, 2010 Share Posted May 26, 2010 Could you not provide (within code tags) the related code? Also what do you mean by: It's logging me in but not taking the info into the database. ...As that doesn't make any sense. Quote Link to comment https://forums.phpfreaks.com/topic/202940-sign-up-form-not-sending-info-to-db/#findComment-1063477 Share on other sites More sharing options...
djlfreak Posted May 26, 2010 Author Share Posted May 26, 2010 The registration form is set up so once you sign up your automatically logged in. I attached the two related files. But I'll give you the code anyway. These are just excerpts. You can see all the code in attachments. CMS TRANSACT USER.PHP case 'Create Account': $name = (isset($_POST['name'])) ? $_POST['name'] : ''; $email = (isset($_POST['email'])) ? $_POST['email'] : ''; $username = (isset($_POST['username'])) ? $_POST['username'] : ''; $age = (isset($_POST['age'])) ? $_POST['age'] : ''; $phone = (isset($_POST['phone'])) ? $_POST['phone'] : ''; $address = (isset($_POST['address'])) ? $_POST['address'] : ''; $county = (isset($_POST['county'])) ? $_POST['county'] : ''; $password_1 = (isset($_POST['password_1'])) ? $_POST['password_1'] : ''; $password_2 = (isset($_POST['password_2'])) ? $_POST['password_2'] : ''; $password = ($password_1 == $password_2) ? $password_1 : ''; if (!empty($name) && !empty($email) && !empty($username) && !empty($password) && !empty($age) && !empty($phone)&& !empty($address) && !empty($county)) { $sql = 'INSERT INTO site_users (name, email, username, password, age, phone, address, county) VALUES ("' . mysql_real_escape_string($email, $db) . '", PASSWORD("' . mysql_real_escape_string($password, $db) . '"), "' . mysql_real_escape_string($name, $db) . '", "' . mysql_real_escape_string($username, $db) . '", "' . mysql_real_escape_string($age, $db) . '", "' . mysql_real_escape_string($phone, $db) . '", "' . mysql_real_escape_string($county, $db) . '", "' . mysql_real_escape_string($address, $db) . '")'; mysql_query($sql, $db) or die(mysql_error($db)); session_start(); $_SESSION['user_id'] = mysql_insert_id($db); $_SESSION['access_level'] = 1; $_SESSION['name'] = $name; $_SESSION['username'] = $username; } redirect('cms_index.php'); break; CMS USER ACCOUNT.PHP <?php $db = mysql_connect('localhost', 'root', '') or die ('Unable to connect. Check your connection parameters.'); mysql_select_db('dvdff2', $db) or die(mysql_error($db)); $user_id = (isset($_GET['user_id']) && ctype_digit($_GET['user_id'])) ? $_GET['user_id'] : ''; if (empty($user_id)) { $name = ''; $email = ''; $username = ''; $access_level = ''; } else { $sql = 'SELECT name, email, access_level, username FROM site_users WHERE user_id =' . $user_id; $result = mysql_query($sql, $db) or die(mysql_error($db)); $row = mysql_fetch_array($result); extract($row); mysql_free_result($result); } include 'cms_header.inc.php'; if (empty($user_id)) { echo '<h2 class="blue">Create Account</h2>'; } else { echo '<h2 class="blue">Modify Account</h2>'; } ?> <table width="400" style="border:1px #0094ff dashed; align="center" cellpadding="30" cellspacing="1" bgcolor="#ffffff"> <tr> <form method="post" action="cms_transact_user.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"><strong></strong></td> </tr> <tr> <td> </td> </tr> <tr> <td><label for="name">Full Name: </label></td> <td><input type="text" id="name" name="name" maxlength="100" style="width: 200px;" value="<?php echo htmlspecialchars($name); ?>"/></td> </tr> <tr> <td><label for="name">User Name: </label></td> <td><input type="text" id="username" name="username" maxlength="100" style="width: 200px;" value="<?php echo htmlspecialchars($username); ?>"/></td> </tr><tr> <td><label for="email">Email Address:</label></td> <td><input type="text" id="email" name="email" maxlength="100" style="width: 200px;" value="<?php echo htmlspecialchars($email); ?>"/></td> </tr> <?php if (isset($_SESSION['access_level']) && $_SESSION['access_level'] == 3) { echo '<tr><td>Access Level</td><td>'; $sql = 'SELECT access_level, access_name FROM site_access_levels ORDER BY access_level DESC'; $result = mysql_query($sql, $db) or die(mysql_error($db)); while ($row = mysql_fetch_array($result)) { echo '<input type="radio" id="acl_' . $row['access_level'] . '" name="access_level" value="' . $row['access_level'] . '"'; if ($row['access_level'] == $access_level) { echo ' checked="checked"'; } echo '/> <label for="acl_' . $row['access_level'] . '">' . $row['access_name'] . '</label><br/>'; } mysql_free_result($result); echo '</td></tr>'; } if (empty($user_id)) { ?> <tr> <td><label for="password_1">Password:</label></td> <td><input type="password" id="password_1" name="password_1" maxlength="50" style="width: 200px;"/> </td> </tr><tr> <td><label for="password_2">Password (again):</label></td> <td><input type="password" id="password_2" name="password_2" maxlength="50" style="width: 200px;"/> </td> </tr> <tr> <td><label for="age">Age:</label></td> <td><input type="text" id="age" name="age" maxlength="10" style="width: 200px;"/> </td> </tr> <tr> <td><label for="phone">Phone:</label></td> <td><input type="text" id="phone" name="phone" maxlength="20" style="width: 200px;"/> </td> </tr> <tr> <td><label for="address">Address:</label></td> <td><input type="text" id="address" name="address" maxlength="50" style="width: 200px;"/> </td> </tr> <tr> <td><label for="county">County:</label></td> <td><input type="text" id="county" name="county" maxlength="50" style="width: 200px;"/> </td> </tr> <tr> <td> </td> <td> </td> <td> <input type="submit" name="action" value="Create Account"/> </td> </tr> <?php } else { ?> <tr> <td> </td> <td> </td> <td> <input type="hidden" name="user_id" value="<?php echo $user_id; ?>"/> <input type="submit" name="action" value="Modify Account"/> </td> </tr> <?php } ?> </table> </td> </form> Quote Link to comment https://forums.phpfreaks.com/topic/202940-sign-up-form-not-sending-info-to-db/#findComment-1063482 Share on other sites More sharing options...
Adam Posted May 26, 2010 Share Posted May 26, 2010 You need to be way more specific with your problem. What errors are you getting, or what are you seeing? Quote Link to comment https://forums.phpfreaks.com/topic/202940-sign-up-form-not-sending-info-to-db/#findComment-1063491 Share on other sites More sharing options...
djlfreak Posted May 26, 2010 Author Share Posted May 26, 2010 Ok this is weird. It's uploading the formdata into the database but its putting the data in all the wrong fields. I thought you didn't have to match form field names with database column names. I looked through the files and there is no pattern that I can see it's weird. Have you come across this before. What causes this to happen. Quote Link to comment https://forums.phpfreaks.com/topic/202940-sign-up-form-not-sending-info-to-db/#findComment-1063587 Share on other sites More sharing options...
djlfreak Posted May 26, 2010 Author Share Posted May 26, 2010 The table in the database looks like this. site_users user_id (fine) email (taking in the password) password (taking in the username) name (taking in email) username (username is taking in name) age (fine) phone (fine) address (county) county (address) access_level (fine) Quote Link to comment https://forums.phpfreaks.com/topic/202940-sign-up-form-not-sending-info-to-db/#findComment-1063591 Share on other sites More sharing options...
Adam Posted May 26, 2010 Share Posted May 26, 2010 Look at the order in which you have the field names in your insert statement: $sql = 'INSERT INTO site_users (name, email, username, password, age, phone, address, county) And then the order in which you have the values: VALUES ("' . mysql_real_escape_string($email, $db) . '", PASSWORD("' . mysql_real_escape_string($password, $db) . '"), "' . mysql_real_escape_string($name, $db) . '", //etc Quote Link to comment https://forums.phpfreaks.com/topic/202940-sign-up-form-not-sending-info-to-db/#findComment-1063592 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.