mydownfall00 Posted August 31, 2013 Share Posted August 31, 2013 Hello, the problem I am having is on my register.php file. I have a file included that holds three files for me which is connect.php, users.php and general.php. If anyone is familiar with phpacademy i am following alex on video 20. In users.php is where I am having my trouble. The users.php contains a function that will INSERT INTO my database table. I have the connection included at the top of the page in init.php. The code was working 100% fine until I entered in this line of code : mysql_query("INSERT INTO `users` ($fields) VALUES ($data)"); When I attempt to echo out the data : echo "INSERT INTO `users` ($fields) VALUES ($data)"; die(); mysql_query("INSERT INTO `users` ($fields) VALUES ($data)"); It cuts out the bottom half of my webpage which is my footer. This is the full function that I am using in users.php function register_user($register_data) { array_walk($register_data, 'array_sanitize'); $register_data['pword'] = md5($register_data['pword']); $fields = '`' . implode('`, `', array_keys($register_data)) . '`'; $data = '\'' . implode('\', \'', $register_data) . '\''; mysql_query("INSERT INTO `users` ($fields) VALUES ($data)"); } I placed the echo in above mysql_query and thats when it cut my webpage out. But I dont need the echo and with this as my present code nothing is inserted into my database table. I tried `users` users and 'users' which is my table name. If there is maybe a different INSERT INTO command that I could attempt? It was working prior to me using mysql_query. As in if i echoed $fields below fields it would give me my field names and $data will show the data in the fields in the array. Array sanitize is another function from my general.php file which looks like this function array_sanitize(&$item) { $item = mysql_real_escape_string($item); } register code is on the register page. here is my php on register.php <?php if (empty($_POST) == false && empty($errors) == true) { $register_data = array( 'username' => $_POST['username'], 'pword' => $_POST['pword'], 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'email' => $_POST['email'], 'phone' => $_POST['phone'] ); register_user($register_data); // redirect // exit } else if (empty($errors) == false) { echo output_errors($errors); } ?> If you could help me try and figure this out that would be excellent. I have spent a lot of time on this so far and have learned a lot but I am stuck at the moment. Quote Link to comment https://forums.phpfreaks.com/topic/281734-insert-into-wont-insert-data/ 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.