Search the Community
Showing results for tags 'php mysql sql forms'.
-
Hi, I'd like to apologize if I sound like a noob. Other than a book on dummies about php and mysql, I'm new to php and mysql combined. Here is the code where my form is: <class="form-horizontal"> <!-- this is bootstrap form type --> <div id="question"><h1>Have a question?</h1></div> <div class="well span5"> <div class="control-group> <!-- made for each form type --> <div class="control-label" for="name"><strong>Query</strong></label> <div class="controls"> <!-- start form stuff here --> <form action="queries.php" method="post" /> <input type="text" class="span5" placeholder="Type your question here!" name="user_questions" /> <input type="submit" value="Submit" class="btn-primary" /></button> </form> </div> </div> </div> </div> as you can see, the name of the form is "user_questions and the php script linked to it is queries.php. Here is the php code linking mysql to the form: <?php error_reporting(-1); define ('DB_NAME', 'questions'); define ('DB_USER', 'root'); define ('DB_PASSWORD', ''); define ('DB_HOST', 'localhost'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db(DB_NAME, $link); if (!$db_selected) { die('Can\'t use ' . DB_NAME . ':'.mysql_error()); } echo 'Connected successfully'; $value = $_POST['user_questions']; $sql = "INSERT INTO questions_user (questions_field) VALUES ('$value')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } mqsql_close(); ?> (yes i'm aware that having root and no password is very dangerous. This website that i'm making is only a project i'm doing to gain more experience.) As you can see. The script will die if anything doesn't work and it will give me an error message. However if it successfully gets through linking the database then it will say "successfully connected". When I put a query into my form and submit, I'm sent to the queries.php page where it says "successfully connected". Since I haven't made any redirecting or anything it just stops there. But then I go to my database to see if the data is stored and it is empty. **DATABASE INFO** The db name is "questions" The only table is "questions_user" The 2 fields are "ID", which is the primary key with A I and "questions_field" which stores the data with TEXT. If you need anything else just let me know. It's driving me insane. Thanks, Fisher