PHP - Can This Be Done With Php. My Newbie Learning Project.
Hello
This is what I am wanting to do can it be done in php without database or mysql? Basically what I would like to do is from a seach box on my site I would like to take the search term that the user inputs into that search box and then place that seach term on a php page that is automatically generated with the filename search-term.php and is added to a sidebar. The keyword would also be placed on the webpage with a tag %searchterm% so I can have text "you searched for %searchterm%" and it will echo the users search term that they put into the search box. Like I said I am new to php coding so this is a project that I would like to try. It will involve auto generating php files and auto adding links to pages and keyword grabbing. I would like to do this with out mysql or databases. Similar TutorialsCan't figure out what is wrong with my function getVars here is my code Code: [Select] <?php echo"<?xml version=\1.0\"encoding=\UFT-8\"\x3f>"; echo"\n"; ?> <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtmll/DTD/xhtmll-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"lang="en"> <head> <title>My third PHP Generated Document</title> </head> <body> <h2> My Third PHP Document </h2> <?php echo "<h3>Today is ".date('l, F d, Y')."</h3>"; ?> <?php //calculate the area of an equilateral triangle function calcTriangle($cVal) { $halfSide = $cVal/2; $otherSide = sqrt(($cVal*$cVal) - ($halfSide*$halfSide)); $area = $otherSide * $halfSide; echo "<p>The area of an equilateral triangle whose sides are {$calcValue} is {$areaValue}.</p>\n"; } //calculate the area of a circle function calcCircle($cVal) { $areaValue = $calcValue * $calcValue * pi(); echo "<p>The area of a circle whose radius is {$calcValue} is {$areaValue}.</p>\n"; } //calculate the area of s square function calcSquare($cVal) { $areaValue = $calcValue * $calcValue; echo "<p>The area of a square whose sides are {$calcValue} is {$areaValue}.</p>\n"; } //function to test variables function testVars() { global $_POST; if (empty($_POST['vfld'])) { echo "<h3>Error</h3>"; echo "<p>You must enter a value!</p>\n"; return "no"; } else { return "yes"; } } //function to get variables function getVars(&$a, &$b, &$c) { global $_POST; $a->$workValue = $_POST['vfld']; $b->$workType = $_POST['tfld']; $c->$calcValue = (float) $workValue; return; } $workValue = (isset($_POST['vfld']))?$_POST['vfld']:''; $workType = (isset($_POST['tfld']))?$_POST['tfld']:''; if (isset($_POST['submit'])) { if ($_POST['submit'] == "Clear") { clearVars(); } elseif ($_POST['submit'] == "Calculate") { getVars(); $continue = testVars(); if ($continue == "yes") { switch ($workType) { case "circle": calcCircle($workVal); break; case "square": calcSquare($workVal); break; case "triangle": calcTriangle($workVal); break; } } } } <form method="post" action="hw06.php" id="form1" name="form1"> <p> Enter a number here : <input type="text" id="vfld" name="vfld" value="<?php echo $workValue; ?>"/> </p> <p> This number is: <br /> <input type="radio" name="tfld" value="circle" <?php if ($workType == "circle") { echo 'checked="checked"'; } ?> /> : the radius of a circle <br /> <input type="radio" name="tfld" value="square" <?php if ($workType == "square") { echo 'checked="checked"'; } ?> /> : the length of one side of a square <br /> <input type="radio" name="tfld" value="triangle" <?php if ($workType == "triangle") { echo 'checked="checked"'; } ?> /> : the length of one side of an equilateral triangle </p> <p> <input type="submit" name="submit" value="Calculate" /> <input type="submit" name="submit" value="Clear" /> </p> </form> <div id="footer"> </div> </body> </html> and here are my errors Warning: Missing argument 1 for getVars(), called in /studfs1/homepage/CISS-225/hw06.php on line 69 and defined in /studfs1/homepage/CISS-225/hw06.php on line 55 Warning: Missing argument 2 for getVars(), called in /studfs1/homepage/CISS-225/hw06.php on line 69 and defined in /studfs1/homepage/CISS-225/hw06.php on line 55 Warning: Missing argument 3 for getVars(), called in /studfs1/homepage/CISS-225/hw06.php on line 69 and defined in /studfs1/homepage/CISS-225/hw06.php on line 55 Notice: Undefined variable: workValue in /studfs1/homepage/CISS-225/hw06.php on line 57 Fatal error: Cannot access empty property in /studfs1/homepage/CISS-225/hw06.php on line 57 Any help would be greatly appreciated please explain too I just decided to start up on OOP, and it seems quite fun (yes, I find programming fun). But, I'm having trouble on this test OOP page. This is suppose to return the private variable $name, and if it's empty, it's suppose to echo the no name to return message. Code: <?php class findName { private $name; public function setName($sname) { if(!$sname) { $this->name = "There is no name to return."; } else { $this->name=$sname; } } public function getName() { return $this->name; } } $n = new findName(); $n->getName(); ?> If there is an easier way to do this, please let me now! I have a copy of the Developer's Library book PHP and MySQL Web Development. It teaches PHP 5.3 and MySQL 5.1. It is an extensive book of almost 1000 pages. I know that PHP is now at 5.5, but is this still good enough to learn the basics or are there major differences?
Thanks.
Hello everybody, I'm Nishio and I started to program like a month ago, my basic idea was to be able to create websites and to work as a freelancer, I know HTML and CSS from what I can design a simple website, but most of the people who look for freelancers also look for PHP/ASP knowledge, and I know some basics of PHP, like variables, booleans and NULL, constants, arrays, if statement, but I don't know how to acctualy do anything a little more complex with it. So I guess what I am asking for is a mentor, somebody who would tell and show me how do I connect PHP with web design I already know. And no I do not have any money, so I am basicly asking for somebody who has nothing to do for 1/2 hours a day and knows PHP. Thanks in advance, and sorry if I posted in a wrong section. Hello, I'm Dustin I going back to school for software development. this semester I am taking PHP and Javescript.
Hi, I am wanting to build a small internal web portal, hopefully in php, however I just want to check that I can do a few key things before I go down this road. This is for work, so rather than waste a bunch of time, I've got a few quick questions hopefully someone can answer for me. 1) Is it possible to grab NT login information such as NTSID, Domain username, Full name based on domain login 2) show/hide objects based on above login The portal is meant to be a front end access to a bunch of reports, and the ntsid and username are used as authentication for these reports. The idea is that a user navigates to the site, it says Hi John, here are the reports you have access to. The only part I really need to worry about is the hiding and showing of the reports, since they have their own built in security. I'll also want to have an add user page, which will mean i'll need a button that grabs an ntsid based on a username entered in a field. Are these things possible? Regards, Matt Hey people!
I'm new here and I desperately need your help! I have my PHP exam on monday so I'm practicing with codeacademy. I know it's easy stuff for you, but don't judge and help a girl out please!
These are the instructions:
Create a class called Cat.
Add two public properties to this class: $isAlive ought to store the value true and $numLegsshould contain the value 4.
Add a public $name property, which gets its value via the__construct()or.
Add a public method calledmeow(), which returns "Meow meow".
Create an instance of the Catclass, which has the $name "CodeCat".
Call the meow() method on thisCat and echo the result.
This is my code:
<?php Hey sorry that I am asking this question, though I have gotten around to learn connecting to a database and also do the retrieve, yet I am not necessarily getting to learn doing INSERT, UPDATE and DELETE the proper way.
The tutorials available are often not best, I have found a good book ("Object Oriented Programming in PHP5") which teaches SELECT, yet not necessarily INSERT, UPDATE and DELETE.
I am really wondering how does one get to learn CRUD with PHP OOP, how did you people learn this? How can I learn INSERT, UPDATE and DELETE as well with PHP OOP? I feel like paying for this on Elance or Fiverr. I am not sure how else to learn this by now, I have tried quite a bit, I have looked at scripts and tutorials and books. And it has just gotten as far as connecting to the database and doing the "fetching" ("SELECT", or also "retrieve"). Too bad that what is available is not necessarily best. Otherwise I would say one could understand the principle quickly and also pick up on a programming language quickly. Please bear with me, I would appreciate suggestions. When I say I'm a noobie, I'm not kidding!
I'm using a hosting service (Bluehost) that offers PHP 5.4.30 and mySQL 5.5.37 and am trying to work through a beginners tutorial. Using the service's PHPMyAdmin tool, I have no trouble creating a database and table that I can manipulate using this tool. My problem is with my very first php command:
$db = new mysqli(localhost, 'me', 'pw', 'RR');
'me' and 'pw' are my Bluehost signon credentials that were also required to get into the PHPMyAdmin tool. 'RR' is the actual name of the database I'd created. I'm not sure if these are what mySQL is looking for. I also tried 'root' and a null password as done in the tutorial, but that didn't help. The message I get is:
Connect failed: Access denied for user 'me'@'localhost' to database 'RR'
I'd love to get somewhat proficient on PHP/mySQL. Please help.
At the moment I have <input type="hidden" name="iput-time1" value="2021-06-21 01:00"> and the time gets put in the script by $IpTime= $_POST['iput-time1']; So how can I get the time that I would put in <td>01:00</td> and do away with the hidden input bit. I have no idea even if I explained that right
I know this function will get one result, I suspect foreach is the wrong loop to use, should I be using a loop at all? Can someone correct me please. public function getSites($site) { $sql = "SELECT * FROM website WHERE website_id = ?"; $stmt = $this->connect()->prepare($sql); $stmt->execute($site) $siten = $stmt->fetch(); foreach ($siten as $row) { $title = $row["website_title"]; $wname = $row["website_name"]; $image1 = "header.jpg"; $metadesc = $row["website_description"]; $wurl = $row["website_url"]; $gtag = $row["website_gtag"]; $gmap = $row["website_map"]; $wcss = $row["website_css"]; } } Edited February 23 by guymclarenza need help. am learning php oop. Logic below breaks when processing second parent. $db was defined a second time? Suggestions? Do i need to define new database for child??? $db = new Database; $Query = ('Select parentId from PARENT'); $db->query($Query); while ($db->nextRecord()){ $PARENT_ID = $db->Record['PARENT_ID']; $PARENT_NAME = $db->Record['PARENT_NAME']; $Query = ('Select * from CHILD where CHILD_PARENT_ID = $PARENT_ID'); $db->query($Query); while ($db->nextRecord()){ print "child name: $db->Record['CHILD_NAME']; } } Would anyone have any recommendations for a book or any other materials that I can use to start my learning experience and grasp these concepts more? Something that is reader friendly and well laid out preferably.
Hi, I have a working PHP app with limited functionality that I use daily. Some months ago I wanted to add functionality, but soon came to a conclusion I should convert my procedural code to OO PHP. So I read some books by David Powers and Matt Zandstra (the latter was sometimes a little bit too complex for me) and started converting. I now have converted some parts of my app and created new functionality and everything was working perfectly, until I started to use methods from class A inside methods of class B. I started getting irrational errors: sometimes it worked, sometimes it returned an error. I think I have narrowed it down to the use of __construct() and __destruct() in all of my classes, and I'm wondering what is the (better/best) solution. My classes at the moment are all built the same way: Code: [Select] class A { function __construct() { $this->_conn = @ pg_connect( "host=localhost dbname=* user=* password=*" ); } function get_detail() { $this->_res = @ pg_query($this->_conn, "SELECT detail FROM table WHERE ph_id='$id'" ); } function __destruct() { @ pg_free_result( $this->_res ); @ pg_close( $this->_conn );} } I thought I was doing the correct thing by instead of repeating the setting of $this->_conn inside every method, setting that variable upon instantiating the object. But now, I have to make a $this->_conn2 and so on to circumvent the irrational errors (always the same: '5 is not a valid result resource', where '5' should be the '$this->_conn'. Is this a bad practice, or am I doing something else wrong? I also tried 'unset( $this->_conn )' after calling the method, but that didn't seem to work. I'm thinking of looking for a generic PostgreSQL-class so that I can establish the connection inside every method itself, rather than in the __construct() - do you think that would solve my problem? This might be an easy question for someone who is used to OO PHP, so I'm hoping to get an answer which helps me understand the problem. thanks for all the help I can get! HI, I'm new to PHP and I'm trying to learn what sessions are and how they work. I'm working on a login page, I have a table in mysql for sessions, and I have a table with users that includes an email address and password. I just want to query the db to see if there is a user with that email, check the password, and start a session. Every "tutorial" i've looked at fails to answer how the session gets stored in the db, what variable I should set the session at to pull a user's information, and how to use that session to actually echo the information. I'm really frustrated and lost so if anyone knows the correct code or can explain the questions I mentioned above I would appreciate it alot. Thanks! Hi I'm attempting to learn more advanced PHP, such as OOP and the integration of XML, by making a browser-based version of the old Richard Garfield card game "Netrunner". I have a few years experience with pretty basic (bordering on intermediate) PHP. I've done some very basic coding for the game with PHP forms and I've researched some OOP (classes, objects, methods, etc.) but I'm not finding the beginner tutorials that I need. Everything I find has terminology and code that is beyond me. Does anyone have any book or website suggestions for me? I've tried the PHP online manual, but even that throws in advanced stuff all over the place. My goal is to better learn how to use PHP (because I've already put time into it) to create browser based games. Many thanks, Andy Hi, everyone.
I'm having some trouble finding tutorial projects for PHP Functions. Can anyone point me in the right direction if you know of any? I apologize if this is the wrong category to post in for my particular question.
So i've been wanting to expand my php horizons if you will and finally break of my fear of OOP. Here's a simple connection script i built, however i'm kind of stuck on a part of it. user passes username/password. i instantiate the mysqlcon class and call the connect function. the connect function attempts a connection to the database. if successful, pass on the username and password to the authenticator class. call the authenticate function. select user based on username/passwrod criteria. if found return "Confirmed" otherwise "Denied" here's my issue, i'm assuming that my Code: [Select] return $this->ok variable is returned back to the mysqlcon class. however how can i return that variable once more back outside of the object class so that i can continue with my script assuming authentication was confirmed. Here's my code... thanks for the help! <?php ## OOP PRACTICE ## class mysqlcon { function connect($user,$pass) { //Note: Connect to the database $db = mysql_connect("localhost", "usr","psw") or die(mysql_error()); if(mysql_select_db("database",$db) or die(mysql_error())) { $auth = new authenticator(); $auth->authenticate($user,$pass); } } } class authenticator { var $ok = "Confirmed"; var $ex = "Denied"; function authenticate($user,$pass) { //Note: User user and pass variables to check for user in table $qry = "SELECT * FROM users WHERE username = '$user' AND password = '$pass'"; $sql = mysql_query($qry) or die(mysql_error()); $cnt = mysql_num_rows($sql); if($cnt > 0) { return $this->ok; } else { return $this->ex; } } } $con = new mysqlcon(); $con->connect($_POST['username'],$_POST['password']); ?> PS: the classes are in class.php and the instantiation are in index.php. I just placed them together for easy of viewing. I plan on learning PHP for web scraping, automating repetitive tasks and other related stuff. I have no programming background or knowledge at all aside from HTML and CSS (which are not really programming languages). I would like to know if I need to learn everything there is about PHP? Or I can just learn the basics and then just learn specific parts or topics of the language that are related to such tasks (scraping and automation)? Any suggestions are welcomed. Thanks in advance. i Have this Form
<form action="action_page.php" method="POST"> <div class="form-group"> <label for="email">Email address:</label> <input type="email" class="form-control" id="email"> </div> <div class="form-group"> <label for="pwd">Password:</label> <input type="password" class="form-control" id="pwd"> </div> <div class="checkbox"> <label><input type="checkbox"> Remember me</label> </div> <button type="submit" class="btn btn-default">Submit</button> </form>
And im trying to pass the information into a USER class and print out the result in a action_page.php.
<?php class User { private $password; private $emailAddress; function __construct() { $this->emailAddress = isset($_POST['email']) ? $_POST['email'] : null; $this->password = isset($_POST['pwd']) ? $_POST['pwd'] : null; } function start() { if (empty($this->password) || empty($this->emailAddress)) { throw new Exception("Empty Post not allowed"); } else { echo " Registration Done"; } } }
$register = new User(); if(!empty($_POST)) { $register->start(); }
Then in my action page i try to refernence the Object with
?php include "User.php"; $user = new User(); try { $user->start(); } catch (Exception $e) { echo "Cannot Find account"; }
but it never can do it ? Anyone any ideas ??
|