johnmark Posted February 6, 2007 Share Posted February 6, 2007 Hey, i know this is going to be really nooby but i'm having trouble with this simple php database connect code. It's not inserting anything into my table, please help. NOTE: In the real file, I have the strings filled out. <?php $database_host = ""; $database_username = ""; $database_password = ""; mysql_connect($database_host, $database_username, $database_password); mysql_select_db("jb"); mysql_query("INSERT INTO John (Name, Email, Definition, Date) VALUES ('John Bizzle', 'johnbizzle@bizzle.com', 'Please work', '2007-02-96');"); ?> Quote Link to comment Share on other sites More sharing options...
hvle Posted February 6, 2007 Share Posted February 6, 2007 mysql_connect return a database link, so you should use this link in the mysql_query to database: $db_link = mysql_connect($database_host, $database_username, $database_password); mysql_select_db("jb"); $resultSet = mysql_query("INSERT INTO John (Name, Email, Definition, Date) VALUES ('John Bizzle', 'johnbizzle@bizzle.com', 'Please work', '2007-02-96');", $db_link); Quote Link to comment Share on other sites More sharing options...
johnmark Posted February 6, 2007 Author Share Posted February 6, 2007 Is this maybe a server problem? Because that didn't work either. Quote Link to comment Share on other sites More sharing options...
hvle Posted February 6, 2007 Share Posted February 6, 2007 did it give any error? Quote Link to comment Share on other sites More sharing options...
johnmark Posted February 6, 2007 Author Share Posted February 6, 2007 No, it just loads the page, but if i put it above a page of html, it stops downloading the page. So it's like it just stops. No error messages at all. Quote Link to comment Share on other sites More sharing options...
trq Posted February 6, 2007 Share Posted February 6, 2007 You dont need to use the database link. Try this.... <?php $database_host = ""; $database_username = ""; $database_password = ""; mysql_connect($database_host, $database_username, $database_password) or die("Unable to connect"); mysql_select_db("jb") or die("Unable to select db"); $sql = "INSERT INTO John (Name, Email, Definition, `Date`) VALUES ('John Bizzle', 'johnbizzle@bizzle.com', 'Please work', '2007-02-96');" if (mysql_query($sql)) { echo "Insert success"; } else { echo mysql_error(); } ?> PS; Date is a reserved word in sql. Hence the surrounding backticks. Quote Link to comment Share on other sites More sharing options...
johnmark Posted February 6, 2007 Author Share Posted February 6, 2007 Still not working, I have a feelling something to do with my database being on my friends computer and my server being on mine? I probably set something up totally wrong. Quote Link to comment Share on other sites More sharing options...
trq Posted February 6, 2007 Share Posted February 6, 2007 Did you setup the mysql database to accept connections from your ip? Quote Link to comment Share on other sites More sharing options...
johnmark Posted February 6, 2007 Author Share Posted February 6, 2007 Well I can connect to it manualy so i'm guessing yes. Maybe i'll try to download sql on my computer and see what happens. Quote Link to comment Share on other sites More sharing options...
hvle Posted February 6, 2007 Share Posted February 6, 2007 It should give you some kind of error. I would try to debug it by turn on error reporting: place this line at the very first of your php script: error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); post any error, warning you received. Quote Link to comment Share on other sites More sharing options...
trq Posted February 6, 2007 Share Posted February 6, 2007 Well I can connect to it manualy so i'm guessing yes What with? Quote Link to comment Share on other sites More sharing options...
johnmark Posted February 6, 2007 Author Share Posted February 6, 2007 Putty. Quote Link to comment Share on other sites More sharing options...
trq Posted February 6, 2007 Share Posted February 6, 2007 Yeah, but with putty aren't you connecting to your friends machine and then opening mysql? Quote Link to comment Share on other sites More sharing options...
trq Posted February 6, 2007 Share Posted February 6, 2007 Also... as noted you should be at least getting the error messages I posted. What happens when you run the page. We need details. Quote Link to comment Share on other sites More sharing options...
johnmark Posted February 6, 2007 Author Share Posted February 6, 2007 When i run the page with that code, Nothing happens, it loads the page and says it's loading for a while... then just stops like it's done. Quote Link to comment Share on other sites More sharing options...
trq Posted February 6, 2007 Share Posted February 6, 2007 When you run this code? <?php $database_host = ""; $database_username = ""; $database_password = ""; mysql_connect($database_host, $database_username, $database_password) or die("Unable to connect"); mysql_select_db("jb") or die("Unable to select db"); $sql = "INSERT INTO John (Name, Email, Definition, `Date`) VALUES ('John Bizzle', 'johnbizzle@bizzle.com', 'Please work', '2007-02-96');" if (mysql_query($sql)) { echo "Insert success"; } else { echo mysql_error(); } ?> Are you sure php is working properly? Quote Link to comment Share on other sites More sharing options...
johnmark Posted February 6, 2007 Author Share Posted February 6, 2007 Yes, when i run that code, i'm not sure of anything really, i'm not sure if my IIS is hooked up properly either. Quote Link to comment Share on other sites More sharing options...
trq Posted February 6, 2007 Share Posted February 6, 2007 Try a test page with this. <?php phpinfo(); ?> What does that produce? Quote Link to comment Share on other sites More sharing options...
johnmark Posted February 6, 2007 Author Share Posted February 6, 2007 It gives me all the php info. Quote Link to comment Share on other sites More sharing options...
trq Posted February 6, 2007 Share Posted February 6, 2007 Well.. Sorry, I'm not sure what the problem is. Does the page timeout? Quote Link to comment Share on other sites More sharing options...
johnmark Posted February 6, 2007 Author Share Posted February 6, 2007 Nope. Thanks guys for all your help, when I do get it running, i'll be just that much smarter. Quote Link to comment Share on other sites More sharing options...
trq Posted February 6, 2007 Share Posted February 6, 2007 Did you enable error reporting at the top of the script? Quote Link to comment Share on other sites More sharing options...
johnmark Posted February 6, 2007 Author Share Posted February 6, 2007 Yeah Quote Link to comment Share on other sites More sharing options...
trq Posted February 6, 2007 Share Posted February 6, 2007 And your calling this page via a url like? http://localhost/pagename.php I just can't see an issue.... it should output something! Quote Link to comment Share on other sites More sharing options...
johnmark Posted February 6, 2007 Author Share Posted February 6, 2007 Well php works, because i can use $_POST to get email and stuff, but when it gets to the database it just stops. 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.