chicken2008 Posted April 13, 2009 Share Posted April 13, 2009 I've been working on a website that allows users to have a profile page. The only problem is that when they click the add course button or create course on the profile page it shows: we have no data. How can I fix this problem so it actually displays the create a course page and add a course page. Here is my code for the profile page and createCoursePage and addcoursepage. profile page <?php /* */ class profilePage extends webPage { protected function content() { $accountID = ( isset( $_GET['accountID'] ) ? $_GET['accountID'] : 0 ); $query = "SELECT * FROM student WHERE accountID=$accountID"; $result = query($query); if($result->num_rows > 0) { $userInfo = $result->fetch_assoc(); } else { echo "we have no data"; exit; } ?> <div id="Welcome"> <h1>Welcome to <?php echo $userInfo['firstName'];?> <?php echo $userInfo['lastName']; ?>'s Profile!</h1> <!--<img src="" alt="Profile Picture" id="profilePic" />_--> <h3><?php echo $userInfo['firstName']?> <?php echo $userInfo['lastName']?> <?php echo $userInfo['status'];?></h3> <a href="Update_Status.php?accountID=<?php echo $accountID?>"> Update Status</a> </div> <div id="About"> <h2>About Me</h2> <p><?php echo $userInfo['about']; ?></p> <div> <a href=message.html id="msgMe"><font color="black">Message Me!</font></a> <div id="Schedule"> <h2>My Schedule</h2> <div> <p><a href="addCoursePage.php?accountID=<?php echo $accountID; ?>">Add a Course</a></p> <p><a href="createCoursePage.php?accountID=<?php echo $accountID;?>">Create a New Course Here</a></p> </div> <div> <?php $query = "SELECT courseID,courseName from courses WHERE courseID IN (SELECT courseID from account_courses WHERE accountID=$accountID)"; $result = query($query); ?> <p><ul> <?php /* Loop to get all rows */ while ($row = mysqli_fetch_array($result)) { echo "<li><a href='course.php?courseid=" . $row['courseID'] . "'>" . $row['courseName'] . "</a></li>"; } ?> </ul></p> </div> <div id="Intrests"> <h2>Intrestes</h2> <p><ul> <li>Music: <?php echo $userInfo['music'];?></li> <li>Movies: <?php echo $userInfo['movies'];?></li> <li>Hobbies: <?php echo $userInfo['hobbies'];?></li> </ul></p> </div> <div id="Details"> <h2>Details</h2> <p><ul> <li>Birthday: <?php echo $userInfo['birthday'];?></li> <li>Relationship Status: <?php echo $userInfo['relateStat'];?></li> <li>Home town: <?php echo $userInfo['homeTown'];?></li> <li>Greek: <?php echo $userInfo['greek'];?></li> <li>Organizations: <?php echo $userInfo['otherOrgs'];?></li> </ul></p> </div> <div id="Contact"> <h2>Contact Info</h2> <p><ul> <li>E-mail: <?php echo $userInfo['email'];?></li> <li>Instant Messenger: <?php echo $userInfo['instantMsngr'];?></li> <li>Phone: <?php echo $userInfo['landLine'];?></li> <li>Cell Phone: <?php echo $userInfo['cell'];?></li> <li>Address: <?php echo $userInfo['address'];?></li> <li>School Residence: <?php echo $userInfo['schoolRes'];?></li> <li>Campus Box: <?php echo $userInfo['campusBox'];?></li> </ul></p> </div> <div> <a href="editProfile.php?accountID=<?php echo $accountID; ?>">Edit Profile</a> </div> <div> <a href="<?php echo EVENT?>">Create Event</a> </div> <div> <a href="<?php echo DISPLAYEVENT?>">Display Events</a> </div> <?php } } ?> create course page <?php /** */ class createCoursePage extends webPage { protected function content() { $accountID = ( isset( $_GET['accountID'] ) ? $_GET['accountID'] : 0 ); $query = "SELECT courseName FROM courses"; $result = query($query); if($result->num_rows > 0) { $temp = $result->fetch_assoc(); } else { echo "we have no data"; exit; } ?> <h1>Create a Course</h1> <div id="messageBox"></div> <form id="createCoursePageForm" method="POST" action="_createCoursePage.php?accountID=<?php echo $accountID;?>"> <table> <tr> <td>Course Name</td> <td><input type="text" name="courseName" /></td> </tr> <tr> <td>Description</td> <td><input type="text" name="courseDescription" /></td> </tr> <tr> <td>Course Department (ex. CSCI)</td> <td><input type="number" name="courseDepartment" /></td> </tr> <tr> <td>Start Time</td> <td><input type="date" name="startTime" /></td> </tr> <tr> <td>End Time</td> <td><input type="date" name="endTime" /></td> </tr> <tr> <td>Semester</td> <td><input type="text" name="courseSemester" /></td> </tr> <tr> <td>Building</td> <td><input type="text" name="building" /></td> </tr> <tr> <td>Room Number</td> <td><input type="number" name="roomNumber" /></td> <tr> <tr> <td> </td> <td><input type="submit" value="Create Course Page!" /></td> </tr> </table> </form> <?php } } ?> add course page <?php /** */ class addCoursePage extends webPage { protected function content() { $accountID = ( isset( $_GET['accountID'] ) ? $_GET['accountID'] : 0 ); $query = "SELECT courseName FROM courses"; $result = query($query); if($result->num_rows > 0) { $temp = $result->fetch_assoc(); } else { echo "we have no data"; exit; } ?> <h1>Select a Course to Add</h1> <div id="messageBox"></div> <form id="addCoursePageForm" method="POST" action="_addCoursePage.php?accountID=<?php echo $accountID;?>"> <input type="hidden" name="accountID" value="<?php echo $accountID; ?>"> <table> <tr> <td>Course 1</td> <td> <select name="course1"> <?php $query = "SELECT * FROM courses"; $result = query($query); echo "<option value=\" \"></option>"; for($i=0; $i < $result->num_rows; $i++) { $temp2 = $result->fetch_assoc(); echo "<option value=\"$temp2[courseID]\">$temp2[courseName]</option>"; } ?> </select> </td> </td> </tr> <td> </td> <td><input type="submit" value="Add Courses!" /></td> </tr> </table> </form> <?php } } ?> Link to comment https://forums.phpfreaks.com/topic/153812-solved-php-isnt-displaying-right/ Share on other sites More sharing options...
timmah1 Posted April 13, 2009 Share Posted April 13, 2009 May be nothing, but shouldn't you have single quotes around $accountID? $query = "SELECT * FROM student WHERE accountID = '$accountID'"; As well as this? $query = "SELECT courseID,courseName from courses WHERE courseID IN (SELECT courseID from account_courses WHERE accountID = '$accountID')"; Link to comment https://forums.phpfreaks.com/topic/153812-solved-php-isnt-displaying-right/#findComment-808375 Share on other sites More sharing options...
Ashoar Posted April 13, 2009 Share Posted April 13, 2009 Do you have any data in the database already? Also if the above does not work, try change your query results around a bit: $query=mysql_query("SELECT * FROM student WHERE accountID=$accountID"); if(mysql_num_rows($query)==0) echo "No Data"; else for($i=0;$i<mysql_num_rows($query);$i++) { $userInfo=mysql_fetch_assoc($query); Link to comment https://forums.phpfreaks.com/topic/153812-solved-php-isnt-displaying-right/#findComment-808382 Share on other sites More sharing options...
chicken2008 Posted April 13, 2009 Author Share Posted April 13, 2009 I tried both of those solutions and they didn't work. When I click the links add a course page or create a course page the two pages both just show. We have no data. I'm not sure whats going on... Link to comment https://forums.phpfreaks.com/topic/153812-solved-php-isnt-displaying-right/#findComment-808393 Share on other sites More sharing options...
Ashoar Posted April 13, 2009 Share Posted April 13, 2009 If you have no data, that is your problem. if($result->num_rows > 0) { $temp = $result->fetch_assoc(); } else { echo "we have no data"; That message displays when it cannot find data from the table you are fetching from. Link to comment https://forums.phpfreaks.com/topic/153812-solved-php-isnt-displaying-right/#findComment-808398 Share on other sites More sharing options...
chicken2008 Posted April 13, 2009 Author Share Posted April 13, 2009 Yeah, but that doesn't make sense because I have a data in my table. Link to comment https://forums.phpfreaks.com/topic/153812-solved-php-isnt-displaying-right/#findComment-808406 Share on other sites More sharing options...
Ashoar Posted April 13, 2009 Share Posted April 13, 2009 Ok then, instead of selecting all info (*) add the table rows you would like to select from. SELECT rowname,rowname,rowname etc. Link to comment https://forums.phpfreaks.com/topic/153812-solved-php-isnt-displaying-right/#findComment-808418 Share on other sites More sharing options...
chicken2008 Posted April 13, 2009 Author Share Posted April 13, 2009 Ok so I fixed my create a course page and add a course page by making it >= instead of just > for $result = query($query); if($result->num_rows >= 0) { $temp = $result->fetch_assoc(); } Now it allows me to add courses to my page as links. But now when I click on the course name link that was just added to my profile it doesn't draw from the database. here is my course.php <?php /** */ class coursePage extends webPage { protected function content() { $courseID = ( isset( $_GET['courseID'] ) ? $_GET['courseID'] : 0 ); $query = "SELECT * FROM courses WHERE courseID=$courseID"; $result = query($query); if($result->num_rows > 0) { $temp = $result->fetch_assoc(); } else { echo "we have no data"; exit; } ?> <h1>Course Name: <?php echo $temp['courseName'] ?></h1> <fieldset> <table> <tr> <td>Description: <?php echo $temp['courseDescription'] ?></td> <td></td> </tr> <tr> <td>Department: <?php echo $temp['courseDepartment'] ?></td> <td></td> </tr> <tr> <td>Start Time: <?php echo $temp['courseStartTime'] ?></td> <td></td> </tr> <tr> <td>End Time: <?php echo $temp['courseEndTime'] ?></td> <td></td> </tr> <tr> <td>Semester: <?php echo $temp['courseSemester'] ?></td> <td></td> <tr> <tr> <td>Building: <?php echo $temp['courseBuilding'] ?></td> <td></td> </tr> <tr> <tr> <td>Room Number: <?php echo $temp['courseRoomNumber'] ?></td> <td></td> </tr> </table> </fieldset> </form> <?php } } ?> Link to comment https://forums.phpfreaks.com/topic/153812-solved-php-isnt-displaying-right/#findComment-808428 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.