stow19 Posted July 15, 2010 Share Posted July 15, 2010 Hi all, I've been trying to write a piece of code that allows some data to be added to a table that is specified by the user but nothing seems to happen. So, for example if the user type in the value "chair" in the furniture box in the form below the rest of the data will be added to the table chair... Here's the code, it's a bit basic... The Form: <form method="post" action="process_add.php"> Furniture: <input type="text" name="furniture" /><br /> Material: <input type="text" name="material" /><br /> Price: <input type="text" name="price" /><br /> Quantity: <input type="text" name="quantity" /><br /> Color: <input type="text" name="color" /><br /> Width: <input type="text" name="width" /><br /> Height: £<input type="text" name="height" /><br /> <input type="submit" name="submit" value="Submit" /> <input type="reset" value="Cancel" /> </form> and the php file <?php if($_POST['submit']) { $furniture = $_POST['furniture']; $material = $_POST['material']; $price = $_POST['price']; $color = $_POST['quantity']; $width = $_POST['width']; $height = $_POST['height']; $connection = mysql_connect("localhost", "user", "pass"); $db = "products"; if(!$furniture || !$material || !$price || $color || $width || $height) { echo "Please fill out all the details"; } else { mysql_query("INSERT INTO '".$furniture."' (material, price, color, width, height) VALUES ('".$material."','".$price."','".$color."','".$width."','".$height."'"); echo "The data you have filled in has been added to the table"; } } ?> Any help would be appreciated. Thanks. Link to comment https://forums.phpfreaks.com/topic/207872-using-user-input-to-select-a-table-from-a-database/ Share on other sites More sharing options...
AMcHarg Posted July 15, 2010 Share Posted July 15, 2010 mysql_select_db($db); Link to comment https://forums.phpfreaks.com/topic/207872-using-user-input-to-select-a-table-from-a-database/#findComment-1086741 Share on other sites More sharing options...
stow19 Posted July 16, 2010 Author Share Posted July 16, 2010 @AMcHarg Thanks for that, can't believe I forgot to put it in but... I forgot another piece of code :-\... ok here we go... I'm trying to do a check to see if the furniture has the same type of material so I used this piece of code: $mCheck = "SELECT material FROM ".$furniture." WHERE material = '".$material."'"; $mGet = mysql_query($nCheck) or die(mysql_error()); if($material == $mGet) { echo "Please enter a different material"; } From this peice of code I don't get any reply when I tested it. Sorry about the poor mistake before Link to comment https://forums.phpfreaks.com/topic/207872-using-user-input-to-select-a-table-from-a-database/#findComment-1086970 Share on other sites More sharing options...
AMcHarg Posted July 16, 2010 Share Posted July 16, 2010 You made a typo: mysql_query($nCheck) should be mysql_query($mCheck), see below: $mCheck = "SELECT material FROM ".$furniture." WHERE material = '".$material."'"; $mGet = mysql_query($mCheck) or die(mysql_error()); if($material == $mGet) { echo "Please enter a different material"; } Link to comment https://forums.phpfreaks.com/topic/207872-using-user-input-to-select-a-table-from-a-database/#findComment-1086972 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.