laron Posted March 20, 2007 Share Posted March 20, 2007 I am having a problem INSERTing into mysql database(online) I am able to make the connection, and my php looks like it works, but when i check the database nothing is there my main form: <?php $db_name = 'goaustindata'; $mysql_user = 'austin'; $mysql_password = 'sow5453had'; $db = mysql_connect('localhost',$mysql_user,$mysql_password); /*if problem w/ database, comment*/ if(!$db){ echo 'Error connecting to the database, mesage returned: '. mysql_error(); die; } $link = mysql_select_db($db_name); if(!$link){ echo 'error selecting the database, message returned: '. mysql_error(); die; } ?> <form action="inputdata.php" method="post"> <table border="0" cellpadding="0" cellspacing="2"> <tr><td> E-mail</td><td><input type="text" name="email" /></td></tr> <tr><td> Username:</td><td><input type="text" name="username" /></td></tr> <tr><td> Password:</td><td><input type="password" name="password" /></td></tr> <tr><td> </td><td> <input type="submit" name="submit" value="Register" /></td></tr> </table> </form> and the page it is sent to on submit <?php $email = $_POST['email']; $username = $_POST['username']; $password = $_POST['password']; $server = 'localhost'; $user = '*******'; $pass = '********'; $database = '********'; $ip = $_SERVER['HTTP_USER_AGENT']; // connect to the sql database using the variables set inn 'config.php' $link = mysql_connect($server, $user, $pass); $db = mysql_select_db($database, $link); // the 'insert' that will er, insert the data as a new row into the table under the respective columns. $query = "INSERT INTO user (username, password, email, ip) VALUES ('$username', '$password', '$emali', '$ip', '$email',)"; $result = mysql_query($query, $link); echo 'Thank you for registering.'; ?> it is sloppy code at the moment, but I am just trying to get it to work before i move on.... thanks Quote Link to comment Share on other sites More sharing options...
codexx Posted March 20, 2007 Share Posted March 20, 2007 Could you post some of your code please? Its hard for us to help you trouble shoot guessing at what could be going wrong. Quote Link to comment Share on other sites More sharing options...
laron Posted March 20, 2007 Author Share Posted March 20, 2007 yes, i modified it right after i posted, sorry Quote Link to comment Share on other sites More sharing options...
Warptweet Posted March 20, 2007 Share Posted March 20, 2007 I just made a topic about this. My problem was that at my control panel, I forget to give my database the permissions. Make sure your database has ALL the permissions needed to be written in. Since I trust myself (obviously), I just give my database ALL permissions, instead of a select few. Considering you have database, I almost 100% assume you have a control panel to set your database permissions. Quote Link to comment Share on other sites More sharing options...
codexx Posted March 20, 2007 Share Posted March 20, 2007 <?php $query = "INSERT INTO user (username, password, email, ip) VALUES ('$username', '$password', '$emali', '$ip', '$email')"; ?> Emali? If your database has 4 slots and you are trying to input 5 pieces of data, its not going to like you very much. Try this instead. <?php $query = "INSERT INTO user (username, password, email, ip) VALUES ('".$username."', '".$password."', '".$ip."', '".$email."')"; ?> If that doesn't work try to see if $result is even executing properly. <?php $result = mysql_query($query, $link); if($result){ echo 'Thank you for registering.'; }else{ echo 'There has been a database error.'; } ?> Quote Link to comment Share on other sites More sharing options...
laron Posted March 20, 2007 Author Share Posted March 20, 2007 where do I edit the permissions Quote Link to comment Share on other sites More sharing options...
codexx Posted March 20, 2007 Share Posted March 20, 2007 I don't think it is your permissions, I think it is your insert command formatting. Quote Link to comment Share on other sites More sharing options...
laron Posted March 20, 2007 Author Share Posted March 20, 2007 well ive done what you have recomended and, it echo'ed' "There has been a database error." so may it be the permissions not letting it insert or edit, or the format of my insert Quote Link to comment Share on other sites More sharing options...
codexx Posted March 20, 2007 Share Posted March 20, 2007 try to replace this line again. I fixed it up a little more. <?php $query = "INSERT INTO user (username, password, email, ip) VALUES ('".$username."', '".$password."', '".$ip."', '".$email."')"; ?> Quote Link to comment Share on other sites More sharing options...
laron Posted March 20, 2007 Author Share Posted March 20, 2007 awsome! it solved the problem... thank you much! Quote Link to comment Share on other sites More sharing options...
btherl Posted March 20, 2007 Share Posted March 20, 2007 There's a little switcheroo in there.. email and ip <?php $query = "INSERT INTO user (username, password, email, ip) VALUES ('".$username."', '".$password."', '".$email."', '".$ip."')"; ?> Quote Link to comment 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.