Jump to content

jrws

Members
  • Posts

    124
  • Joined

  • Last visited

    Never

Everything posted by jrws

  1. Alright will try your suggestions. I will edit this post in a minute, as soon as I have tried You are my hero! Thats what I was missing! I don't know how I kept missing it >_<; Thanks for all your help. Man I am glad I have you guys to help ^^
  2. I thought I was too, it is all correct and yet I still cannot see why it isn't working. It is really peeing me off! I told you I am not doing sercurity at the moment. Because this is staying in a test environment. I don't see the title in the edit page, I mean when you edit a topic here it has your topic name and then the body content. In my file it is missing the topic name (in this example). Do you understand now? And I don't understand what you are doing by saying inserting the value? Its already there
  3. Hey guys me again. Ignore the fact that this is insecure, it is simply for testing purposes. Anyway here are the files first: <?php //Edit Data //edit.php require_once'config.php'; if (isset($_GET['id']) && is_numeric($_GET['id'])) { error_reporting(E^ALL); $id = $_GET['id']; $sql2 = mysql_query("SELECT * FROM `formdata` WHERE id='$id'") or die(mysql_error()); $row = mysql_fetch_array($sql2); $title = $row['title']; $data = $row['data']; $id = $row['id']; if(empty($title)or $title =='') echo 'Its empty...'; echo ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=us-ascii"> <meta name="author" content=""> <title>Database Edit</title> </head> <body> <form action="http://localhost/website/Basic ideas/edit2.php" method = "post"> <input type = "hidden" name = "id" value ="'.$id.'"> Title:<input type="text" name = "title" size="32 value = "'.$title.'"><br> <textarea rows="6" cols="40" name = "data"> ' . $data . ' </textarea> <br> <input type = "submit" value = "Submit"> </form> </body> </html>'); }else{ echo 'No data selected to edit!'; } ?> ^ The problem code (I think) <?php //display.php include "config.php"; if (isset($_GET['id'])&& is_numeric($_GET['id'])) { $id = $_GET['id']; $sql2 = mysql_query("SELECT * FROM `formdata` WHERE id='$id'") or die(mysql_error()); $row = mysql_fetch_array($sql2); $title = $row['title']; $data=$row['data']; echo '<h1>'.$title.'</h1>'; echo '<p>'.$data.'</p>'; echo '<a href = "http://localhost/website/Basic ideas/edit.php?id='.$id.'">Edit this</a>'; }else{ header('Location: http://localhost/website/Basic ideas/database.htm'); } ?> <?php //Edit 2 require_once('config.php'); $title = $_POST['title']; $data = $_POST['data']; $id = $_POST['id']; $query = "UPDATE formdata SET title='$title', data='$data' WHERE id=$id"; $res =mysql_query($query)or die('Error: '.mysql_error().'<br>Query: '.$query); if($res){ echo 'Successfully updated!'; } ?> <?php require_once ('config.php'); $data = clean($_POST['data']); $title = clean($_POST['title']); $query = "INSERT INTO formdata(title,data)VALUES('$title','$data')"; $res = mysql_query($query) or die('Error: ' . mysql_error() . '<br>' . 'Query: ' . $query); if ($res) { echo 'Success! Click <a href="http://localhost/website/Basic ideas/database.htm" >here</a> to go back<br>Below are all the recent articles:<br>'; } $sql = mysql_query("SELECT * FROM `formdata` ORDER BY `id` ASC") or die(mysql_error ()); # select the news echo 'Current posts: '; while ($row = mysql_fetch_array($sql)) { #create a while loop to echo the news in. echo '<br>' . 'Title: ' . $row['title'] . '<br>' . 'Post: ' . $row['data'] . '<br>' . '<a href ="http://localhost/website/Basic ideas/display.php?id=' . $row['id'] . '"> View full post</a>'; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=us-ascii"> <meta name="author" content=""> <title>Database Submition test</title> </head> <body> <form action="http://localhost/website/Basic ideas/data.php" method = "post"> Title:<input type="text" name = "title" size="32"><br> <textarea rows="6" cols="40" name = "data"> </textarea> <br> <input type = "submit" value = "Submit"> </form> </body> </html> Okies so that was all the code. Now the problem. When I enter the edit screen it shows no title. At one point I did a test to see if it was empty (as is still in the code) it returned true. And now it returns false. I can't find where it is having the problem. The edit works, its only the title that doesn't seem to want to. So help is appreciated
  4. Yes but as many errors as possible, also to Crayon Violent, I agree. I appoligize for not being able to contribute much but I try my best. It is hard to help people when you do not know if you know the correct answers.
  5. In the user class. It takes the arguments given, $user, $pass1, $pass2, $email. It then uses these to perform the rest of the script. I was thinking that the arguments would be from the form users submit, therefore making the $user = $_POST['user'; etc
  6. A method is a function no? And the point of cleaning the emai is to prevent unsanitary user input.
  7. No idea, I am new to PHP and programing in general, trying random stuff. I know my logic is way off, What do you mean by pass the database object? edit: The num_rows function is inside a class. And what do you mean by there is already a method?
  8. Here's an idea for a short article and I know it would help a lot of new people, have an article listing all possible errors that PHP may throw at you and explain how to fix them, or what to look for. I think a lot of people would like that and you may not get as many questions about the errors.
  9. Hi guys, me again. I have a fatal error of Call to a member function on a non-object How do you fix these errors? The specific error that it is saying is about the mysql_num_rows function called Num_Rows; here's the code for it <?php function Num_Rows($sql) { $sql = $this->query($sql); $sql = mysql_num_rows($sql) or die(mysql_error()); return $sql; } ?> And here is a snippit of the code in use (specifically the problem) <?php require_once ('../inc/config.php'); $db = new mysql(); //....... //This is in a class mind you: $username_query = "SELECT username FROM user WHERE username = '$username'"; $username_queryR = $db->Num_Rows($username_query); $email = $this->clean($email); $email_query = "SELECT email FROM user WHERE email = '$email'"; $email_queryR = $db->Num_Rows($email_query); ?> The question is how do I fix this problem and any future problems such as this?
  10. Thanks for the help. I will try to do that then.
  11. Sorry, but I am new to classes and OOP. I was wondering how do you get two classes to interact with each other? For example I have the mysql class that does mysql functions, and one of them is to count the rows. Then I have a user class that needs to use this function to see if the user exists. How do I do this? Do I use the double :: or? Any help is much appreciated.
  12. Alright I will try thank you. Yes it works, thanks. Geeze I really wish I could see these simple things...
  13. Wow, this is really peeving me off, first I find a solution to a problem and then, no more...This one is saying: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\xampp\xampp\htdocs\Website\v1\lib\classes\mysql.php on line 35 Now I don't understand why, here are two codes that interact, I have omitted the full class: function Num_Rows($sql) { $sql = $this->query($sql); $sql = mysql_num_rows($sql) or die(mysql_error()); return $sql; } and public function query($sql) { $query = mysql_query($sql) or die(mysql_error()); return $sql; } So what is it saying? Can someone instead of just giving an answer explain why it is complaining? It is spouting this error in reply to a test to add a user, the user code is: public function register($username, $password, $password2, $email) { global $Send_Email, $Admin_Email; $error = array(); $username = $this->clean($username); $username_query = "SELECT username FROM user WHERE username = '$username'"; $username_query = parent::Num_Rows($username_query); $email = $this->clean($email); $email_query = "SELECT email FROM user WHERE email = '$email'"; $email_query = $this->Num_Rows($email_query); $password = $this->clean($password); $password2 = $this->clean($password2); $password = $this->encrypt($password); //Lets start the error checking: if (checkString($username, 1, 30, 'ctype_alnum') || ($username_query > 0)) { $error[] = 'Username must be between 1 and 30 characters and alphanumeric otherwise your username is already taken.</span>'; } if (!valid_email($email) || ($email_query > 0)) { $error[] = 'Your email is invalid OR is already taken.</span>'; } if ($password !== $password2) { $error[] = 'Your passwords are not the same!</span>'; } if (count($error) > 0) { echo "The following errors occured:</br>"; foreach ($error as $err) { echo "<span style=\"color: red;\">$err"; } } else { if ($Send_Email == 1) { $subject = 'Your registration'; $message = 'This is a dummy message!'; if (mail($email, $subject, $message)) { echo 'A confirmation email has been dispatched, please check your inbox and junk mail folder.'; } else { echo 'There appears to be a problem in sending the email, please contact the administrator.'; } } else { $query = "INSERT INTO `user` (`username` ,`password` ,`email`) VALUES ('$user', '$password', '$email'); "; if (query($query)) { echo 'Congradulations you have been added to the database and can now login.'; } else { echo 'There appears to be a problem, please contact the administrator ' . $Admin_Email; } } } } If you need more of my code ask.
  14. Wait NM, I am probaly one of the stupidest people. I forgot I need to add $this-> when using a function with OOP
  15. Hey guys, wow I have a lot of problems. Anyway this particular one is about registration. So basically my user class extends the mysql class which is as its name suggests, about mysql functions. Anyway so a function called register is not working it is saying Fatal error: Call to undefined function clean() in D:\xampp\xampp\htdocs\Website\v1\lib\classes\user.php on line 22 So, what is confusing me is that I thought functions could call functions as long as they exist somewhere? So yeah, if there is any particular code you need ask as I do not know what code to post. And thanks again for helping me.
  16. Alright thanks, I thought I was forgetting something simple. Thanks again for your help, it works now
  17. Sorry I don't understand what you mean by where it it created? Do you mean where at the script? At the very top: require_once ('config.php'); $mysql = new mysql(); Config has the autoload function, and I will try your suggestion Just tried it, no change. BTW why do you add echo anyway? I have seen it done many times and now I am interested as to why, because just the server variable seems to work for me...
  18. I have a script I am using, and as I am a beginer at PHP and OOP the code may have problems. I am trying to make an install page. So far it worked until I added the option of adding an admin via the install page. There are no user levels as of yet and so it was a test. Heres the problem; I click submit and the form processes without going to another page, and the administrator is added, however the email is not there, I even echoed what the database thouht was happening and this is what I got: INSERT INTO `site`.`user` ( `id` , `username` , `password` , `email` ) VALUES ( NULL , 'test', '68358d5d9cbbf39fe571ba41f26524b6', '' ); Now I can't figure out why, because when all forms are filled in that is the same continuous result. I've checked my code to make sure I got the names right,I do. I have also checked that the functions don't interfer with the code, and they don't. So now I am lost. Finially here is the code: <?php $user = clean($_POST['user']); $email = clean($POST['email']); $password = clean($_POST['password']); $password = encrypt($password); $Add_Admin = "INSERT INTO `site`.`user` ( `id` , `username` , `password` , `email` ) VALUES ( NULL , '$user', '$password', '$email' ); "; if ($mysql->query($Add_Admin)) { echo 'Admin user created succesfully!<br>'; echo $Add_Admin; } else { echo 'Admin user failed to be created!<br>'; }?> PHP tags added for the sake of adding them. Heres the form: <form method="post" action="<? $SERVER_['PHP_SELF']; ?>"> Admin Name: <input type="text" name="user"> <br> Password: <input type="password" name="password"><br> Email:<input type="text" name="email"><br> <input type="submit" name ="submit" value="Submit"> </form> When I said error_reporting(E_ALL) the only error I got was with the $SERVER variable... If there is anything else you need to help me solve my problem please ask. Thanks
  19. Like I said, I am new to PHP, and I was advised by an Author of a book to just use the opening tags if it is only going to be php. I have also solved the problem. Turned out I keep doing the same thing. I keep forgetting a simple ; or $. Anyway thanks. Edit: I see your comment now. Seems the forums didn't post the whole code, no matter the problem is solved so thanks again.
  20. It is, that is the whole code, and I will check for the at the end. Thanks for your reply.
  21. I simply get this error: Parse error: syntax error, unexpected '}' in D:\xampp\xampp\htdocs\Website\v1\lib\classes\mysql.php on line 7 But I cannot see what it is talking about, I am new to OOP so it may be something simple: //Testing the classes to make sure the work. require_once('../inc/config.php'); error_reporting(E_ALL); $mysql = new mysql(); $query= "CREATE TABLE `test_mysql` ( `id` int(4) NOT NULL auto_increment, `name` varchar(65) NOT NULL default '', `lastname` varchar(65) NOT NULL default '', `email` varchar(65) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=0 ;"; $mysql ->query($query); The code I run to get the error, and heres the mysql class: function FetchArray($sql) { $sql = $this->query($sql); $sql = mysql_fetch_array($sql) or die(mysql_error()); return $sql; } function FetchRow($sql) { $rows = mysql_fetch_row($sql)or die(mysql_error()); return $rows; } function Num_Rows($sql) { $sql = $this->query($sql); $sql = mysql_num_rows($sql) or die(mysql_error()); return $sql; } function __destruct(){ $this->close(); } } And just for good measure here is the config file. <?php //Database info //Change these as needed define(DBHOST,'localhost'); define(DBUSER,'root'); define(DBPASS,''); define(DATABASE,'site'); $PHPLIB_DIR = $_SERVER['DOCUMENT_ROOT'] . '../lib/classes'; $TEMPLATE_DIR =$_SERVER['DOCUMENT_ROOT'] . '../lib/templates'; //Site information, most if not all these things can be edited via the admin control panel $Admin_Email ='admin@sandstorm.net';//The administrator email $Cookie_Time= 86400;//How long the cookie lasts //Custom error message, there is no need to use it if you don't want to. $Custom_Error = '<br>An error has occured, please contact the site administrator at '. $Admin_Email .'and include and details such as what page and what appeared to be the error occording to the site.'; $Send_Email=0;//0=False, 1 = true, send a confirmation email. //CHANGE ONLY THE Location of the classes function __autoload($class) { $classpath = '../classes/' . $class . '.php'; if (file_exists($classpath)) { require_once $classpath; } $classpath = 'libs/' . $class . '.php'; if (file_exists($classpath)) { require_once $classpath; } } The config file
  22. Hey, I am not wanting anyone to program this as such, rather I wish to know how I go about it. So here is my idea. I am sure you guys have seen the random ad scripts? Where you have images in an array and it selects them at random? Well I was thinking would it be possible so you didn't need to name the file? What I mean is you just point php to the folder that stores all the images and then it selects one at random. If this is possible there is no reason that you couldn't then add it so that you have adverts uploaded via the website instead of FTP but that is what I want to know how to go about it. I am thinking I will need to have PHP look for the file extensions that are common to pictures (.jpg, .gif etc) So what else would I need to do?
  23. Thank you. I will try a new code.
  24. Yes, that is what I was talking about. But unfortunately my limited capacity of knowledge of PHP refrains from allowing me to work the solution completely by myself. So if anyone my help, I would be appreciative. Thanks
×
×
  • 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.