Even after reading up on it I'm not sure how to use if(isset(... for what I'm I'm trying to do. Can someone point me in the right direction please before I pull my hair out?

My code

if(isset($_POST['email1'])){
mysql_query("INSERT INTO rating_invite SET 
		user_id='$_SESSION[user_id]',
		email='$em1'");}

if(isset($_POST['email2'])){
mysql_query("INSERT INTO rating_invite SET 
		user_id='$_SESSION[user_id]',
		email='$em2'");}

Just need a quick pointer as to where I'm going wrong.

Perhaps I should elaborate a bit more. Even though the fields I am posting from - email1, email2, etc. - are blank, the queries still execute and insert a blank record into the table. If the fields are not filled out I would like to skip the INSERT queries. I've tried lots of variations of if, else, ifelse .. all with mixed results. I think it comes down to me not understanding it well enough, although I'm trying to.

My code

if(isset($_POST['email1'])){
mysql_query("INSERT INTO rating_invite SET 
		user_id='$_SESSION[user_id]',
		email='$em1'");}

if(isset($_POST['email2'])){
mysql_query("INSERT INTO rating_invite SET 
		user_id='$_SESSION[user_id]',
		email='$em2'");}

Just need a quick pointer as to where I'm going wrong.

Thanks anyhow, I got it.

if(isset($_POST['email1'])){
$em1 = $_POST['email1'];}

if(isset($_POST['email2'])){
$em2 = $_POST['email2'];}

if($em1){
mysql_query("INSERT INTO rating_invite SET 
		user_id='$_SESSION[user_id]',
		email='$em1'");}

if($em2){
mysql_query("INSERT INTO rating_invite SET 
		user_id='$_SESSION[user_id]',
		email='$em2'");}

you can also use if(isset($_POST[thenameofthesubmitbutton])){then post all the variables in the form at once like
$var = mysql_real_escape_string($_POST[var]);
$var2 = mysql_real_escape_string($_POST[var2]);
$var3 = mysql_real_escape_string($_POST[var3]);
then insert stements}
just saying htats how ive been using it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.