liamk Posted May 23, 2012 Share Posted May 23, 2012 Code; -- phpMyAdmin SQL Dump -- version 3.4.5 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: May 23, 2012 at 02:55 PM -- Server version: 5.5.16 -- PHP Version: 5.3.8 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `stock` -- -- -------------------------------------------------------- -- -- Table structure for table `stocktransfers` -- CREATE TABLE IF NOT EXISTS `stocktransfers` ( `id` tinyint(11) NOT NULL AUTO_INCREMENT, `brands` varchar(250) NOT NULL, `season` varchar(250) NOT NULL, `name` varchar(250) NOT NULL, `tillcode` varchar(250) NOT NULL, `departments` varchar(250) NOT NULL, `size` varchar(250) NOT NULL, `quantity` varchar(250) NOT NULL, `color` varchar(250) NOT NULL, `auth` varchar(250) NOT NULL, `status` varchar(250) NOT NULL, `from` varchar(250) NOT NULL, `to` varchar(250) NOT NULL, `date` varchar(250) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; SQL Data Structure CREATE TABLE IF NOT EXISTS `stocktransfers` ( `id` tinyint(11) NOT NULL AUTO_INCREMENT, `brands` varchar(250) NOT NULL, `season` varchar(250) NOT NULL, `name` varchar(250) NOT NULL, `tillcode` varchar(250) NOT NULL, `departments` varchar(250) NOT NULL, `size` varchar(250) NOT NULL, `quantity` varchar(250) NOT NULL, `color` varchar(250) NOT NULL, `auth` varchar(250) NOT NULL, `status` varchar(250) NOT NULL, `from` varchar(250) NOT NULL, `to` varchar(250) NOT NULL, `date` varchar(250) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; No errors appear just cant seem to get this to insert the data everthing else i have created so far works just not that :\ Your help would be appreciated. Thanks, Liam. Quote Link to comment https://forums.phpfreaks.com/topic/262992-inserting-data-in-mysql-datebase/ Share on other sites More sharing options...
scootstah Posted May 23, 2012 Share Posted May 23, 2012 Because that code creates a table. Quote Link to comment https://forums.phpfreaks.com/topic/262992-inserting-data-in-mysql-datebase/#findComment-1347944 Share on other sites More sharing options...
liamk Posted May 23, 2012 Author Share Posted May 23, 2012 Sorry i noticed i never entered the php code my bad. <?php ob_start(); if (isset($_POST['add'])) { $brands= $_POST['brands']; $season= $_POST['season']; $name= $_POST['name']; $tillcode = $_POST['tillcode']; $departments = $_POST['departments']; $size = $_POST['size']; $quantity = $_POST['quantity']; $color = $_POST['color']; $auth = $_POST['auth']; $status = $_POST['status']; $from = $_POST['from']; $to = $_POST['to']; $date = $_POST['date']; $query = mysql_query("INSERTINTO stocktransfers (brands, season, name, tillcode, departments, size, quantity, color, auth, status, from, to, date) VALUES('$brands','$season','$name','$tillcode','$departments','$size','$quantity','$color','$auth,','$status','$from','$to','$date')"); echo "<meta http-equiv='refresh' content='0;url=page.php?id=stocktransfers' />"; } else { ?> <fieldset> <legend>Post Request</legend> <form method='POST'> <label>Brand:</label> <?php $sql = "SELECT brands FROM brands ORDER BY brands"; $result = mysql_query($sql); echo "<select name='brands'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['brands'] . "'>" . $row['brands'] . "</option>"; } echo "</select>"; ?> <br /> <label>Season:</label> <?php $sql = "SELECT season FROM season"; $result = mysql_query($sql); echo "<select name='season'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['season'] . "'>" . $row['season'] . "</option>"; } echo "</select>"; ?> <br /> <label>Product Name:</label> <input type='text' size='35' maxlength='255' name='name' /><br /> <label>Till Code:</label> <input type='text' size='35' maxlength='35' name='tillcode' /><br /> <label>Color:</label> <input type='text' size='35' maxlength='25' name='color' /><br /> <label>Size:</label> <input type='text' size='35' maxlength='25' name='size' /><br /> <label>Quantity:</label> <input type='text' size='35' maxlength='25' name='quantity' /><br /> <label>Department:</label> <?php $sql = "SELECT departments FROM departments"; $result = mysql_query($sql); echo "<select name='departments'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['departments'] . "'>" . $row['departments'] . "</option>"; } echo "</select>"; ?> <br /> <label>Authorized By:</label> <input type='text' size='35' maxlength='25' name='auth' /><br /> <label>Status:</label> <select name='status'> <option value='pending'>Pending</option> <option value='completed'>Completed</option> </select> <br /> <label>From:</label> <?php $sql = "SELECT branch FROM branch"; $result = mysql_query($sql); echo "<select name='from'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['branch'] . "'>" . $row['branch'] . "</option>"; } echo "</select>"; ?> <br /> <label>To:</label> <?php $sql = "SELECT branch FROM branch"; $result = mysql_query($sql); echo "<select name='to'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['branch'] . "'>" . $row['branch'] . "</option>"; } echo "</select>"; ?> <br /> <label>Date:</label> <input readonly="readonly"type='text' name='date' size='35' value='<?php echo date("D M d, Y G:i a"); ?>' /><br /> <input name='add' type='submit' value='Post Request' /> </form> </fieldset> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/262992-inserting-data-in-mysql-datebase/#findComment-1347950 Share on other sites More sharing options...
mrMarcus Posted May 23, 2012 Share Posted May 23, 2012 Try changing INSERTINTO to INSERT INTO 2 words. And, off topic, use header() for your redirects instead of <meta refresh>: header('Location: page.php?id=stocktransfers'); exit(0); Quote Link to comment https://forums.phpfreaks.com/topic/262992-inserting-data-in-mysql-datebase/#findComment-1347959 Share on other sites More sharing options...
liamk Posted May 23, 2012 Author Share Posted May 23, 2012 Thanks for the input and done the changes and still not working :\ Quote Link to comment https://forums.phpfreaks.com/topic/262992-inserting-data-in-mysql-datebase/#findComment-1347961 Share on other sites More sharing options...
mrMarcus Posted May 23, 2012 Share Posted May 23, 2012 Add: or die(mysql_error()); to the end of your query, like so: $query = mysql_query("INSERT INTO stocktransfers (brands, season, name, tillcode, departments, size, quantity, color, auth, status, from, to, date) VALUES('$brands','$season','$name','$tillcode','$departments','$size','$quantity','$color','$auth,','$status','$from','$to','$date')") or die(mysql_error()); and see if any errors come up. Quote Link to comment https://forums.phpfreaks.com/topic/262992-inserting-data-in-mysql-datebase/#findComment-1347963 Share on other sites More sharing options...
liamk Posted May 23, 2012 Author Share Posted May 23, 2012 I got this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, to, date) VALUES('47 Brand','SS11','sada2','asd','T-Shirts','sad','sad','a' at line 1 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/262992-inserting-data-in-mysql-datebase/#findComment-1347966 Share on other sites More sharing options...
mrMarcus Posted May 23, 2012 Share Posted May 23, 2012 Just looking quickly, you are using MySQL Reserved Words as column names in your database table. from and to are reserved words, and need to be encapsulated with ticks. Using `ticks` are good practice, but are rarely encouraged. And this is the issue noobs will find themselves in when not learning the real basics. Using error control also helps as you would have seen that there was a syntax error in your query had you used mysql_error() to begin with. So, add ticks to your column/field names like so: $query = mysql_query("INSERT INTO `stocktransfers` (`brands`, `season`, `name`, `tillcode`, `departments`, `size`, `quantity`, `color`, `auth`, `status`, `from`, `to`, `date`) VALUES('$brands'..... Quote Link to comment https://forums.phpfreaks.com/topic/262992-inserting-data-in-mysql-datebase/#findComment-1347967 Share on other sites More sharing options...
liamk Posted May 23, 2012 Author Share Posted May 23, 2012 Thankyou so much for your help and yes i am a n00b but very egar to learn and i am quick learner and everything that is told me i take on board. Thank you again This forum is brilliant Quote Link to comment https://forums.phpfreaks.com/topic/262992-inserting-data-in-mysql-datebase/#findComment-1347971 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.