Jump to content

[SOLVED] Help with syntax and $_REQUEST errors


Recommended Posts

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  :)

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')";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.