mydownfall00 Posted June 2, 2009 Share Posted June 2, 2009 First post, doesn't mean anything. There's many who know more, but that's not the point. So, im attempting to create a sign up form and i have the script working.. it's running and i don't get any errors. Although it doesn't want to insert the information into the database. The database is ran through the site where I have my server and I set the database up through there. username varchar(25) No firstname varchar(25) No lastname varchar(25) No email varchar(30) No sex varchar(7) No age tinyint(3) No (the no's mean not null... just saying) this is how my database table is setup. i don't have a primary key.. which im pretty sure that I should but I know how to auto_increment I just didnt know how to include it with the form in html. now here is my php code $username=$_POST['username']; $firstname=$_POST['firstname']; $lastname=$_POST['lastname']; $email=$_POST['email']; $sex=$_POST['sex']; $age=$_POST['age']; $query = "INSERT INTO member(username, firstname, lastname, email, sex, age) VALUES ('$username', '$firstname', 'lastname', 'email', 'sex', 'age')"; $result = ($query); if (!$result) { $errormessage = pg_last_error(); echo "Error with query: " . $errormessage; exit(); } printf ("These values were inserted into the database - %s %s %s", $username, $firstname, $lastname); ?> if anyone could possibly help me it would be great or if you see an error in my code or how i have my table setup.. that is where the error is i just don't know how to fix it. any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/ Share on other sites More sharing options...
anupamsaha Posted June 2, 2009 Share Posted June 2, 2009 Dude, where the query is executing? Issue in this line: $result = ($query); Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-847514 Share on other sites More sharing options...
mydownfall00 Posted June 2, 2009 Author Share Posted June 2, 2009 i'm not exactly sure how to fix that.. ??? im really lost.. sorry Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-847519 Share on other sites More sharing options...
anupamsaha Posted June 2, 2009 Share Posted June 2, 2009 i'm not exactly sure how to fix that.. ??? im really lost.. sorry Change the following: $result = ($query); To: $result = pg_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-847527 Share on other sites More sharing options...
Alt_F4 Posted June 2, 2009 Share Posted June 2, 2009 $query = "INSERT INTO member(username, firstname, lastname, email, sex, age) VALUES ('$username', '$firstname', 'lastname', 'email', 'sex', 'age')"; your last 4 variables lastname,email etc are missing the $ what database are you using?? Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-847528 Share on other sites More sharing options...
mydownfall00 Posted June 2, 2009 Author Share Posted June 2, 2009 Fatal error: Call to undefined function pg_query() is the error i get now that i changed the result query, and yeah i put the $ back where they belong.. i cant believe i missed them. Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-847530 Share on other sites More sharing options...
anupamsaha Posted June 2, 2009 Share Posted June 2, 2009 Fatal error: Call to undefined function pg_query() is the error i get now that i changed the result query, and yeah i put the $ back where they belong.. i cant believe i missed them. What database are you using? Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-847538 Share on other sites More sharing options...
dreamwest Posted June 2, 2009 Share Posted June 2, 2009 Fatal error: Call to undefined function pg_query() is the error i get now that i changed the result query, and yeah i put the $ back where they belong.. i cant believe i missed them. What database are you using? Most likely mysql $result = mysql_query($query); pg_query() isnt a mysql function Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-847547 Share on other sites More sharing options...
anupamsaha Posted June 2, 2009 Share Posted June 2, 2009 Fatal error: Call to undefined function pg_query() is the error i get now that i changed the result query, and yeah i put the $ back where they belong.. i cant believe i missed them. What database are you using? Most likely mysql $result = mysql_query($query); pg_query() isnt a mysql function I know. But, did you look at pg_last_error() statement in the code? Its PostgreSQL database statement. So, I took it as he is using PostgreSQL database. Hope, I am making sense. Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-847550 Share on other sites More sharing options...
mydownfall00 Posted June 2, 2009 Author Share Posted June 2, 2009 phpMyAdmin - 2.11.9.5 MySQL client version: 5.0.67 okay.. i dont know all that much of sql.. i did it back in high school and i was just playing around to see what i could still possibly do since im paying for a host. i have a php for dummies book i have to find.. but i like talking to atleast someone about it. i have no idea what a PostgreSQL database is.. but that's what my host uses. im not too sure about the differences in the code, but if someone could just fill me in a little bit.. that would be cool. Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-847920 Share on other sites More sharing options...
anupamsaha Posted June 2, 2009 Share Posted June 2, 2009 Ok, try this: <?php $username=$_POST['username']; $firstname=$_POST['firstname']; $lastname=$_POST['lastname']; $email=$_POST['email']; $sex=$_POST['sex']; $age=$_POST['age']; $query = "INSERT INTO `member`(`username`, `firstname`, `lastname`, `email`, `sex`, `age`) VALUES ('$username', '$firstname', '$lastname', '$email', '$sex', '$age')"; $result = mysql_query($query); if (!$result) { $errormessage = mysql_error(); echo "Error with query: " . $errormessage; exit(); } printf ("These values were inserted into the database - %s %s %s", $username, $firstname, $lastname); ?> Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-847924 Share on other sites More sharing options...
mydownfall00 Posted June 2, 2009 Author Share Posted June 2, 2009 Okay, so the code im pretty sure is going to work except now I am having a problem with my connection and it's saying that Warning: mysql_query() [function.mysql-query]: Access denied for user 'shopceme'@'localhost' (using password: NO) in /home/shopceme/public_html/mydownfall/add2.php on line 35 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/shopceme/public_html/mydownfall/add2.php on line 35 Error with query: Access denied for user 'shopceme'@'localhost' (using password: NO) and im not exactly sure which username and password I have to use, when I create a new database through phpmyadmin it makes me create a user to login and access it. im thinking that is the one that you would have to use but it doesnt seem to be trying. im going to attempt to make a new table really quick and see what I can do incase I have the password wrong. One question though, how do I set up an auto_increment to give as a user id so say each time someone signs up they will each be given a number such as #1, #2, #3 and so on.. and how do I set that up with the html form.. or dont I even have to include it because of the auto_increment.. just checking.. i really appreciate all this help. Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-848172 Share on other sites More sharing options...
mydownfall00 Posted June 2, 2009 Author Share Posted June 2, 2009 this is how i have my connection setup.. $host="localhost"; $username="myusername"; // $password="password"; // $db_name="shopceme_mydownfall"; now the database I have created is called shopceme_mydownfall and then the table I have created inside shopceme_mydownfall is called user... so... $query = "INSERT INTO `user` i changed that.. but it wont let me connect. im not sure if i have to change anything in the settings of my server or not. (btw i made a new table so there is only username firstname lastname and email.) EDIT!!!! Okay, I get the error message on line 34: this is what line 34 consists of... $result = mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-848178 Share on other sites More sharing options...
MadTechie Posted June 2, 2009 Share Posted June 2, 2009 Okay add this, right after <?php $link = mysql_connect('localhost', 'root', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; $DBname = "MyDatabase"; $db_selected = mysql_select_db($DBname, $link); if (!$db_selected) { die ("Can't use $DBname: " . mysql_error()); } but change the $DBname = "MyDatabase"; to your database name (the name of the database on the left in PMA) Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-848179 Share on other sites More sharing options...
mydownfall00 Posted June 2, 2009 Author Share Posted June 2, 2009 Man im sorry that this is so hard and i dont freakin know what's wrong because now Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'admin'@'localhost' (using password: YES) in /home/shopceme/public_html/mydownfall/add2.php on line 20 Could not connect: Access denied for user 'admin'@'localhost' (using password: YES) i think since it's saying yes that the password is working but the user I don't know why it's not working. When I just created this table.. it asked me to setup a username and a password.. which I believe would be the reason to connect to the database.. unless it's something else but there aren't that many choices especially since i think the password is right.. sorry im trying guys.. EDIT!!! also I just went and changed the password so password = yes must not mean that I have my password correct. Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-848195 Share on other sites More sharing options...
mydownfall00 Posted June 3, 2009 Author Share Posted June 3, 2009 Just wondering if there is still anyone there that can help me.. Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-848544 Share on other sites More sharing options...
gevans Posted June 3, 2009 Share Posted June 3, 2009 Show all your code to date Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-848547 Share on other sites More sharing options...
mydownfall00 Posted June 3, 2009 Author Share Posted June 3, 2009 I appreciate it but I got it to work, with the help of everyone else. thanks a lot guys, i'll be back with more questions.. don't worry. Quote Link to comment https://forums.phpfreaks.com/topic/160592-solved-script-wont-post-in-database/#findComment-848559 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.