Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Randomly Inserting Blank MySQL Rows

Status
Not open for further replies.

parx87

MIS
Sep 25, 2008
3
US
I'm having an issue with PHP inserting what seems to be randomly blank entries into a MySQL table. I'm a n00b developer and I'm sure this is a simple issue, but just can't seem to figure it out, and searching here and Google hasn't turned up a solution. Here's the code I'm working with:

Code:
$search_name = $_POST['name'];
$enter_number = $_POST['number'];
$enter_city = $_POST['city'];
$enter_address = $_POST['address'];
		
mysql_query("INSERT INTO remote_sites (number, city, address)
			VALUES('$enter_number','$enter_city','$enter_address')")
	or die (mysql_error());
		
$result = mysql_query("SELECT * FROM remote_sites WHERE
        city = '$search_name' ORDER BY number")
        or die (mysql_error());
		
echo "<table border='8'>";
echo "<tr> <th>Number</th> <th>City</th> <th>Address</th></tr>";

while($display = mysql_fetch_array($result)) {
	echo "<tr><td>";
	echo $display['number'];
	echo "</td><td>";
	echo $display['city'];
	echo "</td><td>";
	echo $display['address'];
	echo "</td></tr>";
}

echo "</table>";

Any help would be appreciated.
 
Do you ever run this script without the form values actually being submitted? I would first check if the form values have been successfully submitted and only proceed if they were.
Code:
if (isset ($_POST['number']))
{
  ...
}
If they weren't, your variables would be filled with blanks and blanks would be inserted into the database.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Apart from that, I'd switch all error reporting ON on your development machine. Not checking post values for existence should paint a good part of your browser window red!

On production servers, you want error reporting off, apart from the fact that you log the errors yourself (don't you?), so hackers cannot get too much free inside info.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top