GOLDfish_74 Posted May 20, 2007 Share Posted May 20, 2007 To view the full story: Click Here. Anywho, a summary of the story goes, I am trying to run a really simple script that would place users in my database when they registered: <?php // Connects to your Database mysql_connect("localhost", "goldfish_root", "password") or die(mysql_error()); mysql_select_db("goldfish_retaildefault") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) { die('You did not complete all of the required fields'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $check = mysql_query("SELECT user_name FROM users WHERE user_name = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, '.$_POST['username'].', you are already registered.'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { die('Your passwords did not match.'); } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['username'] = addslashes($_POST['username']); } // now we insert it into the database $insert = "INSERT INTO users (user_id, user_name, user_pass, user_sec) VALUES ('".$_POST['userid']."', '".$_POST['username']."', '".$_POST['pass']."', '".$_POST['security']."')"; mysql_query($insert); ?> <h1>Registered</h1> <p>Thank you, you have registered - you may now login</a>.</p> <p><? echo ($_POST['pass']); echo ($_POST['security']); echo ($_POST['username']); echo ($_POST['userid']) ?></p> <?php } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr><td>Your User ID is:</td><td> <? $userid = rand(1000, 9999); echo($userid); ?> <input type="hidden" name="userid" value="<? echo($userid); ?>"> </td></tr> <tr><td>Full Name:</td><td> <input type="text" name="username" maxlength="60"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="10"> </td></tr> <tr><td>Confirm Password:</td><td> <input type="password" name="pass2" maxlength="10"> </td></tr> <tr><td>Security Level</td><td> <input type="radio" name="security" value="2">Supervisor<br><input type="radio" name="security" value="1">Employee</td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table> </form> <?php } ?> This did not report any errors but also failed to put any data in the database. As this failed to work I figured I'd just try a simple alternative: <? error_reporting(E_ALL); mysql_connect("localhost", "goldfish_root", "password") or die(mysql_error()); mysql_select_db("goldfish_retaildefault") or die(mysql_error()); $insert = "INSERT INTO users (user_id, user_name, user_pass, user_sec) VALUES ('1234, Josh, 3883, 1')"; $add_member = mysql_query($insert); ?> This also failed to work with no errors, and now I have no idea what is going wrong. These questions all came about when I tried to use EasyPHP to test my script while I was on public transport and away from home. When it seemed they did not like Vista, I got a free web host (qupis.com) and the problems are still the same. I am sure there is nothing wrong with my code, so what could be going wrong? Regards, THEfish. Quote Link to comment https://forums.phpfreaks.com/topic/52269-solved-cant-get-data-into-mysql-database/ Share on other sites More sharing options...
Richzilla Posted May 20, 2007 Share Posted May 20, 2007 try removing this part and see what happens - (user_id, user_name, user_pass, user_sec) Quote Link to comment https://forums.phpfreaks.com/topic/52269-solved-cant-get-data-into-mysql-database/#findComment-257894 Share on other sites More sharing options...
GOLDfish_74 Posted May 20, 2007 Author Share Posted May 20, 2007 Removing that line made absolutely no difference what so ever. It ran without reporting an error and still failed to put the data into the database. Regards, THEfish! Quote Link to comment https://forums.phpfreaks.com/topic/52269-solved-cant-get-data-into-mysql-database/#findComment-257904 Share on other sites More sharing options...
TNGuy03 Posted May 20, 2007 Share Posted May 20, 2007 If you have an 'id' field for the records in your db table which is auto incremented, be sure to pass 'NULL' for that field. Quote Link to comment https://forums.phpfreaks.com/topic/52269-solved-cant-get-data-into-mysql-database/#findComment-257915 Share on other sites More sharing options...
radar Posted May 20, 2007 Share Posted May 20, 2007 Here is how I insert things to a database... $insert = "INSERT INTO users SET user_id = '', user_name = 'Josh', user_pass = '3883', user_sec = '1'"; you can also use this to update. by changing the syntax from insert to update.. such as.. $update = "UPDATE users SET user_id = '', user_name = "Jump", user_pass = '3434324', user_sec = '2' WHERE user_id = '$user_id'"; hope it helps.. Quote Link to comment https://forums.phpfreaks.com/topic/52269-solved-cant-get-data-into-mysql-database/#findComment-257919 Share on other sites More sharing options...
penguin0 Posted May 21, 2007 Share Posted May 21, 2007 If user_id is auto incrementing, there is no reason to insert it at all. Quote Link to comment https://forums.phpfreaks.com/topic/52269-solved-cant-get-data-into-mysql-database/#findComment-257928 Share on other sites More sharing options...
GOLDfish_74 Posted May 21, 2007 Author Share Posted May 21, 2007 Just to let you know, I have done a fair bit of PHP and MySQL before. And I know what auto_increment is... AND ITS NOT SET TO THAT. If you had cared to look, the id is set by a random number generator, not by the database. If you have any more suggestions that could work, please post. Regards, THEfish! PS: I tried using SET instead of VALUES with no difference in result. Quote Link to comment https://forums.phpfreaks.com/topic/52269-solved-cant-get-data-into-mysql-database/#findComment-257994 Share on other sites More sharing options...
GOLDfish_74 Posted May 21, 2007 Author Share Posted May 21, 2007 Turns out it was the most obvious thing in the world!!! user_pass, was meant to be user_pin. and I had error display off. That and I agree EasyPHP is not what I should be using... lol, THANKS for all your patience to find such a pointless flaw. Ciao, THEfish! Quote Link to comment https://forums.phpfreaks.com/topic/52269-solved-cant-get-data-into-mysql-database/#findComment-257998 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.