George Botley Posted July 24, 2009 Share Posted July 24, 2009 I must once again ask for the PHP Freak communites help, Here is the code: <? //Variable Setup $name = $_POST["name"]; $dayphone = $_POST["dayphone"]; $evephone = $_POST["evephone"]; $mobphone = $_POST["mobphone"]; $email = $_POST["email"]; $q5 = $_POST["q5"]; $assignment = $_POST["q5a"]; $q5b = $_POST["q5b"]; $q6 = $_POST["q6"]; $q5c = "$q5b $q5"; $q5d = "Enquiry about $q5"; //Script Execute echo "<h2 class='greenh2'>Message Sent</h2> $name,<br/><br /> Your message has been sent to the relevant person within the club. Please bare in mind that our managers run teams as well as there jobs. As a result there may be a long delay before you recieve a response. <br /><br /> Kindest Regards,<br/> Pen Mill FC"; //Check for Relevant Person $query = "SELECT * FROM team_members WHERE assignment='$assignment'"; $qry = mysql_query($query) or die ("Could not match data because ".mysql_error()); while($row = mysql_fetch_array($qry)) { $to_contact = $row['name']; $to_email = $row['email']; $to_subject = "$q5d"; $to_message = "$q6"; $today = date("Y-m-d"); $time = date("g:i a"); } echo "$to_contact"; //Send Message To Relevant Person //$con = mysql_connect("mysql.interdns.co.uk","penmillfc","derrick2009"); //if (!$con) // { // die('Could not connect: ' . mysql_error()); // } // //mysql_select_db("penmillfc", $con); // //$sql="INSERT INTO team_messages (to, from, from_email, subject, message, date, time) //VALUES ('$to_contact','$_POST[name]','$_POST[email]', '$to_subject', '$to_message', '$today', '$time')"; // //if (!mysql_query($sql,$con)) // { // die('Error: ' . mysql_error()); // } //echo "1 record added"; ?> Ignore the commented out section but when I run this script and try to extract the person from the database it doesn't extract them with the variable in the WHERE assignment='$assignment' section. It will however extract a person when I manually write their assignment for example WHERE assignment='Payment' . My variables are present and correct which was proven after echoing them onto the page. Thanks George Quote Link to comment https://forums.phpfreaks.com/topic/167259-solved-select-from-failure/ Share on other sites More sharing options...
ignace Posted July 24, 2009 Share Posted July 24, 2009 WHERE assignment LIKE '%$assignment%' Quote Link to comment https://forums.phpfreaks.com/topic/167259-solved-select-from-failure/#findComment-881877 Share on other sites More sharing options...
rhodesa Posted July 24, 2009 Share Posted July 24, 2009 What happens when you echo out the $query: $query = "SELECT * FROM team_members WHERE assignment='$assignment'"; echo $query; what is the output? Quote Link to comment https://forums.phpfreaks.com/topic/167259-solved-select-from-failure/#findComment-881879 Share on other sites More sharing options...
George Botley Posted July 24, 2009 Author Share Posted July 24, 2009 @ignace Thanks but that didn't seem to work... @rhodesa The output is SELECT * FROM team_members WHERE assignment='%Pen Mill U14s%' The % follows the suggestion of ignace. Quote Link to comment https://forums.phpfreaks.com/topic/167259-solved-select-from-failure/#findComment-881882 Share on other sites More sharing options...
George Botley Posted July 24, 2009 Author Share Posted July 24, 2009 Hmmm. I may have found my own solution to this quesiton.... It is outputting the team not the assignment, something wrong with my variables me thinks. I will update you shortly. Quote Link to comment https://forums.phpfreaks.com/topic/167259-solved-select-from-failure/#findComment-881883 Share on other sites More sharing options...
George Botley Posted July 24, 2009 Author Share Posted July 24, 2009 I have sorted the intial fault but now when adding a AND to the equation it spits out Could not match data because You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Pen Mill U14s' at line 1 The new query is $query = "SELECT * FROM team_members WHERE assignment='$assignment' AND team = '$team"; Quote Link to comment https://forums.phpfreaks.com/topic/167259-solved-select-from-failure/#findComment-881884 Share on other sites More sharing options...
rhodesa Posted July 24, 2009 Share Posted July 24, 2009 I would check your html form and make sure your input names are assigned correctly. also, at the top of this script, you can put a print_r($_POST); and make sure all key/values are what you expect Quote Link to comment https://forums.phpfreaks.com/topic/167259-solved-select-from-failure/#findComment-881894 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.