blackhawk08 Posted April 22, 2007 Share Posted April 22, 2007 im having a real hard time...i cant figure out why this wont work...anyone got any ideas? the code is at http://pastebin.ca/452773 ??? ??? ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/ Share on other sites More sharing options...
john010117 Posted April 22, 2007 Share Posted April 22, 2007 Try this: <?php // Connect to the database $host = "HOST"; // db host $user = "USERNAME"; // db username $pass = "PASSWORD"; // db password $db = "DATABASE NAME"; // db name $connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect"); mysql_select_db ($db) or die ("Unable to select database"); ?> Remember to replace all the capitalized words with your own. Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235214 Share on other sites More sharing options...
blackhawk08 Posted April 22, 2007 Author Share Posted April 22, 2007 i tried doing that and added echo 'test approved'; at the end, and nothing printed Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235217 Share on other sites More sharing options...
blackhawk08 Posted April 22, 2007 Author Share Posted April 22, 2007 anyone? i cant get this thing frustration is kicking in... Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235225 Share on other sites More sharing options...
john010117 Posted April 22, 2007 Share Posted April 22, 2007 So you didn't get any error messages? If that's the case, try putting a mysql query after that. Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235226 Share on other sites More sharing options...
blackhawk08 Posted April 22, 2007 Author Share Posted April 22, 2007 this creates no output, not even in the source <html> <head> <title>Example</title> </head> <?php include 'dbconnect.php'; $query = "SELECT * FROM Person"; $result = mysql_query($sql); $people = array(); while($row = mysql_fetch_array($result)){ $people[] = $row; } ?> <body> <?php die("<pre>" . print_r($people,true) . "</pre>"); ?> </body> </html> the included file is: <?php // Connect to the database $host = "localhost"; // db host $user = "root"; // db username $pass = "********"; // db password $db = "testing"; // db name $connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect"); mysql_select_db ($db) or die ("Unable to select database"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235230 Share on other sites More sharing options...
jchemie Posted April 22, 2007 Share Posted April 22, 2007 Hi, Make sure you have the host address and the port written correctly. If it still aint working... my only guess comes that the connection config aint correct. You could also check if there is an error in the username and password, else if the user is assigned the rights to access the database. Thanks Jyot Vakharia Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235231 Share on other sites More sharing options...
AndyB Posted April 22, 2007 Share Posted April 22, 2007 $query = "SELECT * FROM Person"; $result = mysql_query($sql); How about $query = "SELECT * FROM Person"; $result = mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235236 Share on other sites More sharing options...
blackhawk08 Posted April 22, 2007 Author Share Posted April 22, 2007 no change...but that did make a lot of sense...im going to try reinstalling php, and check my sql configs...been awhile since ive worked with this stuff, maybe i messed soemthing up last time i tried this stuff Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235239 Share on other sites More sharing options...
AndyB Posted April 22, 2007 Share Posted April 22, 2007 Well, maybe you want to extend your error trapping while you're at it. $query = "SELECT * FROM Person"; $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); // what's happening? Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235243 Share on other sites More sharing options...
blackhawk08 Posted April 22, 2007 Author Share Posted April 22, 2007 im at a complete loss here...reinstalled everything...now im using a WAMP bundle...cant seem to figure out whats going on...here's my latest code <html> <head> <title>add info into sql</title> </head> <body> <?php include 'dbconnect.php'; { $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $age = $_POST['age']; $query = "INSERT INTO Person('FirstName', 'LastName', 'Age'); mysql_query($query) or die('Error, Insert query failed'); mysql_Close($conn) echo 'new data added'; } else { ?> <form method="post"> <table width="400" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="100">Firstname</td> <td><input name="Firstname" type="text" id="firstname"></td> </tr> <tr> <td width="100">lastname</td> <td><input name="lastname" type="text" id="lastname"></td> </tr> <tr> <td width="100">age</td> <td><input name="age" type="text" id="age"></td> </tr> <tr> <td width="100"> </td> <td> </td> </tr> <tr> <td width="100"> </td> <td><input name="add" type="submit" id="add" value="Add New Info"></td> </tr> </table> </form> <?php } ?> </body> </html> and the dbconnect.php is: <?php // Connect to the database $host = "127.0.0.1:3307"; // db host $user = "root"; // db username $pass = "ind34dol"; // db password $db = "testing"; // db name $connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect"); mysql_select_db ($db) or die ("Unable to select database"); ?> what am i missing here? where am i screwing up? im not getting ANY output, not even the form that i created..NOTHING Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235291 Share on other sites More sharing options...
MadTechie Posted April 22, 2007 Share Posted April 22, 2007 note change <?php $query = "INSERT INTO Person('FirstName', 'LastName', 'Age'); ?> to <?php $query = "INSERT INTO Person('FirstName', 'LastName', 'Age')"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235294 Share on other sites More sharing options...
wildteen88 Posted April 22, 2007 Share Posted April 22, 2007 Looks like you have forgotten to close a string somewhere in you code, if you look at the first code block above you will see about half way through the syntax colouring goes wrong. This is the offending line: $query = "INSERT INTO Person('FirstName', 'LastName', 'Age'); Change it to: $query = "INSERT INTO Person('FirstName', 'LastName', 'Age')"; Also it is a good idea to run display_errors on in your php.ini. If you make any changes to the php.ini make sure you restart Apache. EDIT: Ooh MadTechie beat me to it. Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235298 Share on other sites More sharing options...
blackhawk08 Posted April 22, 2007 Author Share Posted April 22, 2007 still no output, i have all error reporting on, what reasons could there be for no output? [move]*BlackHawk starting to get annoyed*[/move] Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235308 Share on other sites More sharing options...
wildteen88 Posted April 22, 2007 Share Posted April 22, 2007 Does a simple: <?php echo "Hello World"; ?> Work? If that doesn't work then Apache is not configured properly. Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235311 Share on other sites More sharing options...
MadTechie Posted April 22, 2007 Share Posted April 22, 2007 Simple test #2 <?php phpinfo(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235313 Share on other sites More sharing options...
blackhawk08 Posted April 22, 2007 Author Share Posted April 22, 2007 yes, everything works until i try adding the mysql_connect() command Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235329 Share on other sites More sharing options...
MadTechie Posted April 22, 2007 Share Posted April 22, 2007 so what errors are you getting ? if not try adding error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235334 Share on other sites More sharing options...
wildteen88 Posted April 22, 2007 Share Posted April 22, 2007 yes, everything works until i try adding the mysql_connect() command Check that the mysql extension is loaded by running phpinfo() and scrolling down the page until you find a mysql section. Click the link in my sig below and read the FAQ thread titled called to undefined function mysql_connect Quote Link to comment https://forums.phpfreaks.com/topic/48132-mysql_connect/#findComment-235342 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.