sammyconn Posted February 12, 2007 Share Posted February 12, 2007 i know nothing about php or mysql so keep any answers simple please! ??? I built a website for my missus and want to collect submitted form data to a mysql database provided by the hosting company. Can't access the database unless online. I created a table in the database called contact_us with seven fields. I inserted this code before any html code: <?php $db_host = "localhost"; $db_user = ""; $db_pwd = ""; $db_name = ""; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); ?> obviously using my own username and password between the " " in the body of the html, i inserted this code for my form: <?php if (!isset($_POST['submit'])) { ?> <form action="" method="post"> Name: <input type="text" name="name"><br> Address 1: <input type="text" name="address1"><br> Address 2: <input type="text" name="address2"><br> Postcode: <input type="text" name="postcode"><br> Telephone: <input type="text" name="telephone"><br> Email: <input type="text" name="email"><br> Comments: <input type="textarea" name="comments"><br> <input type="submit" name="submit" value="Submit!"> </form> <?php } else { $name = $_POST['name']; $address1 = $_POST['address1']; $address2 = $_POST['address2']; $postcode = $_POST['postcode']; $telephone = $_POST['telephone']; $email = $_POST['email']; mysql_query("INSERT INTO `contact_us` (name, address1, address2, postcode, telephone, email, comments) VALUES ('$name', '$address1', '$address2','$postcode','$telephone','$email','$comments',)"); echo "Thank you, your information has been added."; } ?> needless to say it doesn't work. Can anybody point me in the right direction? once the form is working, how do i then view information submitted to the contact us table? any help much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/38221-idiot-needs-help/ Share on other sites More sharing options...
wildteen88 Posted February 12, 2007 Share Posted February 12, 2007 make sure you connect to MySQL in your second code block. If you are not connected to MySQL the query will fail to work as there is no connection. What you should do is save your mysql connection code in a file called db.inc.php. Then include this file when you need to connect to the database like so: include 'db.inc.php'; Quote Link to comment https://forums.phpfreaks.com/topic/38221-idiot-needs-help/#findComment-183053 Share on other sites More sharing options...
Daniel0 Posted February 12, 2007 Share Posted February 12, 2007 You also need to make sure that the mysql extension is actually loaded. In PHP5 it isn't by default. I'm not sure about PHP4. Check your php.ini to see if extension=php_mysql.dll (Windows) or extension=php_mysql.so (Linux - not sure if it has the php_ prefix) is present (without a semi-colon in the front). Quote Link to comment https://forums.phpfreaks.com/topic/38221-idiot-needs-help/#findComment-183058 Share on other sites More sharing options...
calabiyau Posted February 12, 2007 Share Posted February 12, 2007 In your query you have to use $name, $address 1 etc. You just have name, address 1, etc. To view the entries once you have submitted them into the database you have to make a new page and use a SELECT query to see the results. Or else use php my admin. Quote Link to comment https://forums.phpfreaks.com/topic/38221-idiot-needs-help/#findComment-183071 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.