Jump to content

yarnold

Members
  • Posts

    67
  • Joined

  • Last visited

Everything posted by yarnold

  1. If you're referring to the attribute from INSIDE the class, use $this->attribute.. If you're referring to the attribute from the rest of your script (ie not inside the class) then use the variable that you assigned to become an instance of that class.. so in your example, $a->attribute $this-> just "means" that it is referring to an attribute or a method that is inside "this" instance of "this" class. Any better?
  2. What on earth are you doing in your PHP code that takes over 15 seconds? You haven't got an accidental infinite loop have you?
  3. $result = mysql_query($query) or die(mysql_error());
  4. <?php echo date("dS"); ?> Or, if you wanted it with sup.. <?php echo date("d").'<sup>'.date("S").'</sup>'; ?>
  5. Just remember that you've got to stripslashes($field); when you extract the data from the database
  6. <?php error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('track_errors', true); //Connect to DB $db = mysql_connect("localhost", "x", "xx"); mysql_select_db("xx"); if(isset ($_POST['submit'])) { //CHANGE TABLE NAME $result = "UPDATE ActiveMembers SET last_name='".mysql_real_escape_string($_POST['last_name'])."', first_name='".mysql_real_escape_string($_POST['first_name'])."', Rank = '".mysql_real_escape_string($_POST['Rank'])."', Agency = '".mysql_real_escape_string($_POST['Agency'])."', Address = '".mysql_real_escape_string($_POST['Address'])."', CSZ = '".mysql_real_escape_string($_POST['CSZ'])."', Phone = '".mysql_real_escape_string($_POST['Phone'])."', Fax = '".mysql_real_escape_string($_POST['Fax'])."', email = '".mysql_real_escape_string($_POST['email'])."', ResidenceAddress = '".mysql_real_escape_string($_POST['ResidenceAddress'])."', RCSZ = '".mysql_real_escape_string($_POST['RCSZ'])."', ResidencePhone = '".mysql_real_escape_string($_POST['ResidencePhone'])."', id_number = '".mysql_real_escape_string($_POST['id_number'])."' WHERE id = '".$id."'"; mysql_query($result) or die(mysql_error()); // echo out the query if (mysql_affected_rows()==1){ echo "Success"; } else { echo "Failure"; } } ?> I fixed a syntax error above. One question - where are you setting $id? If you're getting it from $_POST, you need to assign $id before you construct the query. $id = mysql_real_escape_string($_POST['id']);
  7. last_name = '".mysql_real_escape_string($_POST['last_name'])."',
  8. Why do you need to? <?php class database { // Contains host private $ho; // Contains database name private $dn; // Contains database user private $du; // Contains user password private $up; public function __construct($ho, $dn, $du, $up) { // Sets the connection information $this->ho = $ho; $this->dn = $dn; $this->du = $du; $this->up = $up; } public function connect() { // Establishes a mysql connection and selects the database if(!$this->connection = mysql_connect($this->ho, $this->du, $this->up)) { // If we fail, tell the class that we have failed! throw new exception('MySQL Error :'.mysql_errno().' - Connection to mysql server could not be established -- '.mysql_error(), 1); } if(!mysql_select_db($this->dn,$this->connection)){ // If we fail to select the database, tell the class that we have done so! throw new exception('MySQL Error :'.mysql_errno().' - Database could not be selected -- '.mysql_error(), 1); } return true; } public function disconnect() { // Disconnects from the mysql server. return mysql_close($this->connection); } } // TO USE: $DBConnection = new database('localhost', 'messenger', 'yourusername', 'yourpassword'); $DBConnection->connect(); // Your db queries go here $DBConnection->disconnect(); ?>
  9. For a start, you need to escape all input to prevent the risk of malicious activity being carried out through the form. Use mysql_real_escape_string() around all of the $_POST variables in your update query...
  10. The lowercase sentence starting was intentional, but on reflection it was a bad idea from the start - I removed that "effect" now. I have received comments from other people regarding the left hand side of the banner too, I will give that a rethink - perhaps something more simple to go with the rest of the site would suffice? Thank you again for your advice.
  11. Not easily.. imagine how many people would steal PHP code off magnificent PHP Content Management Systems.. we'd all be out of a job
  12. Remember that PHP is server-side scripting and can only execute when a new HTTP request is made to the server. You should look into the implementation of "AJAX" (Asynchronous javascript and XML) - plenty of tutorials on the Internet regarding how to do form validation with it, or even just basic javascript form validation. Achieving the result you want with PHP alone is, as far as I know, nigh on impossible. Unless I've misunderstood, of course!
  13. <!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=iso-8859-1"> <title><Your Forum> :: Index</title> <link rel="stylesheet" type="text/css" href="css/style.css" /> <link rel="stylesheet" type="text/css" href="css/print.css" /> </head> <body> <div align="center"> <table width="800" height="50"> <tr> <td><p align="center"><Your Forum> :: Index </p> <table cellpadding="0" cellspacing="0" border="0" align="center" style="margin-left: 10px;"> <tr> <td class="maintab_active_first"></td> <td valign="top" class="maintab_active_back"> <a href="index.php">Home</a> </td><td class="maintab_active_last"> </td> <td valign="top" class="maintab_back"> <a href="help.php">Help</a> </td> <td valign="top" class="maintab_back"> <a href="profile.php">Profile</a> </td> <td valign="top" class="maintab_back"> <a href="members.php">Members</a> </td> <td class="maintab_last" valign="top"> <?php if (!isset($_SESSION['username']) == false) echo "<td valign='top' class='maintab_back'> <a href='logout.php'>Logout</a> </td>"; else{ echo "<td valign='top' class='maintab_back'> <a href='login.php'>Login</a> </td> <td valign='top' class='maintab_back'> <a href='register.php'>Register</a> </td>"; }?> </tr> </table> </td> </tr> </table> </div> <?php $host="*********"; // Host name $username="**"; // Mysql username $password="*************"; // Mysql password $db_name="*******"; // Database name $tbl_name="forum_main"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <div align="center"> <?php $board = $_GET['board']; if ($board == false) { echo "<table width='90%' border='0' align='center' cellpadding='3' cellspacing='1' bgcolor='#CCCCCC'> <tr> <td width='3%' align='center' bgcolor='#E6E6E6'><strong></strong></td> <td width='40%' align='center' bgcolor='#E6E6E6'><strong>Board</strong></td> <td width='27%' align='center' bgcolor='#E6E6E6'><strong>Topics</strong></td> <td width='16%' align='center' bgcolor='#E6E6E6'><strong>Posts</strong></td> <td width='14%' align='center' bgcolor='#E6E6E6'><strong>Last Post</strong></td> </tr>"; while($rows=mysql_fetch_array($result)){ // Start looping table row echo "<tr> <td align='center' bgcolor='#FFFFFF'></td> <td bgcolor='#FFFFFF'><a href='?board=".$rows['board']."'>".$rows['board']."</a><BR></td> <td align='center' bgcolor='#FFFFFF'>".$rows['topics']."</td> <td align='center' bgcolor='#FFFFFF'>".$rows['posts']."</td> <td align='center' bgcolor='#FFFFFF'>".$rows['lastpost']."</td> </tr>"; } } else { echo "This is a Board"; } ?> </div> <?php // Exit looping and close connection } mysql_close(); ?> <tr> <td colspan="5" align="right" bgcolor="#E6E6E6"></td> </tr> </table> </body> </html>
  14. remove the second and third occurences of "$this = new Order();" in your script and it should work?
  15. Could you paste the code you're using to use the class?
  16. <!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=iso-8859-1"> <title><Your Forum> :: Index</title> <link rel="stylesheet" type="text/css" href="css/style.css" /> <link rel="stylesheet" type="text/css" href="css/print.css" /> </head> <body> <div align="center"> <table width="800" height="50"> <tr> <td><p align="center"><Your Forum> :: Index </p> <table cellpadding="0" cellspacing="0" border="0" align="center" style="margin-left: 10px;"> <tr> <td class="maintab_active_first"></td> <td valign="top" class="maintab_active_back"> <a href="index.php">Home</a> </td><td class="maintab_active_last"> </td> <td valign="top" class="maintab_back"> <a href="help.php">Help</a> </td> <td valign="top" class="maintab_back"> <a href="profile.php">Profile</a> </td> <td valign="top" class="maintab_back"> <a href="members.php">Members</a> </td> <td class="maintab_last" valign="top"> <?php if (!isset($_SESSION['username']) == false) echo "<td valign='top' class='maintab_back'> <a href='logout.php'>Logout</a> </td>"; else{ echo "<td valign='top' class='maintab_back'> <a href='login.php'>Login</a> </td> <td valign='top' class='maintab_back'> <a href='register.php'>Register</a> </td>"; }?> </tr> </table> </td> </tr> </table> </div> <?php $host="*********"; // Host name $username="**"; // Mysql username $password="*************"; // Mysql password $db_name="*******"; // Database name $tbl_name="forum_main"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <div align="center"> <?php $board = $_GET['board']; if ($board == false) echo "<table width='90%' border='0' align='center' cellpadding='3' cellspacing='1' bgcolor='#CCCCCC'> <tr> <td width='3%' align='center' bgcolor='#E6E6E6'><strong></strong></td> <td width='40%' align='center' bgcolor='#E6E6E6'><strong>Board</strong></td> <td width='27%' align='center' bgcolor='#E6E6E6'><strong>Topics</strong></td> <td width='16%' align='center' bgcolor='#E6E6E6'><strong>Posts</strong></td> <td width='14%' align='center' bgcolor='#E6E6E6'><strong>Last Post</strong></td> </tr>"; while($rows=mysql_fetch_array($result)){ // Start looping table row echo "<tr> <td align='center' bgcolor='#FFFFFF'></td> <td bgcolor='#FFFFFF'><a href='?board=".$rows['board']."'>".$rows['board']."</a><BR></td> <td align='center' bgcolor='#FFFFFF'>".$rows['topics']."</td> <td align='center' bgcolor='#FFFFFF'>".$rows['posts']."</td> <td align='center' bgcolor='#FFFFFF'>".$rows['lastpost']."</td> </tr>"; } } else { echo "This is a Board"; } ?> </div> <?php // Exit looping and close connection } mysql_close(); ?> <tr> <td colspan="5" align="right" bgcolor="#E6E6E6"></td> </tr> </table> </body> </html>
  17. Try running a script which contains this: chmod("/somedir/", 777); For the directories that you're trying to delete. It's by no means guaranteed to work but you never know!
  18. Do the same. remember that the var num2 is ONLY set to 100 for that INSTANCE of that object, not for all instances of that object. So to access the var num2 that is set to 100 you must use the same object that you used to set num2. So to execute your "example" class in your most recent post, you'd do exactly the same as what I put in my post - try it..
  19. Assuming you ran the following from my example, it would return 100: $Example = new example; $Example->foo(); $Example->shownum2();
  20. Try removing $this = new Order(); from the start of the function.
  21. Place this in a HTML document <form id='form' name='form' action='http://www.mysite.com/phpfile.php' method='get' enctype='multipart/form-data'> <input type='text' size='20' name='name' id='name' /> <input type='submit' value='Submit' id='submit' name='submit' /> </form>
  22. Instead of using $num2.. use $this->num2. That way the variable "$this->num2" is accessible throughout your whole class. class example { public $num2; public function foo() { $this->num2 = '100'; } public function shownum2() { // $this->num2 is accessible from here too! echo $this->num2; } }
×
×
  • 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.