sigridish Posted January 31, 2013 Share Posted January 31, 2013 Hi all! I would like to ask for help. i have a code that i got from youtube. my problem is i cant connect to my database and i dont know why. i dont think that i have a problem in my code. i have 2 php file. reg.php for the connection and demo-form.php for adding the record. demo-form.php <form action="reg.php" method="post" /> <p>First Name: <input type="text" name="fname" /> </p> <p>Middle Name: <input type="text" name="mname" /> </p> <p>Last Name: <input type="text" name="lname" /> </p> <p>Home address: <input type="text" name="homeadd" /> </p> <p>Email address: <input type="text" name="emailadd" /> </p> <p>Office/project number: <input type="text" name="ofcnum" /> </p> <p>Mobile number: <input type="text" name="mobilenum" /> </p> <p>Home number: <input type="text" name="homenum" /> </p> <p>Position: <select name="position"> <option value ="">Select</option> <option value ="Project Manager">Project Manager</option> <option value ="Practice Lead">Project Manager</option> <option value ="Team Leader">Team Leader</option> <option value ="Team Member">Team Member</option> </select> <p>Practice: <select name="position"> <option value ="">Select</option> <option value ="Solutions">Solutions</option> <option value ="Outsourcing">Outsourcing</option> </select> <p>Project Name: <input type="text" name="projname" /> </p> <p>Project Manager: <input type="text" name="projmgr" /> </p> <p>Team Leader: <input type="text" name="teamlead" /> </p> <input type="submit" value="Submit" /> <body bgcolor="cccccc"> </form> reg.php <?php[/b] [b]define ('DB_NAME', 'emp'); define ('DB_USER', 'root'); define ('DB_PASSWORD', ''); define ('DB_HOST', 'localhost');[/b] [b]$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);[/b] [b]if (!$link) { die('Could not connect: ' . mysql_error()); }[/b] [b]$db_selected = mysql_select_db(DB_NAME, $link);[/b] [b]if (!$db_selected) { die('Can\'t use ' . DB_NAME . ': ' . mysql_error()); }[/b] [b]$value1 = $_POST["fname"]; $value2 = $_POST["mname"]; $value3 = $_POST["lname"]; $value4 = $_POST["homeadd"]; $value5 = $_POST["emailadd"]; $value6 = $_POST["ofcnum"]; $value7 = $_POST["mobilenum"]; $value8 = $_POST["homenum"]; $value9 = $_POST["position"]; $value10 = $_POST["practice"]; $value11 = $_POST["projname"]; $value12 = $_POST["projmgr"]; $value13 = $_POST["teamlead"];[/b] [b]$sql = "INSERT INTO employee (fname, mname, lname, homeadd, emailadd, ofcnum, mobilenum, homenum, position, projname, projmgr, teamlead) VALUES ('$value1', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); }[/b] [b]mysql_close();[/b] [b]?> Quote Link to comment https://forums.phpfreaks.com/topic/273854-cant-connect-php-to-database/ Share on other sites More sharing options...
Barand Posted January 31, 2013 Share Posted January 31, 2013 Perhaps you might like to share any error messages with us. Quote Link to comment https://forums.phpfreaks.com/topic/273854-cant-connect-php-to-database/#findComment-1409333 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.