Jump to content

dannyp100

Members
  • Posts

    41
  • Joined

  • Last visited

Everything posted by dannyp100

  1. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'error' ; switch ($action) { case 'search': $s = new CourseService(); $st = $s->search(); echo $st; break; The search is not bringing up any results so i'm guessing its not searching properly: Thats the url i am testing the search on: http://localhost/courseservicepipe.php?action=search&searchterm=accounting comes back with 'No Results found' so confused!
  2. search function within CourseService Class public function search() { $searchterm = '%'.$_POST['searchterm'].'%'; $sql = "SELECT * FROM srs_course WHERE coursetitle LIKE :searchterm "; try { $db = dbConnection::getConnection(); $query = $db->prepare($sql); $query->bindParam(':searchterm', $searchterm, PDO::PARAM_STR); $query->execute(); if(!$query->rowCount()==0) { while($row = $query->fetch()) { echo "<tr>"; echo "<td>".$row."</td>"; } } else { echo "No results found!"; } $query->closeCursor(); } catch (Exception $ex){ echo "Something went wrong " . $ex; } } My service pipe class code: case 'search': $s = new CourseService(); $st = $s->search(); echo $st; break; I check to see if its working by the url, adding &searchterm=b, but no results present. How can i do this via a search form so it picks up what the user has inputted? http://localhost/courseservicepipe.php?action=search&searchterm=b
  3. Still doesnt seem to be working, just giving me an error saying theres an undefined index 'searchterm'. I'm not sure if my code in my service pipe is right or the form. Also its not bringing me back any search results, saying 'No results found', how can i search throughout multiple tables and return the results as just a field and not under any headings?
  4. I am having difficulty getting my search working for the page that i am doing: heres my search function within a class called CourseService public function search() { $searchterm = $_POST['searchterm']; $sql = "SELECT * FROM srs_course WHERE coursetitle LIKE '% :searchterm %' "; try { $db = dbConnection::getConnection(); $query = $db->prepare($sql); $query->bindParam(':searchterm', PDO::PARAM_STR); $query->execute(); if(!$query->rowCount()==0) { while($row = $query->fetch()) { echo "<tr>"; echo "<td>".$row['coursecode']."</td>"; echo "<td>".$row['coursetitle']."</td>";; } } else { echo "No results found!"; } $query->closeCursor(); } catch (Exception $ex){ echo "Something went wrong " . $ex; } } Then I will call the function in my servicepipeclass: case 'search': $s = new CourseService(); $st = $s->search(); echo $st; break; The finally on a php page called phptesting.php went user types something it, it should bring back search results but it doesnt: <form action="courseservicepipe.php" method="post"> Search: <input type="text" name="searchterm" /><br /> <input type="submit" name="submit" value="Submit" /> </form> I would also like help on how to change my code to search all table in the database and for keywords to anything, these are the tables: srs_student, srs_course, srs_student_module Any help would be amazing! I'm extremely confused
  5. I am having trouble with SQL statements, i just can't seem to get them right This is the strcuture of the DB SRS_STUDENT studentid varchar( latin1_swedish_ci forename varchar(60) latin1_swedish_ci surname varchar(40) latin1_swedish_ci coursecode varchar(14) latin1_swedish_ci stage smallint(6) No 0 email varchar(50) latin1_swedish_ci SRS_COURSE coursecode varchar(14) latin1_swedish_ci coursetitle varchar(100) latin1_swedish_ci deptcode char(2) latin1_swedish_ci SRS_MODULE modulecode varchar(6) latin1_swedish_ci moduletitle varchar(120) latin1_swedish_ci points int(11) level char(2) latin1_swedish_ci I am firstly trying to show students on a course , i have got: 'select forename, surname, coursetitle, from srs_student inner join srs_course where coursecode = coursecode' I am a beginner to sql, what seems to be the problem? I am also trying to do the same thing but showing students on a module, what logic would help me do this? Thankyou!!
  6. <?php include 'gradnetconn.php'; require_once ('webpage.class.php'); include 'functions.php'; session_start(); require_once ('webpage.class.php'); $page = new webpage( "GradNet", array( "test.css", "style.css" ) ); $messageTo = $_SESSION['userID']; if (!(isset($_SESSION['userID']) && $_SESSION['userID'] != '')) { $display.= "Log in to send a message" ; header ("Location: login.php"); exit(); } else { $display.= "You aree logged in, please feel free to delete a message "; } $sql="SELECT * FROM gn_messages WHERE messageTo = $messageTo AND messageDeleted = '0' ORDER BY messageDate DESC"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <?php while($rows=mysql_fetch_array($result)) { $display.="<td><form name=\"form1\" method=\"post\" action=\"deletemessagesprocess.php\"> <table width=\"400\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\"> <tr> <td> </td> <strong>Delete A Message</strong> </td> </tr> <tr> <td> <strong>Message ID</strong></td> <td> <strong>From</strong></td> <td> <strong>Subject</strong></td> <td> <strong>Messge Contents</strong></td> </tr>"; $display.="<tr><td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$rows['messageID']\"></tr></td> <td>\"$rows['messageID']\"</td> <td>\"$rows['messageFrom']\"</td> <td>\"$rows['messageSubject']\"</td> <td>\"$rows['messageBody']\"</td> </tr><tr> <td colspan=\"5\" align=\"center\"<input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\"></td> </tr></table> </form> </td> </tr> </table>"; } $page->addToBody( " <div id=\"content\"> $display </div> "); echo $page->getPage(); ?> Thats the code, the line the error is on is: $display.="<tr><td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$rows['messageID']\"></tr></td> Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
  7. $display.="<tr><td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$rows['messageID']\"></tr></td> this is the line that the error is on. is it something to do with this part value=\"$rows['messageID']\"> ?
  8. Took the escape quotes etc and there still an error on the same line <?php include 'gradnetconn.php'; require_once ('webpage.class.php'); include 'functions.php'; session_start(); require_once ('webpage.class.php'); $page = new webpage( "GradNet", array( "test.css", "style.css" ) ); $messageTo = $_SESSION['userID']; if (!(isset($_SESSION['userID']) && $_SESSION['userID'] != '')) { $display.= "Log in to send a message" ; header ("Location: login.php"); exit(); } else { $display.= "You aree logged in, please feel free to delete a message "; } $sql="SELECT * FROM gn_messages WHERE messageTo = $messageTo AND messageDeleted = '0' ORDER BY messageDate DESC"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <?php while($rows=mysql_fetch_array($result)) { $displayform.=<<<deleteform <td><form name="form1" method="post" action="deletemessagesprocess.php"> <table width="400" border="0" cellpadding="3" cellspacing="1"> <tr> <td> </td> <strong>Delete A Message</strong> </td> </tr> <tr> <td> <strong>Message ID</strong></td> <td> <strong>From</strong></td> <td> <strong>Subject</strong></td> <td> <strong>Messge Contents</strong></td> </tr> <tr><td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="$rows['messageID']"></td></tr> <td>$rows['messageID']</td> <td>$rows['messageFrom']</td> <td>$rows['messageSubject']</td> <td>$rows['messageBody']</td> </tr><tr> <td colspan="5" align="center"<input name="delete" type="submit" id="delete" value="Delete"></td> </tr></table> </form> </td> </tr> </table> deleteform; } $page->addToBody( " <div id=\"content\"> $displayform $display </div> "); echo $page->getPage(); ?> so confusing!
  9. I've done a heredoc and an error still appears <?php include 'gradnetconn.php'; require_once ('webpage.class.php'); include 'functions.php'; session_start(); require_once ('webpage.class.php'); $page = new webpage( "GradNet", array( "test.css", "style.css" ) ); $messageTo = $_SESSION['userID']; if (!(isset($_SESSION['userID']) && $_SESSION['userID'] != '')) { $display.= "Log in to send a message" ; header ("Location: login.php"); exit(); } else { $display.= "You aree logged in, please feel free to delete a message "; } $sql="SELECT * FROM gn_messages WHERE messageTo = $messageTo AND messageDeleted = '0' ORDER BY messageDate DESC"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <?php while($rows=mysql_fetch_array($result)) { $displayform =<<<deleteform <td><form name=\"form1\" method=\"post\" action=\"deletemessagesprocess.php\"> <table width=\"400\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\"> <tr> <td> </td> <strong>Delete A Message</strong> </td> </tr> <tr> <td> <strong>Message ID</strong></td> <td> <strong>From</strong></td> <td> <strong>Subject</strong></td> <td> <strong>Messge Contents</strong></td> </tr> <tr><td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$rows['messageID']\"></td></tr> <td>\"$rows['messageID']\"</td> <td>\"$rows['messageFrom']\"</td> <td>\"$rows['messageSubject']\"</td> <td>\"$rows['messageBody']\"</td> </tr><tr> <td colspan=\"5\" align=\"center\"<input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\"></td> </tr></table> </form> </td> </tr> </table> } deleteform; $page->addToBody( " <div id=\"content\"> $displayform </div> "); echo $page->getPage(); ?> Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in on line 47 on this line <tr><td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$rows['messageID']\"></td></tr>
  10. error is on this line <tr><td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$rows['messageID']\"</tr></td>
  11. The actual code works fine to display messages to be deleted. There seems to be this error that pops up: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING Its on the line that i've put in bold <?php include 'gradnetconn.php'; require_once ('webpage.class.php'); include 'functions.php'; session_start(); require_once ('webpage.class.php'); $page = new webpage( "GradNet", array( "test.css", "style.css" ) ); $messageTo = $_SESSION['userID']; if (!(isset($_SESSION['userID']) && $_SESSION['userID'] != '')) { $display.= "Log in to send a message" ; header ("Location: login.php"); exit(); } else { $display.= "You aree logged in, please feel free to delete a message "; } $sql="SELECT * FROM gn_messages WHERE messageTo = $messageTo AND messageDeleted = '0' ORDER BY messageDate DESC"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <?php while($rows=mysql_fetch_array($result)) { $display.="<td><form name=\"form1\" method=\"post\" action=\"deletemessagesprocess.php\"> <table width=\"400\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\"> <tr> <td> </td> <strong>Delete A Message</strong> </td> </tr> <tr> <td> <strong>Message ID</strong></td> <td> <strong>From</strong></td> <td> <strong>Subject</strong></td> <td> <strong>Messge Contents</strong></td> </tr> [b]<tr><td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$rows['messageID']\"</tr></td>[/b] <td>\"$rows['messageID']\"</td> <td>\"$rows['messageFrom']\"</td> <td>\"$rows['messageSubject']\"</td> <td>\"$rows['messageBody']\"</td> </tr><tr> <td colspan=\"5\" align=\"center\"<input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\"></td> </tr></table> </form> </td> </tr> </table>"; } $page->addToBody( " <div id=\"content\"> $display </div> "); echo $page->getPage(); ?> Any help would be great!
  12. Hey guys, i'm nearly there with this project. I have created a personal messaging system on my site. I am creating email notifications to be sent to the users email address when they have been sent a message I need logic on how to do this. Would the send email notification script be in the confirmation page when a message is sent? These are the tables in gn_users Field Type Collation Attributes Null Default Extra Action userID int(3) No None AUTO_INCREMENT userEmail varchar(40) latin1_swedish_ci No None userPassword varchar(64) latin1_swedish_ci No None userSalt varchar(3) latin1_swedish_ci No None userFirstName varchar(20) latin1_swedish_ci No None userSurname varchar(20) latin1_swedish_ci No None userActive char(1) latin1_swedish_ci Yes Y userType char(1) latin1_swedish_ci Yes U userLastLogin date Yes NULL userGender char(1) latin1_swedish_ci Yes NULL userDOB date Yes NULL userTown varchar(20) latin1_swedish_ci Yes NULL userHobby varchar(1000) latin1_swedish_ci Yes NULL userLinks varchar(1000) latin1_swedish_ci Yes NULL These are the tables in gn_messages Field Type Collation Attributes Null Default Extra Action messageID int(3) No None AUTO_INCREMENT messageTo int(3) No None messageFrom int(3) No None messageSubject varchar(500) latin1_swedish_ci No None messageBody varchar(9999) latin1_swedish_ci No None messageDate text latin1_swedish_ci No None messageRead enum('0','1') latin1_swedish_ci No None messageDeleted enum('0','1') latin1_swedish_ci No None sent_deleted varchar(3) latin1_swedish_ci No None any logic, solution or links welcome please!
  13. SELECT gn_messages.*, CONCAT(to_user.userFirstName, ' ', to_user.userSurname) AS to_full_name, CONCAT(from_user.userFirstName, ' ', from_user.userSurname) AS from_full_name FROM gn_messages INNER JOIN gn_users to_user ON to_user.userID = gn_messages.messageTo INNER JOIN gn_users from_user ON from_user.userID =gn_messages.messageFrom WHERE messageTo = $messageTo AND messageDeleted = '0' ORDER BY messageDate DESC This query is working now but not returning a name, still only the userID? I have return it as (return->messageFrom)
  14. This is what i get when i debugg it #1064 - 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 'FROM gn_messages INNER JOIN gn_users to_user ON to_user.user_id = gn_messages.m' at line 4
  15. SELECT gn_messages.*, CONCAT(userFirstName, ' ', userSurname) AS full_name FROM gn_messages INNER JOIN gn_users ON gn_users.user_id = gn_messages.messageTo (-- assuming you want the user's name who it is to. You'll need to do this join AGAIN to get the sender's name as well). WHERE messageTo = $messageTo AND messageDeleted = '0' ORDER BY messageDate DESC" OH right, oh yeah i understand now! Sorry, i read it all wrong! SELECT gn_messages.*, CONCAT(userFirstName, ' ', userSurname) AS full_name FROM gn_messages INNER JOIN gn_users ON gn_users.user_id = gn_messages.messageTo INNER JOIN gn_users ON gn_users.user_id =gn_messages.messageFrom WHERE messageTo = $messageTo AND messageDeleted = '0' ORDER BY messageDate DESC" So where you've put in the note in the query above (assuming.......etc) I have to do the join again like above?
  16. Would you be able to tell me why the correct user that the message is from isn't appearing. This is my inbox code: <?php include 'gradnetconn.php'; include 'functions.php'; session_start(); $messageTo = $_SESSION['userID']; $sql = mysql_query("SELECT * FROM gn_messages WHERE messageTo = $messageTo AND messageDeleted = '0' ORDER BY messageDate DESC"); ?> <table width='95%'> <tr><th>From</th><th>Message Subject</th><th>Date Recieved</th></tr> <?php while($return = mysql_fetch_object($sql)) { $fromUser = getNameFromID1($return->messageFrom); $messageDate = gmdate("M d Y H:i:s",$return->messageDate); if($return->messageRead == "0") { $messageRead = "notread.jpg"; } else { $messageRead = "read.jpg"; } echo "<tr><td><img src='".$messageRead."' /></td> <tr><td>$fromUser</td><td><a href='viewmessage1.php?messageID=$return->messageID'>$return->messageSubject</a> </td><td>$messageDate</td></tr>"; } ?> </table> This is my function that i have called in the inbox code: <?php function getNameFromID1($userID){ include 'gradnetconn.php'; $query = ("SELECT CONCAT(userFirstName, ' ', userSurname) AS full_name FROM gn_users INNER JOIN gn_messages WHERE gn_users.userID = gn_messages.messageFrom"); $result = mysql_query($query); while($row = mysql_fetch_array($result)) { return( $row['full_name']); } } ?> The wrong full_name is appearing. The full name should be 'steven steven' when its saying 'Daniel Petrie' Really frustrated on this now could you give me any solution or logic?
  17. Still having trouble with the query. This is the code ive got now so on a users inbox, they can see the full_name of the person that the message was from. Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource <?php include 'gradnetconn.php'; include 'functions.php'; session_start(); $messageFrom = $_SESSION['userID']; $sql = mysql_query("SELECT gn_messages.*, CONCAT(userFirstName, ' ', userSurname) AS full_name FROM gn_messages INNER JOIN gn_users ON gn_users.user_id = gn_messages.messageFrom WHERE messageFrom = $messageFrom AND messageDeleted = '0'"); ?> <table width='95%'> <tr><th>From</th><th>Message Subject</th><th>Date Recieved</th></tr> <?php while($return = mysql_fetch_object($sql)) { $messageDate = gmdate("M d Y H:i:s",$return->messageDate); if($return->messageRead == "0") { $messageRead = "notread.jpg"; } else { $messageRead = "read.jpg"; } echo "<tr><td><img src='".$messageRead."' /></td> <tr><td>$return->messageFrom</td><td><a href='viewmessage1.php?messageID=$return->messageID'>$return->messageSubject</a> </td><td>$messageDate</td></tr>"; } ?> </table>
  18. I'm having trouble trying to create a delete function to delete inbox messages. This is my delete form <?php include 'gradnetconn.php'; require_once ('webpage.class.php'); include 'functions.php'; session_start(); $messageTo = $_SESSION['userID']; if (!(isset($_SESSION['userID']) && $_SESSION['userID'] != '')) { echo "Log in to send a message" ; header ("Location: login.php"); exit(); } else { echo "You aree logged in, please feel free to delete a message "; } $sql="SELECT * FROM gn_messages WHERE messageTo = $messageTo AND messageDeleted = '0' ORDER BY messageDate DESC"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action="deletemessagesprocess.php"> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Delete A Message</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF">#</td> <td align="center" bgcolor="#FFFFFF"><strong>Message ID</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>From</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Subject</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Messge Contents</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['messageID']; ?>"></td> <td bgcolor="#FFFFFF"><? echo $rows['messageID']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['messageFrom']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['messageSubject']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['messageBody']; ?></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> </table> </form> </td> </tr> </table> This is my delete form process file: <?php include 'gradnetconn.php'; include 'functions.php'; session_start(); { for($i=0;$i<$count;$i++){ $del_id = $chk[$i]; $sql = "DELETE FROM gn_messages WHERE messageID='$del_id'"; $result = mysql_query($sql); } if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">"; } } mysql_close(); ?> I know this is completetly wrong, I need help on it, how to get the processing right in the second file so it actually deletes the messages that are checked. Any soolutions/ advice and talking my through code solutions would be so great!
  19. This is probably a rookie way of doing it, but these are the functions in order for the full name to display on the inbox and outbox 1st function for inbox, second for outbox <?php function getNameFromID1($userID){ include 'gradnetconn.php'; $query = ("SELECT CONCAT(userFirstName, ' ', userSurname) AS full_name FROM gn_users INNER JOIN gn_messages WHERE userID = messageFrom"); $result = mysql_query($query); while($row = mysql_fetch_array($result)) { return( $row['full_name']); } } ?> <?php function getNameFromID2($userID){ include 'gradnetconn.php'; $query = ("SELECT CONCAT(userFirstName, ' ', userSurname) AS full_name FROM gn_users INNER JOIN gn_messages WHERE userID = messageTo"); $result = mysql_query($query); while($row = mysql_fetch_array($result)) { return( $row['full_name']); } } ?>
  20. I managed to figure it out just before you posted this Thankyou for your help and advice and bearing with me!
  21. I have never done inner joins before, i'm a total beginner. I know this will be wrong but $query = ("SELECT CONCAT(userFirstName, ' ', userSurname) AS full_name FROM gn_users INNER JOIN gn_messages WHERE userID = userID"); would the userID have to be equal to the 'messageTo' field is thats the column where the name appears in the inbox page?
  22. Sorry if got confused, i fixed all the silly errors i made. Heres the functions.php code: <?php function getNameFromID($userID){ include 'gradnetconn.php'; $query = ("SELECT CONCAT(userFirstName, ' ', userSurname) AS full_name FROM gn_users WHERE userID = userID"); $result = mysql_query($query); while($row = mysql_fetch_array($result)) { return( $row['full_name']); } } Inbox code: <?php include 'gradnetconn.php'; include 'functions.php'; session_start(); $messageTo = $_SESSION['userID']; $sql = mysql_query("SELECT * FROM gn_messages WHERE messageTo = $messageTo AND messageDeleted = '0' ORDER BY messageDate DESC"); ?> <table width='95%'> <tr><th>From</th><th>Message Subject</th><th>Date Recieved</th></tr> <?php while($return = mysql_fetch_object($sql)) { $fromUser = getNameFromID($return->messageFrom); $messageDate = gmdate("M d Y H:i:s",$return->messageDate); if($return->messageRead == "0") { $messageRead = "notread.jpg"; } else { $messageRead = "read.jpg"; } echo "<tr><td><img src='".$messageRead."' /></td> <tr><td>$fromUser</td><td><a href='viewmessage1.php?messageID=$return->messageID'>$return->messageSubject</a> </td><td>$messageDate</td></tr>"; } ?> </table> So it works now! The only problem is, in the user ID field, it is returning the wrong name for the messages. It is returning the name of 'Nial McGowan' which is the first full_name field when the query is run. I doesn't seem to be matching the Full_name with the correct userID
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.