Jump to content

simple "else" statement


wkilc

Recommended Posts

Hello,

 

I'm pulling data from a table in order to pre-populate a form.  I have either a "school" address or a "home "addresses" for each record in the table.  I've already connected to the table and made the query... what I need to do now is simply create an "else" statement.  If the value "Address_type" is "school", pre-populate the form... if it's not "school" then display an empty form:

 

I think I've got the idea, but my syntax can't be right:

 

<?php 
if ($Address_type = 'school') 
{ 
?>

School address street</b>:
<input type="text" name="Address_street" value="<?php echo stripslashes($row['school_address']); ?>" />

School address city</b>:
<input type="text" name="Address_city" value="<?php echo stripslashes($row['school_city']); ?>" />

School address state</b>:
<input type="text" name="Address_state" value="<?php echo stripslashes($row['school_state']); ?>" />

School address zipcode</b>:
<input type="text" name="Address_zip" value="<?php echo stripslashes($row['school_zip']); ?>" />

<?php
}else {
?>

School address street</b>:
<input type="text" name="Address_street" />

School address city</b>:
<input type="text" name="Address_city" />

School address state</b>:
<input type="text" name="Address_state" />

School address zipcode</b>:
<input type="text" name="Address_zip" />

<?php
}
?>

Link to comment
https://forums.phpfreaks.com/topic/220298-simple-else-statement/
Share on other sites

So what seems to be the problem? Is it not working?

 

Also, is there a reason you're using stripslashes() to display data retrieved from a database? It shouldn't be necessary unless the data isn't being inserted properly.

Archived

This topic is now archived and is closed to further replies.

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