Jump to content

Skatecrazy1

Members
  • Posts

    126
  • Joined

  • Last visited

Contact Methods

  • AIM
    skatecrzy1
  • MSN
    dleedurgin@hotmail.com
  • Website URL
    http://www.snapskate.com/
  • Yahoo
    verrizzzon

Profile Information

  • Gender
    Male
  • Location
    Southern California

Skatecrazy1's Achievements

Member

Member (2/5)

0

Reputation

  1. I'm used to OOP, but haven't used it much with PHP so the syntax and declarations are a bit hazy. Used it more often with C++ and Java, and whatever bastardized version of C++ arduino runs off of. I have used mysqli in the past so I do know that there are a few things that are different, how it takes arguments, etc. I am trying to get a basic grasp back on OOP syntax and database querying with php after being gone from it for years working in an industrial occupation. Currently rewriting my code with more updated syntax and function libraries. Having issues declaring protected or public variables as they seem to go undefined when it comes time to call them. Now bear with me, declaring your own constructors wasn't really necessary back when I was at it, so I'm still trying to wrap my head around the concept of it. I seem to be failing pretty hard. This code throws me an "UNEXPECTED T_VARIABLE" on line 6. <?php class Sql { protected $host, $user, $pass, $db; $host = "localhost"; $user = "admin"; $pass = ""; $db = "blog"; public function __construct($host, $user, $pass, $db){ $this->host = $host; $this->user = $user; $this->pass = $pass; $this->db = $db; $conn = mysqli_connect($host, $user, $pass); mysqli_select_db($db); } public function userData() { $sql = "SELECT * FROM users"; $result = mysqli_query($conn, $sql); $num = mysqli_num_rows($result); for($i = 0; $i < $num; $i++){ $data = mysqli_fetch_array($result); echo $data['name']; echo " | "; echo $data['email']; echo " | "; echo $data ['phone']; echo "<br />"; } } } ?>
  2. Is mysql improved expected to be supported for any length of time? It's closer to what I'm used to. The OOP is terrible because I used to write scripts back in the PHP2-3 days and never used objects with any frequency.
  3. Guess not. Was using the older code because that's what I remember off the top of my head. I'll seek help elsewhere, then. So long phpfreaks, you used to be cool.
  4. Thanks for making my point for me. I'm using it because I haven't written any code in a few years. Anyone on this forum who actually wants to look at my code ? Or has there been a large influx of pompous twits in the couple years I've been gone and no one actually helps out here anymore?
  5. Can you actually elaborate? What parts of my code are obsolete? Try being helpful instead of just confirming what I already know. For what it's worth the code was working perfectly fine until I imported everything into the new db.
  6. So I'm just starting this little side project to mess around with the idea of a torrent tracker site. I'm a little rusty with my hand-typed scripts so I'm sure I'm looking right at something here and missing it. Just trying to display table data from 'users'. Worked just fine while I ran it on the test db, but after exporting it from the test db and importing it into the actual db I'm using I get a boolean returned for my $result, which causes my num_rows to fail and throw an error. Thanks in advance for any help. <?php class Sql { public function __construct(){ global $host, $user, $pass, $db, $conn; $host = "localhost"; $user = "admin"; $pass = ""; $db = "blog"; $conn = mysql_connect($host, $user, $pass); mysql_select_db($db); } } class Connect extends Sql { //connect function and verification public function init(){ //this function connects to the database based on //global variables defined in the "Sql" class // globals global $user, $pass, $conn, $host, $db; if(!$conn){ print "Connection failed."; } else { print "<div id = \"connect\">"; print "SQL Connection Successful"; print "</div>"; } } } class Display extends Sql { //this class selects and displays data from a given table public function user_display(){ // globals global $conn; $sql = "SELECT * FROM users"; $result = mysql_query($sql, $conn); if(!$result){ echo $result; } $num = mysql_num_rows($result); echo " <table padding=\"3\" border=\"1\"> <tr> <td> <strong>Name</strong> </td> <td> <strong>Email</strong> </td> <td> <strong>Phone</strong> </td> </tr>"; //loop through the data for($i = 0; $i < $num; $i++){ $data = mysql_fetch_array($result); echo " <tr> <td> ".$data['name']." </td> <td> ".$data['email']." </td> <td> ".$data['phone']." </td> </tr>"; } mysql_close($conn); } } ?>
  7. having a problem using get variables to include certain pages. I have a management script for a news feed that uses get variables to display certain parts of the script. here is the template/ main part of the script <?php session_start(); require_once("vars.php"); $username = $_SESSION['username']; $is_admin = $_SESSION['is_admin']; $referer = $_SERVER['HTTP_REFERER']; //check to see if user is logged in and is an administrator if((isset($_SESSION['username'])) && ($_SESSION['is_admin'] == 1)){ //if all session variables are set, display admin panel ?> <html> <head> <title>Administration</title> <link rel="stylesheet" type="text/css" href="/cameo/css/admin.css" media="screen" /> </head> <body> <table cellspacing="0" cellpadding="3" class="layout"> <tr> <td colspan="2"><h3>Administration</h3></td> </tr> <tr> <td valign="top"> <a href="index.php?pg=news">Manage News Feed</a> </td> <td> <?php $id = $_GET['pg']; switch($id){ case news: include("manage_news.php"); case editpost: include('edit_post.php'); break; } ?> </td> </tr> </table> </body> </html> <?php } else { echo("You do not have permission to view this page. <br />"); echo("<a href=\"".$referer."\">Go Back</a>"); } ?> and heres the edit post page that the script refers to <?php require_once("vars.php"); $id = $_GET['id']; $query = "SELECT * FROM news_feed WHERE id=".$id; $result = mysqli_query($dbc,$query); $row = mysqli_fetch_array($result); ?> <form method="post" action="update.php"> <textarea><?php echo $row['post_body']; ?></textarea> </form> now, for some reason, the edit post form is showing up under the main news feed listing, even though the get id does not match the one in the switch statement. thanks in advance for any help
  8. nevermind, double checked the database and the data somehow got duplicated, thanks for all the help guys
  9. k, finally got it working, but the 2 test rows I created are being displayed twice. once again, here is the code: <?php require_once("vars.php"); //write the query to get the news feed info from the database $query = "SELECT * FROM news_feed"; $result = mysqli_query($dbc, $query); //create beginning tags for the news data table $output = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" name=\"news_data\">"; //display the news feed data while($row = mysqli_fetch_array($result)){ $output .= "<tr>" ."<td><h3>".$row['post_title']."</h3>" ."<br />Posted by: ".$row['posted_by']." on ".$row['date']."</td>" ."</tr>" ."<tr>" ."<td>".$row['post_body']."</td>" ."</tr>"; } $output .= "</table>"; echo $output; ?>
  10. umm, i got an answer as to why my code's not working, but nothing on how to fix it, i tried incrementing the row's id field as such: <?php require_once("vars.php"); //write the query to get the news feed info from the database $query = "SELECT * FROM news_feed WHERE "; $result = mysqli_query($dbc, $query); //create beginning tags for the news data table $output = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" name=\"news_data\">"; //display the news feed data while($row = mysql_fetch_array($result)){ $row_id = $row['id']; $output .= "<tr>" ."<td><h3>".$row['post_title']."</h3>" ."<br />Posted by: ".$row['posted_by']." on ".$row['date']."</td>" ."</tr>" ."<tr>" ."<td>".$row['post_body']."</td>" ."</tr>"; $row_id++; } $output .= "</table>"; echo $output; ?> now I get this error, which by the way i've been getting a lot lately and it's quite annoying, I've used the same mysql_fetch_array parameters for years and the function is just now giving me problems, happens with select_db and mysql_connect as well: Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in /Applications/XAMPP/xamppfiles/htdocs/cameo/newsfeed.php on line 10 any help would be appreciated as I have a loose deadline coming up soon on this
  11. oh okay, but wouldn't while(mysql_num_rows($result)) keep fetching rows until the statement is null?
  12. Hey, was just writing rough code for a news feed script, and this error came up: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 133693565 bytes) in /Applications/XAMPP/xamppfiles/htdocs/cameo/newsfeed.php on line 17 here's the code <?php require_once("vars.php"); //write the query to get the news feed info from the database $query = "SELECT * FROM news_feed"; $result = mysqli_query($dbc, $query); //create beginning tags for the news data table $output = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" name=\"news_data\">"; //display the news feed data $row = mysqli_fetch_array($result); while($row){ $output .= "<tr>" ."<td><h3>".$row['post_title']."</h3>" ."<br />Posted by: ".$row['posted_by']." on ".$row['date']."</td>" ."</tr>" ."<tr>" ."<td>".$row['post_body']."</td>" ."</tr>"; } $output .= "</table>"; echo $output; ?> and heres my vars file if needed <? //common session variables $username = $_SESSION['username']; $is_admin = $_SESSION['is_admin']; //database connection information variables $server = "localhost"; $user = "root"; $pass = ""; $db = "cameo"; //database function variables $dbc = mysqli_connect($server, $user, $pass, $db); //http header and script return variables $index = "/cameo/index.php"; $self = $_SERVER['PHP_SELF']; ?>
  13. shooot, now i'm running this code: <?php session_start(); //sql variables $server = "localhost"; $user = "root"; $pass = ""; $db = "cameo"; //iff user isn't logged in, try to log them in if(!isset($_SESSION['username'])){ if(isset($_POST['submit'])){ //connect to database $dbc = mysqli_connect($server, $user, $pass, $db); //grab entered form data $user_username = mysqli_real_escape_string($dbc, trim($_POST['username'])); $user_password = mysqli_real_escape_string($dbc, trim($_POST['username'])); //if both username and password are entered then find a match in the database if((!empty($user_username)) && (!empty($user_password))) { //look up the username and password in the database $query = "SELECT * FROM users WHERE username = '$user_username' AND '$user_password'"; $data = mysqli_query($dbc, $query); //authenticate if data matches a row if(mysqli_num_rows($data) == 1){ //login is okay $row = mysqli_fetch_array($data); $_SESSION['username'] = $row['username']; $_SESSION['is_admin'] = $row['is_admin']; header('Location:index.php'); } else { //username and password are incorrect or missing, so send a message $error_msg = 'Sorry, you must enter a valid username and password to log in.'; } } } } ?> and the script is working but I come up with a blank page and the header redirect back to index isn't working
  14. ah, i referenced the database name rather than the table in the query
  15. um added another curly bracket at the end, now i get this error: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\xampp\htdocs\cameo\login.php on line 26 numrows shouldn't return a boolean should it? this is quite confusing it should just return the number of rows found not a true/false
×
×
  • 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.