Jump to content

Ignoring blank entries from going into a MySQL database using PHP question


Recommended Posts

As it stands, it seems the only way to handle this problem is on the PHP side of things. Essentially I have several text boxes which allow for people to enter various information to be entered into a database. Once that information is entered, the next page will respond by displaying the information present which has been entered into all of the existing tables; though as a result of this, there are blank spaces returned as well, within the lists. What I have been trying to figure out is how to have the program ignore the text boxes when they are empty so that no blank spaces are returned. In short, the PHP will ignore blank entries into text boxes.  I would think this would be a simple process, but I could be very wrong, if it is simple, does anyone know what to do?

 

I am fairly new to both PHP and MySQL, only a few months in.

That shouldn't be very hard. Could you post the code you already have?

 

Just a note, the checkbox stuff is there because the next step for me would be to work on a method of selecting items and deleting them from the web page. If you could help me with the deletion system that would save me a lot of time on research; right now I am just playing around with things blindly hoping something will work.

 

Also as a note, there are going to be several other tables (that is why the whole align left stuff, etc...), I am just working with one at the moment to keep things simple. I do realize I could have a lot wrong here, so far it is functioning. MySQL tables already ignore duplicate entries.

 


mysql_connect ($localhost, $username, $password);
mysql_select_db (managementcenter);
{
mysql_query ("INSERT INTO manage(coin) VALUES 
('$coin');
");

$coin2 = mysql_query ( "select * from coin;");

echo "<table border='1' align='left'><tr>";	
	Echo "<td bgcolor=#cccccc><B>coins in stock:</b> <BR></td></tr\n>";
	while($row4 = mysql_fetch_array( $coin2 )){
	echo "<td>{$row4['coin']}";
	echo "<input type = 'checkbox' name = 'mychk[]'>";
	{
	$delete = mysql_query ("delete from away where coin = '$coin'");
	}
	echo '<br /></td>';
	echo "</tr\n>";
}
echo "</tr\n>";
}
echo	"</table>"
?>

 

{
$delete = mysql_query ("delete from away where coin = '$coin'");
}

Why do you have brackets here?

 

Additionally I don't see what text boxes you want to check to see if they are blank in any of that code.

That code for the check boxes is in the works, it's not finished.

 

 

What I am trying to figure out at the moment is what code will allow for PHP to not make an entry into MySQL if the text box is empty. For example, if the text box is empty, and I hit enter, a blank space will appear in one of the rows, I want to avoid that.

 

 

For example:

 

"text a" is written in the text box, the submit button is hit, that text is added to the database and returned to display to the user visually. Then "text b" is entered and submit is hit, so "text a" and "text b" will be in the database and both returned to the user. Then the user hits the submit button without entering any text, a blank space is then entered into the database as the third entry under "text a" and "text b" then "text c" is entered:

 

What I want to return to the user is the following:

text a

text b

text c

 

rather than:

text a

text b

 

text c

 

 

I essentially want that blank space ignored completely, not entered into the database at all.

I see, I thought you had posted code for your first problem, which would be helpful. From the information you've provided, I think this should do the trick.

 

Before you actually update or add to the database, do a simple if statement using isset().

if (isset($_POST['textboxname'])) {
   *update database*
} else {
   *Give error for null input?*
}

Thanks, I will try incorporating that. This is what I have for my code now by the way:

 

$away = $HTTP_POST_VARS['away'];
?>

<form action="testcoinbase.php" method=post>
</tr>
<tr>
<td>away</td>
<td align="Center"><input type="text" name="away" size="30" maxlength="30"></td>
</tr>
<tr>
	<td colspan="2" align=center"><input type="submit" value="Submit Order"></td>
</tr>
</table>
</form>
<? 
mysql_connect ($host, $username, $password);
mysql_select_db (coinmanagement);
{
mysql_query ("INSERT INTO away(coins) VALUES 
('$away');
");
}
  	if($_POST['perform']) { 

foreach($_POST as $row) {

mysql_query("DELETE FROM charge WHERE id='$row2' limit 1"); 
}}
$away2 = mysql_query ( "select * from away;");

echo "<table border='1' align='left'><tr>";	
	echo "<td bgcolor=#cccccc><B>coins away:</b><BR></td></tr\n>";
	while($row = mysql_fetch_array( $away2 )){
	echo "<tr>";
	echo "<td>{$row['coins']}";
	?><form name="action" id="action" method="post" action="<?=$_SERVER['PHP_SELF']?>"> 

<input type="checkbox" name="<?=$row[coins]?>" id="<?=$row[coins]?>" value="<?=$row[coins]?>" />
<?
	echo '<br /></td>';
	echo "</tr\n>";

	echo "</tr\n>";
}		?>

<input type="submit" name="perform" id="perform" value="Delete Selected" /> 	

</form>

 

I know it may look like a mess, but I really am a newbie to this. And my checkbox delete system doesn't work...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.