actually, his syntax IS correct and it will parse properly!
just try it
the syntax "$array[assoc]" will work only if you had one dimension array
if you had $array['assoc']['level2'] running "$array[assoc][level2]" will give parse error.. so the solution is "{$array['assoc']['level2']}" or of course concatenation..
this is actually the only way to parse arrays, even with one dimension, if you use the heredoc style! no other way will work.
// here you insert it!
$result = mysql_query($sql) or print(mysql_error());
// This will return at least one row!
$emailcheck = "SELECT * FROM questionaire WHERE email='{$_POST['email']}'";
$checkemailexists = mysql_query($emailcheck);
Does your code always fail?
__________________ onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Hmm... never new of this Thanks for the hint, but I think it's safer to keep to the concatenation. Highlighting editors are of a great help then. Don't you think?
__________________ onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
i have tried what was said and still the answer is the same. what i had before works on my own site. http://www.dcobbinah.co.uk if you look at the email subscription you will be able to enter a unique email address. when you try and enter it again you will see that you cannot enter it because its in the database already. but now i try and do the same thing and now it is not working. not sure what to do
as you will see here the code clearly shows the SELECT QUERY first before the insert into database but still no joy. actually what happens is that the validation to check if anything is entered into the field is present. the validation to check if the email is in a correct format is there. both of these work. but the validation to check if the email address already exists doesnt work at all. yet all 3 validation scripts are before the inser script. this is my problem
PHP Code:
$connection = mysql_connect($host,$user,$password) or die ("could not connect to server");
$db = mysql_select_db($database,$connection);
$emailcheck = "SELECT * FROM questionaire WHERE email='$email'";
$checkemailexists = mysql_query($emailcheck);
if(mysql_num_rows($checkemailexists) == 1) { //Check if the database found any matching emails
echo "<table border=5 bordercolor=006633 bgcolor=#EDF0EC width=750 cellpadding=4 cellspacing=0 align=center>";
echo "<tr><td>";
echo "<img src = 'images/topimage.jpg'";
echo "</td></tr>";
echo "<tr><td>";
echo "<span class='textstylesbold'>";
echo "<br>Email Address is already there.";
echo "</span>";
echo "<form>";
echo "<input type='button' value='Go Back' onclick='history.back(-1)' class='newColor2'>";
echo "</form>";
echo "</td></tr></table>";
exit;
}else{
if (empty($_POST['email'])) //validation to check if the email field has been filled in
{
echo "<table border=5 bordercolor=006633 bgcolor=#EDF0EC width=750 cellpadding=4 cellspacing=0 align=center>";
echo "<tr><td>";
echo "<img src = 'images/topimage.jpg'";
echo "</td></tr>";
echo "<tr><td>";
echo "<span class='textstylesbold'>";
echo "<br>You may have forgotten to enter your email address, please do so now.";
echo "</span>";
echo "<form>";
echo "<input type='button' value='Go Back' onclick='history.back(-1)' class='newColor2'>";
echo "</form>";
echo "</td></tr></table>";
exit;
}
if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $_POST['email'])) //validation to check the format of an email address
{
echo "<table border=5 bordercolor=006633 bgcolor=#EDF0EC width=750 cellpadding=4 cellspacing=0 align=center>";
echo "<tr><td>";
echo "<img src = 'images/topimage.jpg'";
echo "</td></tr>";
echo "<tr><td>";
echo "<span class='textstylesbold'>";
echo "<br>Please enter a valid e-mail address.";
echo "</span>";
echo "<form>";
echo "<input type='button' value='Go Back' onclick='history.back(-1)' class='newColor2'>";
echo "</form>";
echo "</td></tr></table>";
exit;
}
}
$sql = "insert into questionaire (name, email, communicate_email, spelling_mistakes, nondictionary_words, openclose_emails, respond_email, emphasise_words, smart_emails, multiple_emails, file_emails, struggletosend, copy_email, printdocsfromemails, savedocsfromemails, changedocsfromemails, sendarequest, resendchangedemails, deleteoldemails, emailtoprinter) values ('{$_POST['name']}','{$_POST['email']}','{$_POST['communicate_email']}','{$_POST['spelling_mistakes']}','{$_POST['nondictionary_words']}','{$_POST['openclose_emails']}','{$_POST['respond_email']}','{$_POST['emphasise_words']}','{$_POST['smart_emails']}','{$_POST['multiple_emails']}','{$_POST['file_emails']}','{$_POST['struggletosend']}','{$_POST['copy_email']}','{$_POST['printdocsfromemails']}','{$_POST['savedocsfromemails']}','{$_POST['changedocsfromemails']}','{$_POST['sendarequest']}','{$_POST['resendchangedemails']}','{$_POST['deleteoldemails']}','{$_POST['emailtoprinter']}')";
$result = mysql_query($sql) or print(mysql_error());