englishcodemonkey Posted June 21, 2008 Share Posted June 21, 2008 Ok so i have a form that contains several text fields and a drop down field. The HTML for the form is below: <form action="insert.php" method="post" > <p align="left"> Hosta ID: <input name="id" type="text" id="id" /> <-- leave blank!! </p> <p align="left">Hosta Name: <input name="name" type="text" value="" /> </p> <p align="left"> Hybridizer: <input name="hybrid" type="text" id="hybrid"/> </p> <p align="left"> Size: <select name="size" id="size"> <option value="miniature" selected="selected">Miniature</option> <option value="dwarf">Dwarf</option> <option value="small">Small</option> <option value="medium">Medium</option> <option value="large">Large</option> <option value="giant">Giant</option> </select> </p> <p align="left">Description: <textarea name="desc" cols="100" rows="4" id="desc"></textarea> </p> <p>Price: <input type="text" name="price" /> </p> <p> </p> <p> <input type="submit" name="send" /> </p> </form> And it is posting to insert.php the code is below: <?php $dbhost ='p50mysql187.secureserver.net'; $dbuser = 'hostajess'; $dbpass = '****'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die('Error connecting to mysql'); $dbname='hosta'; mysql_select_db($hosta); $name = $_POST['name']; $hy = $_POST['hybrid']; $size = $_POST['size']; $desc= $_POST['desc']; $price= $_POST['price']; echo '<h1>Size is $size</h1>'; $sql = 'INSERT INTO hosta VALUES (\'$hid\', \'$name\', \'$hy\', \'$size\', \'$desc\', \'$price\')'; $r= @mysqli_query ($dbc, $sql); if ($r) { echo '<h1>Thank You! SUCCESS!</h1>'; } else { echo '<h1>System Error</h1>'; echo '<p>You Entered, <b>$name</b> into the database</p>'; mysqli_close($dbc); exit(); } ?> I feel like I Have tried everything, the result I am getting is that the $var is being inserted into the database. For example the hosta_id will be correct (auto_increment is being used) and then the name size price and everything will show $name, $size, $price. Rather than showing the value I entered into the form. Any ideas are welcome! Thanks Quote Link to comment Share on other sites More sharing options...
webent Posted June 22, 2008 Share Posted June 22, 2008 Get rid of the \ before the ' i.e. $sql = "INSERT INTO hosta VALUES ('$hid', '$name', '$hy', '$size', '$desc', '$price')"; Quote Link to comment Share on other sites More sharing options...
englishcodemonkey Posted June 23, 2008 Author Share Posted June 23, 2008 After removing the /'s it said there was an unknown variable and so I then removed the ' aswell. Then it took the statement but entered the '$name' as text into the database rather than the value I had entered into the form??? I can't understand why it is not recognising this as a variable and is just seeing it as text?? Thanks Quote Link to comment Share on other sites More sharing options...
fenway Posted June 23, 2008 Share Posted June 23, 2008 This is a PHP issue.... Quote Link to comment Share on other sites More sharing options...
jaoudestudios Posted June 25, 2008 Share Posted June 25, 2008 You do not need to parse the php variables in the mysql query. Parsing them is slower and allows room for errors. Use... $sql = "INSERT INTO hosta VALUES (".$hid.", ".$name.", ".$hy.", ".$size.", ".$desc.", ".$price.")"; Even better be more specific in your mysql query, try... $sql = "INSERT INTO hosta SET *COL1* = '".$val1."', *COL2* = '".$val2."', ....."; where *COL1* is changed for the name of the column! Quote Link to comment Share on other sites More sharing options...
englishcodemonkey Posted June 25, 2008 Author Share Posted June 25, 2008 Thank you so much!! Quote Link to comment 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.