PHP - Beginner Here, Need A Little Help
First of all, sorry for my bad english.
I have this: PHP Code: [Select] $link = file_get_contents("http://www.imdbapi.com/?i=tt1285016"); $json = json_decode($link,true); echo $json["Title"]; and I want to replace tt1285016 with $info["id"]; (this is something from mysql, first time when i use ). If I put echo $info["id"]; it return exactly what i need: tt1421545. How can I do that? thank u very much and sorry again for bad enlighs, not native language. EDIT: Sorry for bad section, first time when i come here. Similar Tutorialshi there i am a beginner in PHP and i really would like some help with this.....
i need to make use of the date() function to retrieve the current date. Use the split() function to retrieve the day month and the year from the current date. and the calculations to display the age.
if anyone could help me with this it would be amazing.
thank you!!
Attached Files
newagecalc.php 1.56KB
0 downloads Hi all messing about with php , trying to get my head round the basics : ok I have a file called test.php with this in it <? $ourFileName = "testFile.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); ?> when I run this instead of creating a blank text file called testfile.txt all it does is repeat the code in the command box window as below C:\php>php -f c:\php\test\test.php <? $ourFileName = "testFile.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); ?> C:\php> Anyone got a clue as to why it wouldnt create a text file please? Hi, I'm trying to set up a mysql database on my laptop, XP, and connect to a test database using php. I've created the database called 'testdb' with user account 'test' and password 'password. The code I'm using to try and connect to the test datase is the following; $dbconnect=mssql_connect("localhost", "test", "password"); But when I open the page in a web browser, I am getting the following error; Fatal error: Call to undefined function mssql_connect() in <file_location> I'm hoping I'm doing something simple here, but, I've looked up forums and this seems to be the code to use to connect. Anyone who could help would be greatly appreciated. Thanks. hey guys, I am very new to PHP and wanted to create a simple form script. Somehow it doesnt work... can you help me? Help is highly appreciated!! here is the code: Code: [Select] <?php $admin= 'name@email.com'; // 1. Message to the admin $subject1= 'You have one new subscription'; $message1.= 'Email: '.$email."\n\n"; $message1.= 'Name: '.$name."\n\n"; // Sending mail mail($admin, $subject1, $message1, "From: $email"); header('Location: http://www.youtube.com'); ?> Hi guys, sorry for the beginner issues here. after following a tutorial i come across a little problem! Everything works just fine, no errors but my page source only shows the xml tags and not the actual products <?php $link = mysql_connect("localhost","Joao","password"); mysql_select_db("brimelow_store"); $query = 'SELECT * FROM products'; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<products>\n"; while ($line = mysql_fetch_assoc($results)); { echo "<item>" . $line["product"] . "</item>\n"; } echo "</products>\n"; mysql_close($link); ?> source = <?xml version="1.0"?> <products> <item></item> </products> I have checked the database names and they all match... im confused. can i get some help pls? Hello, For all purposes, I am a complete beginner. I just know the basics of passing form data through to an email, and displaying the text of a variable on the next page via ECHO, POST, etc.. My situation is that I do not know what sort of code to use to accomplish the job of what I want done. I have created a form to be used for displaying insurance information. This form allows users to select the following: To Get Started: State You Live In: Car Information: Model Year: Original Listing Price: Your Car Currently Is: Your Information: Do You Rent Or Own? Are You Married? Do You Have Children Under 18 Years Of Age? Gross Annual Household Salary Do You Have Health Insurance? How Much Are You Worth In Total Assets (Savings, Equity, Stocks, 401K, Car, Home, etc...) ------------------------ Next to each question, I have a box from which they can select their options (standard html form code). The form has an action and the method is post. Some code is displayed below.. Now so far I am able to display the text of whatever item they selected, by using Echo $_Post etc and the answer page... Here is my problem... I want to display to the user, "recommended insurance limits" based on the data they select from the drop down boxes. So... If a user lives in Alabama, and has an income of $150K+, I want to display a different answer than someone who only earns $30K and lives in Alabama, and the list goes on, (range of options for each question). I have no idea what sort of code to use to display the appropriate answer. I thought I could use the "if, elseif, else" statement, and simply do hundreds of variations on it for each state, but surely there is a more refined and less bloated code for doing such a thing? I would need to display a different answer for the user, for each separate option they choose. Example) Alabama, Model Year of 1995, Salary of $50K would be DIFFERENT then Alabama, Model Year of 2000, Salary of $50K, etc... Thank you for your time. Here is my php code. Code: [Select] <?php $state = $_POST["state"]; $modelyear = $_POST["modelyear"]; $carprice = $_POST["carprice"]; $carownership = $_POST["carownership"]; $homeownership = $_POST["homeownership"]; $marriage = $_POST["marriage"]; $childrenunder18 = $_POST["childrenunder18"]; $salary = $_POST["salary"]; $healthinsurance = $_POST["healthinsurance"]; $assets = $_POST["assets"]; ?> <?php if ($state=="Alabama") { echo "Alabama requires the following minimum insurance limits:<br /> $25,000 - Liability Per Person<br /> $50,000 - Liability For Total Persons<br /> $25,000 - Property Damage Total"; } elseif ($state=="Alaska") { echo "Alaska requires etc..."; } else { echo "You did not select a state."; } ?> Hi there, I'm new to PHP about 5month (previously i don't have any programming background), i study the basic PHP through online. i found a tutorial from : http://www.phpwebcommerce.com/ , and there is some error in this tutorial + i need customize this tutorial for my site. I'm here to ask , is the tutorial suitable beginner like me ? is the tutorial consider for advanced used ? i able to solve some error in this tutorial but it take too long. Can give a solution ? should i give up this tutorial on my site ? or just continue find solution ? but i'm already spent almost 2month in this tutorial. so far, i left shipping cost cant find solution...(but i have try do it for 2weeks) Thank you. Hi, Basically I just downloaded wamp and got php and mysql etc. I created a database for my "new social network to-be site" which I am trying to develop.. now I want to create a registration page and am trying to follow a guide on another website.. it lets you download a zip with all the php files required. So now, I am totally confused. Here is the guide: http://www.html-form-guide.com/php-form/php-registration-form.html But I dont know what to do with any file or where to put it.. any basic help.. Just to confirm I want to make a login/registration/user database type thing Hi all, I hope I am in the right place. I'm new to php/mysql so please be patient with me. I am trying to create a login script to validate username and password against a database I have created. I am not getting an error message but even when I enter correct username/password details from the database to test the code I am getting the message at the bottom of the script. I can't figure out why as I thought I had all bases covered, but obviously not. Here is my code. Thanks for any help in advance. P.S. I have checked the names against my form and they are correct. <html> <html lang="en"> <head> <meta charset="utf-8" /> <title>USER LOGIN</title> </head> <body> <?php if(empty($_POST['name'])){ $name=NULL; echo "Sorry, you forgot to enter your username.</br>"; }else{ $name=$_POST['name']; } if(empty($_POST['password'])){ $password=NULL; echo "Sorry, you forgot to enter a password.</br>"; }else{ $password=$_POST['password']; } $connection = @mysqli_connect('localhost','root','','BLOG_PROJECT') OR die("Could not connect to server"); $username = stripslashes($name); $password = stripslashes($password); $username = mysql_real_escape_string($name); $password = mysql_real_escape_string($password); $info = "SELECT 'username', 'password' FROM USERS WHERE 'username'='$username' and 'password'='$password'"; $return=@mysql_query($info); $rows=@mysql_num_rows($return); if($rows==1){ session_register("username"); session_register("password"); header("location:admin.php"); echo "Hi $username. You are now logged in."; }else{ echo "You have entered incorrect details. Please check your login details and try again."; } ?> </body> </html> <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="stylesheet.css"> <meta charset="utf-8"> </head> <body> <?php $array = array(); echo "<table>"; for ($z=0; $z <=9; $z++) { echo "<tr>"; for ($s=0; $s <=9; $s++) { $r = mt_rand (1, 100); array_push ($array, $r); if ($r %2 != 0) { echo "<td bgcolor = red>"; echo $r; echo "</td>"; } else { echo "<td bgcolor= lightgreen>"; echo $r; echo "</td>"; } } echo "</tr>"; } echo "</table>"; echo "<br>"; echo "<table>"; sort($array); $arraysplit = array_chunk($array, count($array)/10); for ($z=0; $z <=9; $z++) { echo "<tr>"; for ($s=0; $s <=9; $s++) { if ($r %2 != 0) { echo "<td bgcolor = red>"; echo json_encode (arraysplit); echo "</td>"; } else { echo "<td bgcolor= lightgreen>"; echo json_encode ($arraysplit); echo "</td>"; } } echo "</tr>"; } ?> </body> </html> Hey absolute beginner here. Im working on a table that gives random numbers out and then colorizes them if they can be devided by 2. That works fine. Now i want to get those randomly generated numbers into a second table but sorted. I already managed to put the numbers i generated into an array and sort it but i cant figure out how to echo them 1 by 1 into the table. Maybe you can help me out. Hi, I've been using this tutorial all afternoon, and it's been great, but I wonder if it's outdated... http://www.tizag.com/phpT/index.php I'm using WAMPSERVER 2.2 and PHP 5.3.10 Any recommendations for good up-to-date/relevant tutorials? Thanks Hi all For example if you see this code: public function __set($varName,$varValue) { $this->$varName = $varValue; if ($varName == "varOne") { $this->varTwo = $this->varOne * 9; } } Why somewhere dollar sign exists and somewhere not: $this->$varName , $this->varTwo ? Thanks First, I apologize if this is the wrong venue, but it seemed the best place to ask question about code. The code below is very simple most likely, but I am having the hardest time visualizing how it's run. It would be most helpful if someone could point out the error of my thinking that would be awesome. This is literally the first php lesson I have ever taken.
I'm a very visual, hands on kind of learner. It would be most appreciated to get direction into the best way to learn PHP as a visual learner. Thanks!
<?php // I'm following an example online and need an explanation to this. This first part is creating // a class called User. class User { // This is a variable set to public. Now in the lesson I discovered public and private. Why is // public and private important? Could the code just run on $age? public $age; // This is a public function called __construct. Could I name this anything and the function // would still work? What is important about __? public function __construct($age) { // Ok, why is $this used? Is it correct in assuming that any word with a "$" assigned to it in // this class will refer to age? $this->age = $age; } // This is the 3rd function called getAge(). Why is getAge() blank? public function getAge() { echo $this->age; } } // Shoudln't this be at the top? And isn't there a cleaner way to output the age of a new user? // This seems to take up way too much coding just to display the name of a variable? $brad = new User(31); // I'm so confused. $brad->getAge(); Well I have made a form in html and i need the information which is entered into the form to be shown to the user in a different page so I have a Ticket request page and i have made a Confirmation_Page.php Ticket request page: has this <form id="form1" name="form1" method="get" action="Confirmation_page.php"> The ticket request page has (Just one example so eg. the forename: </p> <p> <label>Forename <input type="text" name="Forname" id="Forname" /> </label> </p> <p> And corresponding to this in the Confirmation_Page.php it is : Your forename is : <?php echo $_GET["Forename"];?><br /> Now the thing is when I enter info in the form inside the ticket request page and click submit It takes me to the Confirmation_Page.php HOWEVER It doesn't show me the information I've inputed it into the form Eg.It only shows Your forename is : please help me I need to hand this in by monday :( thanks to everyone who tries to help me :l I'm trying to get my head around oop and wondered if anyone would look at my comments so far . I want to learn a bit about constructors next but thought I should make sure I understand the below code properly first. Code: [Select] <?php class Dictionary { //new class public $translations = array(); public $type =" "; //new variables called 'PROPERTIES' function summarize() { //function within a class is called a 'METHOD' $ret = "Dictionary type: {$this->type}\n"; // {$this->type} means: use $type which is found within THIS class $ret .= "Terms: ".count( $this->translations )."\n"; // {$this->type} means: count the length of the $translation array which is found within THIS class return $ret; } } ?> Code: [Select] <?php include('class_dictionary.php'); //include file that holds the class $english = new Dictionary; // creating new object using the class called Dictionary $english->type = "EN"; // adding a value to the 'type' property located within the dictionary class $english->translations['TREE'] = "branch"; //adding TREE key and value branch to the translations array $english->translations['TREEtwo'] = "trunk"; //adding TREEtwo key and value trunk to the translations array $french = new Dictionary; //creating a new instance of the Dictionary object $french->type = "FR"; $french->translations['TREE'] = "arbre"; print_r( $english ); echo "<br/>"; print $english->summarize(); //prints the summarize method ?> I have a search box with an input box. When the user enters a string in this box and then when it clicks submit, the form needs to go to the http://ww.mywebsite.com/wp-content/uploads/<?php echo $_POST["name"]; ?>.jpg where $_POST["name"] is what the user entered. how to make it work?? <form action="http://ww.mywebsite.com/wp-content/uploads/<?php echo $_POST["name"]; ?>.jpg" method="post" target="_blank"> <!-- form fields here --> <INPUT TYPE = "Text" NAME = "name"> <input type="submit" /> </form> Hei everyone. I am new on php development and i do not have budget on offering a course so i am trying to learn my self. i need some help on the following : i want to create infopanel.php where the script will get info from. For example if user logs in the script will have to call : <?php include '/incl/infopanel.php' ; ?>The info panel to load all details from database: <?php $name='$myname'; $sur_name='$sname'; $age='$myage'; $country='$mycountry'; ?>So the info with my has to be from database . so can some one help me how to call all information from database to a specific file that i will not have to call always information on every page I hope i have been so clean with my request i am brand new to php and thought a project looking at the weather undergound api would be a great place to "cut my teeth" and i am following up on a recent post i saw here http://www.phpfreaks.com/forums/index.php?topic=354658.msg1675207#msg1675207 the responder excellently described how to use the foreach function however i am not sure this is right for my application the project i am trying to accomplish is defining the freeze thaw cycle for the next ten days which i can accomplish in excel but thought this is a good way to learn to code. so my question is how should i do this, i have tried and failed with trying to pick out individual highs and lows data and define them as above or below freezing but i can't figure out how to pick out the right number my code for this part of the project is $json_line = file_get_contents("http://api.wunderground.com/api/{key}/geolookup/forecast10day/q/$zipcode.json"); $parsed_line = json_decode($json_line); echo $parsed_json->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'date'}->{'weekday'}; $temp_h = $parsed_line->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'high'}->{'farenheit'}; $temp_l = $parsed_json->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'low'}->{'farenheit'}; echo "Forecast for ${day} is:\n"; echo "High Temp is ${temp_h}<br />"; echo "Low Temp is ${temp_l}\n"; another road i was looking at going down was trying to do an array shift any help would be greatly appreciated thanks jeremy I am a total beginner in PHP and i am trying to fix a script i have. I am trying to put filter search boxes over every column (it is a products table). Once the search is made the entire row(s) should be displayed with the search term in it corresponding to the column it was made in. I am attaching a mockup of what i am trying to do. I know i am being a drag in this forum but i am really looking for the PHP code to do this. thanks |