a2bardeals Posted November 20, 2006 Share Posted November 20, 2006 I have a few different pages on my site with a basic set up of:Page_1.php is a normal html form with the POST method and the action set to Page_2.php a couple hidden variables mostly user defined text inputs or select fields. On submit it sends data to Page_2.php which updates a MySQL database using:[code]$con = mysql_connect("localhost","root", "*******");mysql_select_db("database", $con);$sql="INSERT INTO addcampus(school, city, state, email, send) VALUES('$_POST[school]','$_POST[city]','$_POST[state]','$_POST[email]','$_POST[send]')";if (!mysql_query($sql,$con)) { die('ErrorTran: ' . mysql_error()); }[/code]the database table is also set with an ID column that auto increments and is the primary index. Often my database has been inserting one or multiple empty rows with just an ID. So basically the user data is there but where the user data row has an id of 10 the empties are 11 12 13 and so on. At one point i had a table with 1400 rows and only 20 of them actually had information in them. This is very frustrating for maintenance! Anyone have any ideas let me know. Thanks! Link to comment https://forums.phpfreaks.com/topic/27837-adding-empty-rows-on-insert/ Share on other sites More sharing options...
exploo Posted November 20, 2006 Share Posted November 20, 2006 you could always check the posts before entering it into the database..cause i guess this is what's happening, someone is just sending an empty form..use something like this for each post:[code]if(!isset($_POST["school"])) $empty = TRUE;[/code]or loop through the posts in some other way.then use:[code]if(!$empty) {$school = mysql_escape_string($_POST["school"]) // for every post//and then the sql-query with $school instead of $_POST["school"] etc.}[/code]and it should be $_POST["school"] or $_POST['school'] etc. Link to comment https://forums.phpfreaks.com/topic/27837-adding-empty-rows-on-insert/#findComment-127434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.