englishcodemonkey Posted June 24, 2008 Share Posted June 24, 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. Is there a " instead of a ' somewhere? I feel like it is going to be something simple like that? BTW the form is the drop down box on http://www.wadeandgattonnurseries.com/hosta_new.html Any ideas are welcome! Thanks Link to comment https://forums.phpfreaks.com/topic/111584-solved-help-with-syntax-and-_request-errors/ Share on other sites More sharing options...
DarkWater Posted June 24, 2008 Share Posted June 24, 2008 Yes, it's something simple like that. Change this line: $sql = 'INSERT INTO hosta VALUES (\'$hid\', \'$name\', \'$hy\', \'$size\', \'$desc\', \'$price\')'; To: $sql = "INSERT INTO hosta VALUES ('$hid', '$name', '$hy', '$size', '$desc', '$price')"; Link to comment https://forums.phpfreaks.com/topic/111584-solved-help-with-syntax-and-_request-errors/#findComment-572761 Share on other sites More sharing options...
DarkWater Posted June 24, 2008 Share Posted June 24, 2008 Oh, almost forgot to tell you why it didn't work before. PHP doesn't parse variables contained in ' '. It only parses it in " ". =) Link to comment https://forums.phpfreaks.com/topic/111584-solved-help-with-syntax-and-_request-errors/#findComment-572764 Share on other sites More sharing options...
englishcodemonkey Posted June 24, 2008 Author Share Posted June 24, 2008 thanks! problem solved! Link to comment https://forums.phpfreaks.com/topic/111584-solved-help-with-syntax-and-_request-errors/#findComment-572815 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.