escobar Posted November 21, 2011 Share Posted November 21, 2011 Hello, I have a situation witch gave me a lot of headache. I have a simple form for inserting informations in a table, but my problem is that only the data with text values simply don't won't to be saved in my database. I tried a lot of combinations, and everything is ok, i can get the values of the variables like in the form, but i just can't store them in database. Please help, here is the code: Form: <form name="forma" action="form.php" method="post"> <br /> <fieldset> <legend><b>Chose day and month:</b></legend> <div class="class1"> <select name="dayy"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> </div> <div class="class2"> <select name="monthh"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> </div> <div class="class3"> <select name="yearr"> <option value="2011">2011</option> </select> </div> </fieldset> <table border="0"> <tr> <td><b>Chose employe:</b></td> <td> <select name="emp"> <option value="Name">Name</option> <option value="Name1">Name1</option> <option value="Name2">Name2</option> <option value="Name3">Name3</option> </select> </td> </tr> <tr> <td><b>Start:</b></td> <td> <select name="sum1"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </td> </tr> <tr> <td><b>End:</b></td> <td> <select name="sum2"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> </td> </tr> </table> <input type="submit" name="submit" value="Send" /> </form> Php code: require_once "mysql_info.php"; $link = @mysql_connect($server, $username, $password); if (!$link) { echo "Error with server"; exit(); } $bbaza = mysql_select_db($database, $link); if (!$bbaza) { echo "Error with database"; exit(); } if (isset($_POST['submit'])) { $day = $_POST['dayy']; $month = $_POST['monthh']; $year = $_POST['yearr']; $person = $_POST['emp']; $poc_rada = $_POST['sum1']; $zav_rada = $_POST['sum2']; } $query = "INSERT INTO evidencija (djel, poc, zav, dan, mjesec, god) VALUES ($person, $poc_rada, $zav_rada, $day, $month, $year);"; $result = mysql_query($query); if ($result) echo "<p>OK!!!</p>"; else echo "<p>Something is wrong!!!</p>"; mysql_close(); Weird thing is when i try to put some numbers instead of characters in employees field the insertion is ok, but when i try to use names and surnames the insertion does not work. And i have try to change column type from varchar, and text and it didnt work. I hope someone will help me, thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/251547-problems-with-query-for-insert-data-from-form/ Share on other sites More sharing options...
fenway Posted November 21, 2011 Share Posted November 21, 2011 Echo $query. Quote Link to comment https://forums.phpfreaks.com/topic/251547-problems-with-query-for-insert-data-from-form/#findComment-1290025 Share on other sites More sharing options...
escobar Posted November 21, 2011 Author Share Posted November 21, 2011 Thank you fenway for your fast answer, but that didni solve my problem. My problem is that i can't put value from variable "emp" to database. Quote Link to comment https://forums.phpfreaks.com/topic/251547-problems-with-query-for-insert-data-from-form/#findComment-1290034 Share on other sites More sharing options...
escobar Posted November 22, 2011 Author Share Posted November 22, 2011 I have error code, maybe somebody will know from error: Your Query: INSERT INTO evidencija (djel, poc, zav, dan, mjesec, god) VALUES ('Name1', '8.30', '16.30', '1', '1, 2011'); Error: (1136) Column count doesn't match value count at row 1 Quote Link to comment https://forums.phpfreaks.com/topic/251547-problems-with-query-for-insert-data-from-form/#findComment-1290354 Share on other sites More sharing options...
fenway Posted November 23, 2011 Share Posted November 23, 2011 Your VALUES are mis-quoted. You really should be using a DB wrapper. Quote Link to comment https://forums.phpfreaks.com/topic/251547-problems-with-query-for-insert-data-from-form/#findComment-1290808 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.