Jump to content

dannyp100

Members
  • Posts

    41
  • Joined

  • Last visited

dannyp100's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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)
×
×
  • 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.