Jump to content

field in MYSQL is NULL??


jalen

Recommended Posts

I put that code you gave and it doesn't work.

 

it is a name field that is created when created the table, but nothing is input (therefor NULL) to it when someone clicks on the submit button.  Then I have another PHP files that is link with this first file, that is using the same table, but in this file it has the name field and is inserted when someone click the submitted button. 

 

now How do I use a if statement if the name field is null do this otherwise do that?

Link to comment
Share on other sites


<?php
$null = null;

if($null == null){
  echo "Yes, it is equivilent to null\n";
}

if($null === null){
  echo "Yes, it is null\n";
}

if(isset($null)){
  echo "Yes, it is set\n";
}

if(empty($null)){
  echo "Yes, it is empty\n";
}

?>


Link to comment
Share on other sites

yea is a long story.

 

OK I have two php file both created the same table with the same field.  one of the php file never insert the name field (for my purpose) when the submitted button is press there fore created a null field in mysql table.  the other insert the name field so no null, etc.  the purpose is when someone click submit with one php file, it creates a null field and when using the other it doesn't.  So I wanted to distinguish with an if statement if is null do this else do that.  I want to be able to do this within a while loop, which I already have the while loop set up:

 

<input type="text" name="name" size="35">   

 

	while($info1 = mysql_fetch_array($comments_data))
	{


                           if($name = "") 
						echo "Value is Null";

	}

Link to comment
Share on other sites

Or, done in a mysql query:

SELECT IF(`field` IS NULL, 'Default Null Value', `field`) as `field` FROM `table`

 

Would print the following:

bob

joe

Default Null Value

phil

 

 

EDIT: I just realized for inserting data, not extracting it ;)

 

To insert with the if, check on PHP side ;)

 

Link to comment
Share on other sites

I only got one part so far, the other part isn't printing out the name of whoever enter the name in the name field when press submit.

 

while($info1 = mysql_fetch_array($comments_data))
	{
		print"
		<table border=1 width=100%><td> 
		<i>subject: </i><b> $info1[subject]</b><br>

			<font size=2 color=black>$info1[id].  $info1[COMMENTS] </font><br>

		<font size=2 color=gray> Posted by </font><font color=red><b><i>";

                          

if (empty($name)){ 
	echo 'Value is null';
	}else{  
		echo "$info1[name]";
	} 


		  print "</i></b></font><font size=2 color=gray> on $info1[date]  </font>

		</td></table>"; 

   


	}

Link to comment
Share on other sites

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.