regular expression stopping mysql data save

Hi,

I have just added javascript to a form to check an email address is valid, since adding this no data is saved to the mySQL database, I am not given an error messages when I click submit.
I have tried using //echo $insert."<br>"; exit; to see what is the insert and this looks ok.
<?php  
// Connects to your Database    
mysql_connect("localhost", "***", "***") or die(mysql_error());    
mysql_select_db("portal") or die(mysql_error());   
 
//Checks if there is a login cookie    
if(isset($_COOKIE['ID_my_site']))   
{   
        //if already coockie logs in and directes you to the members page     
        $username = $_COOKIE['ID_my_site'];     
        $pass = $_COOKIE['Key_my_site'];    
        $user_level = $_COOKIE['user_level'];    
        $check = mysql_query("SELECT * FROM users WHERE username = '$username' && password = '$pass' && user_level = '$user_level'")or die(mysql_error());   
        $numrows = mysql_num_rows($check);    
        if ($numrows != 1) 
		{   
            header("Location: index.php");   
        }   
}   
?>     
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml">   
<head>   
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
<title>fanbase portal</title>   
<link href="css/layout.css" rel="stylesheet" type="text/css" /> 
<script type= "text/javascript" src = "includes/countries2.js"></script>
<script type="text/javascript" src="datepickercontrol.js"></script>
<link type="text/css" rel="stylesheet" href="datepickercontrol.css" />  

<script type="text/javascript">

/***********************************************
* Email Validation script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval
}

</script>

</head>  
<body class="twoColFixLtHdr">   
<div id="container">   
<div id="header">   
      
<p>  
			<?php include ('includes/header.php'); ?>
</div>   
<div id="sidebar1">
	<p>
			<?php include ('includes/sidebar1.php'); ?>
    </p>
		<p>&nbsp;</p>
        <p>&nbsp;</p>
</p>   
                <!-- end #sidebar1 -->  
</div>   
<div id="mainContent">   
<?php	

		//code runs if the form has been submitted
		if (isset($_POST['submit'])) 
		{ 

		//makes sure no blank fields 
		if (!$_POST['first_name'] | !$_POST['last_name'] | !$_POST['BusinessCompanyName'] | !$_POST['subscribe_jobtitle'] | !$_POST['subscribe_address1'] ) 
		{
		die('You did not complete all of the required fields');
		
		}
		
		//insert into the database
		$insert = "INSERT INTO subscribe (first_name, last_name, subscribe_email, BusinessCompanyName, subscribe_jobtitle, subscribe_address1, subscribe_address2, subscribe_town, country, subscribe_postcode, state, subscribe_land_number, subscribe_mobile_number, subscribe_birthday, subscribe_anniversary, subscribe_hotel_glasgow, subscribe_hotel_edinburgh, subscribe_kmu_accommodation, subscribe_kmu_meetings, subscribe_kmu_pdining, subscribe_kmu_grill, subscribe_from_kmu, subscribe_from_business_card, subscribe_from_comment_card, profile_corp, profile_leisure, profile_ta, entered_by)
		VALUES ('".$_POST['first_name']."', '".$_POST['last_name']."', '".$_POST['subscribe_email']."', '".$_POST['BusinessCompanyName']."', '".$_POST['subscribe_jobtitle']."', '".$_POST['subscribe_address1']."', '".$_POST['subscribe_address2']."', '".$_POST['subscribe_town']."', '".$_POST['country']."', '".$_POST['subscribe_postcode']."', '".$_POST['state']."', '".$_POST['subscribe_land_number']."', '".$_POST['subscribe_mobile_number']."', '".$_POST['subscribe_birthday']."', '".$_POST['subscribe_anniversary']."', '".$_POST['subscribe_hotel_glasgow']."', '".$_POST['subscribe_hotel_edinburgh']."', '".$_POST['subscribe_kmu_accommodation']."', '".$_POST['subscribe_kmu_meetings']."', '".$_POST['subscribe_kmu_pdining']."', '".$_POST['subscribe_kmu_grill']."', '".$_POST['subscribe_from_kmu']."', '".$_POST['subscribe_from_business_card']."', '".$_POST['subscribe_from_comment_card']."', '".$_POST['profile_corp']."', '".$_POST['profile_leisure']."', '".$_POST['profile_ta']."', '".$_COOKIE['user_level']."')";
		//echo $insert."<br>"; exit; 
		$add_member = mysql_query($insert);
		
?>


		<h1>Registered</h1>
		<p>Thank you, contact details saved</a>.</p>       
<?php 
		} 
		else 
		{ 
?>

        <h1>Register Guest On Fanbase</h1>
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <ul class="register_form">
        <li>First Name:<br /><input type="text" name="first_name" id="first_name" /></li>
        <li>Last Name:<br /><input type="text" name="last_name" id="last_name" /></li>
 		<li>Email:<br /><input type="text" name="subscribe_email" id="subscribe_email" /></li>


        <li>Business / Company Name:<br /><input type="text" name="BusinessCompanyName" id="BusinessCompanyName" /></li>
        <li>Job Title:<br /><input type="text" name="subscribe_jobtitle" id="subscribe_jobtitle" /></li>
        <li>Address Line 1:<br /><input type="text" name="subscribe_address1" id="subscribe_address1" /></li>
        <li>Address Line 2:<br /><input type="text" name="subscribe_address2" id="subscribe_address2" /></li>
        <li>Town:<br /><input type="text" name="subscribe_town" id="subscribe_town" /></li>
        <li>County:</li>
        <select onchange="print_state('state',this.selectedIndex);" id="country" name ="country">
        </select>  
   	    <li>Postcode:<br /><input type="text" name="subscribe_postcode" id="subscribe_postcode" /></li>
		<li>Country:</li>  
		<select name ="state" id ="state"></select>  
		<script language="javascript">print_country("country");</script>
		</li>
        <li>Phone Number:<br /><input type="text" name="subscribe_land_number" id="subscribe_land_number" />
        </li>
        <li>Mobile Phone Number:<br /><input type="text" name="subscribe_mobile_number" id="subscribe_mobile_number" /></li>
        <li>Birthday:<br /><input type="text" name="subscribe_birthday" id="DPC_date11" /></li>
        <li>Wedding Date:<br /><input type="text" name="subscribe_anniversary" id="DPC_" /></li>  
        </li>
        </li>
  	      <input type="checkbox" name="subscribe_hotel_glasgow"  id="subscribe_hotel_glasgow" value="yes" checked="CHECKED" />Dakota Glasgow
          <input type="checkbox" name="subscribe_hotel_edinburgh" id="subscribe_hotel_edinburgh" value="yes" checked="checked" /> Dakota Edinburgh         
         </li>
         </li>
         <p>Keep Me Updated About:<br />
			<input name="subscribe_kmu_accommodation" type="checkbox"  id="subscribe_kmu_accommodation" value="yes" checked="checked" />Accommodation
			<input name="subscribe_kmu_meetings" type="checkbox" id="subscribe_kmu_meetings" value="yes" checked="checked" />Meetings And Events
    		<input name="subscribe_kmu_pdining" type="checkbox" id="subscribe_kmu_pdining" value="yes" checked="checked" />Private Dining           
            <input name="subscribe_kmu_grill" type="checkbox" id="subscribe_kmu_grill" value="yes" checked="checked" />Grill
         </p>
         <p>Details Acquired From:<br />
            <input type="checkbox" name="subscribe_from_kmu" id="subscribe_from_kmu" value="yes" />Keep me updated card
			<input type="checkbox" name="subscribe_from_business_card" id="business_card" value="yes" />Business card
			<input type="checkbox" name="subscribe_from_comment_card" id="comment_card" value="yes" />Comment Card <br />
         <p>Profile:<br />
            <input type="checkbox" name="profile_corp" id="profile_corp" value="yes" />Corp
            <input type="checkbox" name="profile_leisure" id="profile_leisure" value="yes" />Leisure
			<input type="checkbox" name="profile_ta" id="profile_ta" value="yes" />Travel Agent<br />
         </li>                                
            <input name="submit" onClick="return checkmail(this.form.subscribe_email)" type="submit" class="inputbox2_button" id="subscribe" value="Save Guest Details" />
            
         </ul><!-- end #mainContent -->
         </form>
         
         <?php
}
?> 
</div>   
    <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->  
        <br class="clearfloat" />   
        
<div id="footer">   
        <p>   
        <?php include ('includes/footer.php'); ?>                    
        </p>   
</div> 
<!-- end #container -->  
</div>  
</body>   
</html>

Open in new window

AlexAmblerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

04it040Commented:
Modify following line to get mysql error if any..


This will give you a fair idea about the problem.
$add_member = mysql_query($insert) or die(mysql_error());

Open in new window

0
jet-blackCommented:
Use
array_map($_POST, 'mysql_real_escape_string');
before the $insert variable.

array_map($_POST, 'mysql_real_escape_string');            $insert = "INSERT INTO subscribe (first_name, last_name, subscribe_email, BusinessCompanyName, subscribe_jobtitle, subscribe_address1, subscribe_address2, subscribe_town, country, subscribe_postcode, state, subscribe_land_number, subscribe_mobile_number, subscribe_birthday, subscribe_anniversary, subscribe_hotel_glasgow, subscribe_hotel_edinburgh, subscribe_kmu_accommodation, subscribe_kmu_meetings, subscribe_kmu_pdining, subscribe_kmu_grill, subscribe_from_kmu, subscribe_from_business_card, subscribe_from_comment_card, profile_corp, profile_leisure, profile_ta, entered_by)
            VALUES ('".$_POST['first_name']."', '".$_POST['last_name']."', '".$_POST['subscribe_email']."', '".$_POST['BusinessCompanyName']."', '".$_POST['subscribe_jobtitle']."', '".$_POST['subscribe_address1']."', '".$_POST['subscribe_address2']."', '".$_POST['subscribe_town']."', '".$_POST['country']."', '".$_POST['subscribe_postcode']."', '".$_POST['state']."', '".$_POST['subscribe_land_number']."', '".$_POST['subscribe_mobile_number']."', '".$_POST['subscribe_birthday']."', '".$_POST['subscribe_anniversary']."', '".$_POST['subscribe_hotel_glasgow']."', '".$_POST['subscribe_hotel_edinburgh']."', '".$_POST['subscribe_kmu_accommodation']."', '".$_POST['subscribe_kmu_meetings']."', '".$_POST['subscribe_kmu_pdining']."', '".$_POST['subscribe_kmu_grill']."', '".$_POST['subscribe_from_kmu']."', '".$_POST['subscribe_from_business_card']."', '".$_POST['subscribe_from_comment_card']."', '".$_POST['profile_corp']."', '".$_POST['profile_leisure']."', '".$_POST['profile_ta']."', '".$_COOKIE['user_level']."')";
            
//echo $insert."<br>"; exit;
            $add_member = mysql_query($insert);

0
AlexAmblerAuthor Commented:
hi,

no error message, just displays
Registered
Thank you, contact details saved.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

AlexAmblerAuthor Commented:
Hi,
array has worked, now saving to db but also error

Warning: array_map() [function.array-map]: The first argument, 'Array', should be either NULL or a valid callback in C:\inetpub\httpdocs\portal\subscribe.php on line 85
0
jet-blackCommented:
sorry it should be:
$_POST = array_map('mysql_real_escape_string',  $_POST);  



array_map($_POST,  'mysql_real_escape_string');
            $insert  = "INSERT INTO subscribe (first_name, last_name, subscribe_email,  BusinessCompanyName, subscribe_jobtitle, subscribe_address1,  subscribe_address2, subscribe_town, country, subscribe_postcode, state,  subscribe_land_number, subscribe_mobile_number, subscribe_birthday,  subscribe_anniversary, subscribe_hotel_glasgow,  subscribe_hotel_edinburgh, subscribe_kmu_accommodation,  subscribe_kmu_meetings, subscribe_kmu_pdining, subscribe_kmu_grill,  subscribe_from_kmu, subscribe_from_business_card,  subscribe_from_comment_card, profile_corp, profile_leisure,  profile_ta, entered_by)
            VALUES ('".$_POST['first_name']."',  '".$_POST['last_name']."', '".$_POST['subscribe_email']."',  '".$_POST['BusinessCompanyName']."',  '".$_POST['subscribe_jobtitle']."', '".$_POST['subscribe_address1']."',  '".$_POST['subscribe_address2']."', '".$_POST['subscribe_town']."',  '".$_POST['country']."', '".$_POST['subscribe_postcode']."',  '".$_POST['state']."', '".$_POST['subscribe_land_number']."',  '".$_POST['subscribe_mobile_number']."',  '".$_POST['subscribe_birthday']."', '".$_POST['subscribe_anniversary']."',  '".$_POST['subscribe_hotel_glasgow']."',  '".$_POST['subscribe_hotel_edinburgh']."',  '".$_POST['subscribe_kmu_accommodation']."',  '".$_POST['subscribe_kmu_meetings']."',  '".$_POST['subscribe_kmu_pdining']."',  '".$_POST['subscribe_kmu_grill']."',  '".$_POST['subscribe_from_kmu']."', '".$_POST['subscribe_from_business_card']."',  '".$_POST['subscribe_from_comment_card']."',  '".$_POST['profile_corp']."', '".$_POST['profile_leisure']."',  '".$_POST['profile_ta']."', '".$_COOKIE['user_level']."')";
            //echo $insert."<br>"; exit;
           $add_member =  mysql_query($insert);
0
jet-blackCommented:
$_POST = array_map('mysql_real_escape_string',  $_POST);  

            $insert  =  "INSERT INTO subscribe (first_name, last_name, subscribe_email,   BusinessCompanyName, subscribe_jobtitle, subscribe_address1,   subscribe_address2, subscribe_town, country, subscribe_postcode, state,   subscribe_land_number, subscribe_mobile_number, subscribe_birthday,   subscribe_anniversary, subscribe_hotel_glasgow,   subscribe_hotel_edinburgh, subscribe_kmu_accommodation,   subscribe_kmu_meetings, subscribe_kmu_pdining, subscribe_kmu_grill,   subscribe_from_kmu, subscribe_from_business_card,   subscribe_from_comment_card, profile_corp, profile_leisure,   profile_ta, entered_by)
            VALUES  ('".$_POST['first_name']."',  '".$_POST['last_name']."',  '".$_POST['subscribe_email']."',  '".$_POST['BusinessCompanyName']."',   '".$_POST['subscribe_jobtitle']."', '".$_POST['subscribe_address1']."',   '".$_POST['subscribe_address2']."', '".$_POST['subscribe_town']."',   '".$_POST['country']."', '".$_POST['subscribe_postcode']."',   '".$_POST['state']."', '".$_POST['subscribe_land_number']."',   '".$_POST['subscribe_mobile_number']."',   '".$_POST['subscribe_birthday']."', '".$_POST['subscribe_anniversary']."',   '".$_POST['subscribe_hotel_glasgow']."',   '".$_POST['subscribe_hotel_edinburgh']."',   '".$_POST['subscribe_kmu_accommodation']."',   '".$_POST['subscribe_kmu_meetings']."',   '".$_POST['subscribe_kmu_pdining']."',   '".$_POST['subscribe_kmu_grill']."',   '".$_POST['subscribe_from_kmu']."', '".$_POST['subscribe_from_business_card']."',   '".$_POST['subscribe_from_comment_card']."',   '".$_POST['profile_corp']."', '".$_POST['profile_leisure']."',   '".$_POST['profile_ta']."', '".$_COOKIE['user_level']."')";
             //echo $insert."<br>"; exit;
           $add_member =   mysql_query($insert);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
04it040Commented:
have you changed this line :-

"$add_member =  mysql_query($insert);"

to

"$add_member = mysql_query($insert) or die(mysql_error());"
0
AlexAmblerAuthor Commented:
thank you.
0
jet-blackCommented:
Thanks for he points.
You're welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.