-2

I have a table (venue) that produces a list of venues from from mysql db. I would like a that can select the venue name and insert it into another table: booking. I have a hidden input field that contains the venue name and a button for booking.

Here is my form:

<td><form action="bookvenues.php" method="post">
     <?php echo "<input type='text' name='booking' value='".$venue['venuename']."' hidden/><button type='submit' class='btn btn-default'>Book this Venue</button>"?>
            </form></td>;

Here is my PHP script:

<?php
mysql_connect("host","user","password") or die(mysql_error()); 
mysql_select_db("db") or die(mysql_error()); 
?>
<?php 
    $venuename = $_POST['booking'];

$result= "INSERT INTO booking (venuename) VALUES  ('".$_POST['venuename']."')";
$add_venue = mysql_query($result);

   echo "Venue Booked!"; 

?>

When I click the book button it echos venue booked and when I check my db a new row has been added but the venuename is empty. Any suggestions?

Thanks :)

sd0093
  • 13
  • 7
  • 1
    is this a live site? you realize you're open to an sql injection. Btw; you've syntax errors – Funk Forty Niner Mar 26 '17 at 14:45
  • Thank you. It isn't live - purely for learning purposes. – sd0093 Mar 26 '17 at 14:49
  • I am trying to learn. It may seem like a duplicate to you but for beginners it can be very confusing! – sd0093 Mar 26 '17 at 14:52
  • Debugging is part of learning and "of the fun" too ;-) Learning and coding correctly takes time and we don't expect people to have success right away. I never learned the alphabet in its entirety the first time around when I was shown all the letters ;-) – Funk Forty Niner Mar 26 '17 at 15:02
  • I totally agree with you. That is why I tried it out myself first, provided my code and asked for assistance. Isn't that what this website is for? Learning? And shouldn't you, as somebody who seems quite experienced be open to new programmers and IT enthusiasts and try to encourage them and pass on your knowledge rather than discourage them? And to be honest, I don't think you can really compare learning the alphabet to programming..... – sd0093 Apr 01 '17 at 16:40

2 Answers2

-1

of course you miss the names. there is a change in line 8.

<?php
mysql_connect("host","user","password") or die(mysql_error()); 
mysql_select_db("db") or die(mysql_error()); 
?>
<?php 
    $venuename = $_POST['booking'];

$result= "INSERT INTO booking (venuename) VALUES  ('".$venuename."')";
$add_venue = mysql_query($result);

   echo "Venue Booked!"; 

?>
morteza kavakebi
  • 1,640
  • 3
  • 18
  • 39
-1

You are getting a $_POST variable that does not exist, change you insert statement by this:

$result= "INSERT INTO booking (venuename) VALUES  ('".$venuename."')";
gmc
  • 3,910
  • 2
  • 31
  • 44