markosaurus Posted April 7, 2008 Share Posted April 7, 2008 Hi there folks, First of all, sorry for my ineptitude, I'm new to SQL, although I have been using PHP for a while it is also relatively new to me, apologies in advance for the nastiness of my code. I'm trying to handle form data and insert it into a table called 'users' FORM CODE; <form action="" method="POST"> <label for="name">Name</label><input name="name" type="text" /> <label for="username">Username</label><input name="username" type="text" /> <label for="password">Password</label><input name="password" type="text" /> <label for="email">Email</label><input name="email" type="text" /> <input name="submit" type="submit" value="submit" class="submit" /> </form> PHP; //make query $sqlquery="INSERT INTO users (id, username, password, role, approved, name, email, joined) VALUES (NULL , '$_POST[username]', '$_POST[password]', 'user', '0', '$name', '$_POST[email]', NOW( ));"; mysql_query($sqlquery) or die (mysql_error()); It has connected fine, my data doesn't seem to be posted for some reason as when I try to test this using; echo $_POST['name']; The code is all on one page, I'm scanning for $_POST['submit'] being set and either outputting a form or inserting data depending on whether submit is set or not. I get no response, is there something very silly I've done here? It's driving me mad. Any thanks would be appreciated muchly. Mark Link to comment https://forums.phpfreaks.com/topic/99966-solved-help-with-sql-insert-posted-data-problem/ Share on other sites More sharing options...
trq Posted April 7, 2008 Share Posted April 7, 2008 Testing using... echo $_POST['name']; does nothing because you have no form filed named name. Is your call to mysql_error() showing any errors? You have a variable ($name) in your query that appears from nowehere. You also ought really clean any user input prior to using it in any query, take a look at mysql_real_escape_string. Link to comment https://forums.phpfreaks.com/topic/99966-solved-help-with-sql-insert-posted-data-problem/#findComment-511172 Share on other sites More sharing options...
markosaurus Posted April 7, 2008 Author Share Posted April 7, 2008 <label for="name">Name</label><input name="name" type="text" /> The first form field is named 'name' ??? I'm confused now. Sorry, I see what you meant now, I have changed the query to; $sqlquery="INSERT INTO users VALUES (NULL , '$_POST[username]', '$_POST[password]', 'user', '0', '$_POST[name]', '$_POST[email]', NOW( ));"; $result=mysql_query($sqlquery) or die (mysql_error()); It still doesn't insert the value Link to comment https://forums.phpfreaks.com/topic/99966-solved-help-with-sql-insert-posted-data-problem/#findComment-511185 Share on other sites More sharing options...
markosaurus Posted April 7, 2008 Author Share Posted April 7, 2008 I've sorted it thanks, I knew it would be something stupid I was doing; I was checking the submit state and then running a loop to check values were'nt empty, except I had escaped two loops instead of one after that, so I was escaping inserting the values. Stupid boy Thanks for your help Link to comment https://forums.phpfreaks.com/topic/99966-solved-help-with-sql-insert-posted-data-problem/#findComment-511206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.