0

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.

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by SKANK!!!!!
0

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.

0

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'");}
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.