Fish181 Posted August 19, 2013 Share Posted August 19, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/281333-i-cant-figure-out-why-data-isnt-saving-in-my-tables/ Share on other sites More sharing options...
jazzman1 Posted August 19, 2013 Share Posted August 19, 2013 He-he, you didn't execute the query string to your database. Quote Link to comment https://forums.phpfreaks.com/topic/281333-i-cant-figure-out-why-data-isnt-saving-in-my-tables/#findComment-1445721 Share on other sites More sharing options...
Fish181 Posted August 19, 2013 Author Share Posted August 19, 2013 I didn't?? How do I do that? Quote Link to comment https://forums.phpfreaks.com/topic/281333-i-cant-figure-out-why-data-isnt-saving-in-my-tables/#findComment-1445722 Share on other sites More sharing options...
mac_gyver Posted August 19, 2013 Share Posted August 19, 2013 the query is being ran - if (!mysql_query($sql)) { Quote Link to comment https://forums.phpfreaks.com/topic/281333-i-cant-figure-out-why-data-isnt-saving-in-my-tables/#findComment-1445723 Share on other sites More sharing options...
jazzman1 Posted August 19, 2013 Share Posted August 19, 2013 I didn't?? How do I do that? It should be something like $result = mysql_query($sql, $link); if(!$result) die('Error: ' . mysql_error()); As a newbie in php you should consider using mysqli or pdo libraries in php instead the mysql. Don't waste your time! Quote Link to comment https://forums.phpfreaks.com/topic/281333-i-cant-figure-out-why-data-isnt-saving-in-my-tables/#findComment-1445724 Share on other sites More sharing options...
Fish181 Posted August 19, 2013 Author Share Posted August 19, 2013 Thanks a ton! I'll be sure to check out those two options as well. Quote Link to comment https://forums.phpfreaks.com/topic/281333-i-cant-figure-out-why-data-isnt-saving-in-my-tables/#findComment-1445725 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.