mysql - Adding to database from PHP inserts NULL -
the missing _ typo on stackoverflow, testing.
i'm trying insert value database using following 2 files:
add record:
<form action="addvenue.php" method="post" /> <p>venue name: <input type="text" name="venue_name" /></p> <p>venue capacity: <input type="text" name="venue_capacity" /></p> <input type="submit" value="submit" /> </form>
addvenue.php
<?php require("dbconnection.php"); // connect database // select database $db= 'database'; mysql_select_db($db) or die("could not select database"); $venue_name = $_post['venue_name']; $venue_capacity = $_post['venue_capacity']; $sql = "insert venues (venue_name) values ('$venue_name')"; $sql = "insert venues (venue_capacity) values ('$venue_capacity')"; if (!mysql_query($sql)) { die('error: ' . mysql_error()); } mysql_close(); ?>
at moment, adds field venue_capacity without fault, adds null venue_name field. capacity field int, , name field varchar.
i have no idea why it's doing it, same pat names, have double , triple checked. have ideas?
you resetting $sql
new query without performing first.
you should combine 2 queries one:
insert venues (venue_name, venue_capacity) values ('$venue_name', '$venue_capacity');
your form needs have field named venue_name
instead of venuename
.
Comments
Post a Comment