PHP - Im A Beginner. Basic Php Calculator
First of all hi everyone, this is my first post as you can see. And i have my first task in PHP, now i warn you i have no experience or know-how whatsover in PHP so please bear with me.
My first task is to extend some PHP code to add some functions. the code weve been given already is capable of mutiplication of two variables x and y. Here it is anyway. 1. View the code and copy/paste it into an editor and save it to your own workspace. 2. Extend the script to perform the four basic arithmetic functions : +, -, *, / and return a result. 3. Extend the script again to move the calculations into a function and make use of this function. Code: [Select] <?php /* ====================================================== PHP Calculator example using "sticky" form (Version 1) ====================================================== Author : P Chatterjee (adopted from an original example written by C J Wallace) Purpose : To multiply 2 numbers passed from a HTML form and display the result. input: x, y : numbers calc : Calculate button pressed Date: 15 Oct 2007 */ // grab the form values from $_HTTP_POST_VARS hash extract($_GET); // first compute the output, but only if data has been input if(isset($calc)) { // $calc exists as a variable $prod = $x * $y; } else { // set defaults $x=0; $y=0; $prod=0; } ?> <html> <head> <title>PHP Calculator Example</title> </head> <body> <h3>PHP Calculator (Version 1)</h3> <p>Multiply two numbers and output the result</p> <form method="get" action="<?php print $_SERVER['PHP_SELF']; ?>"> x = <input type="text" name="x" size="5" value="<?php print $x; ?>"/> y = <input type="text" name="y" size="5" value="<?php print $y; ?>"/> <input type="submit" name="calc" value="Calculate"/> <input type="reset" name="clear" value="Clear"/> </form> <!-- print the result --> <?php if(isset($calc)) { print "<p>x * y = $prod</p>"; } ?> </body> </html> Firstly how do i run this code, i have Xamp installed if thats any good? Secondly, do i need two seperate files. i.e. calculator.php for the php code and calculator.html for the form? Thirdly i have no idea how to implement the divide, add and subtract functions. should i do a drop down menu where the user should select what operator they want? or is it more simple than that. Any help greatly appreciated. Please let me know if this post is okay. Similar TutorialsIs this possible? I have around 2 weeks for a computer science project and I want to do this in PHP. However, I have just started learning PHP, and since I'm so short on time I'm going to see if I can learn how to code this while learning basics of PHP. So basically, can anyone give me a simple and good way of starting this? I have no idea where to begin. I was thinking of doing rooms in a coordinate system with North, South, East, West buttons and a pick up item button and an attack button. So can you guys help? I would also like to know how to make buttons in HTML or anything that goes with Apache 2, I have no idea how that works. Right now I have PHP set up with Apache 2, so I can navigate to the file with the code in the browser and run the code. Im after a little bit of help with two things in my code. www.1pw.co.uk/demo2.php 1) getting an image to appear opposed to just the filename. where and how in my code should i put <img src="filename" /> in the img column of mysql database i am just listing filenames. should i wrap these in the html above instead? 2) how can i get my calculator to behave? i get the correct tally when checking out (using order.php), but as you will see from the link provided the calculator does not work properly, in demo2.php -- addtocart2.php -- Code: [Select] <?php define('INCLUDE_CHECK',1); require "../connect2.php"; if(!$_POST['img']) die("There is no such product!"); $img=mysql_real_escape_string(end(explode('/',$_POST['img']))); $row=mysql_fetch_assoc(mysql_query("SELECT * FROM internet_shop WHERE img='".$img."'")); $jsonArr = array('img' => $row['img'], 'status' => 1, 'id' => $row['id'], 'price' => $row['price'], 'txt' => ' <table width="100%" id="table_'.$row['id'].'"> <tr> <td width="40%">'.$row['img'].'</td> <td width="20%">'.$row['name'].'</td> <td width="10%">$'.$row['price'].'</td> <td width="15%"> <select name="'.$row['id'].'_cnt" id="'.$row['id'].'_cnt" onchange="change('.$row['id'].');"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option></slect> </td> <td width="15%"><a href="#" onclick="remove('.$row['id'].');return false;" class="remove">remove</a></td> </tr> </table>'); echo json_encode($jsonArr); ?> --- demo2.php --- Code: [Select] <?php define('INCLUDE_CHECK',1); require "connect2.php"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>shop</title> <link rel="stylesheet" type="text/css" href="demo.css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> <script type="text/javascript" src="jquery.ui.main.js"></script> <!--[if lt IE 7]> <style type="text/css"> .pngfix { behavior: url(pngfix/iepngfix.htc);} .tooltip{width:200px;}; </style> <![endif]--> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script> <script type="text/javascript" src="simpletip/jquery.simpletip-1.3.1.pack.js"></script> <script type="text/javascript" src="script2.js"></script> </head> <body> <div id="main-container"> <div class="tutorialzine"> <h1>Shopping cart</h1> <h3>The best products at the best prices</h3> </div> <div class="container"> <span class="top-label"> <span class="label-txt">Products</span> </span> <div class="content-area"> <div class="content drag-desired"> <?php $result = mysql_query("SELECT * FROM internet_shop"); while($row=mysql_fetch_assoc($result)) { echo '<div class="product"><a href="#" class="item"><img src="img/products/'.$row['img'].'" alt="'.htmlspecialchars($row['name']).'" width="128" height="128" class="pngfix" /></a></div>'; } ?> <div class="clear"></div> </div> </div> <div class="bottom-container-border"> </div> </div> <div class="container"> <span class="top-label"> <span class="label-txt">Shopping Cart</span> </span> <div class="content-area"> <div class="content drop-here"> <div id="cart-icon"> <img src="img/Shoppingcart_128x128.png" alt="shopping cart" class="pngfix" width="128" height="128" /> <img src="img/ajax_load_2.gif" alt="loading.." id="ajax-loader" width="16" height="16" /> </div> <form name="checkoutForm" method="post" action="order.php"> <div id="item-list"> </div> </form> <div class="clear"></div> <div id="total"></div> <div class="clear"></div> <a href="" onclick="document.forms.checkoutForm.submit(); return false;" class="button">Checkout</a> </div> </div> <div class="bottom-container-border"> </div> </div> </div> <div class="bowlpic"> </div> </body> </html> -- script2.js -- Code: [Select] var purchased=new Array(); var totalprice=0; $(document).ready(function(){ $('.product').simpletip({ offset:[40,0], content:'<img src="img/ajax_load.gif" alt="loading" style="margin:10px;" />', onShow: function(){ var param = this.getParent().find('img').attr('src'); if($.browser.msie && $.browser.version=='6.0') { param = this.getParent().find('img').attr('style').match(/src=\"([^\"]+)\"/); param = param[1]; } this.load('ajax/tips.php',{img:param}); } }); $(".product img").draggable({ containment: 'document', opacity: 0.6, revert: 'invalid', helper: 'clone', zIndex: 100 }); $("div.content.drop-here").droppable({ drop: function(e, ui) { var param = $(ui.draggable).attr('src'); if($.browser.msie && $.browser.version=='6.0') { param = $(ui.draggable).attr('style').match(/src=\"([^\"]+)\"/); param = param[1]; } addlist(param); } }); }); function addlist(param) { $.ajax({ type: "POST", url: "ajax/addtocart2.php", data: 'img='+encodeURIComponent(param), dataType: 'json', beforeSend: function(x){$('#ajax-loader').css('visibility','visible');}, success: function(msg){ $('#ajax-loader').css('visibility','hidden'); if(parseInt(msg.status)!=1) { return false; } else { var check=false; var cnt = false; for(var i=0; i<purchased.length;i++) { if(purchased[i].id==msg.id) { check=true; cnt=purchased[i].cnt; break; } } if(!cnt) $('#item-list').append(msg.txt); if(!check) { purchased.push({id:msg.id,cnt:1,price:msg.price}); } else { if(cnt>=3) return false; purchased[i].cnt++; $('#'+msg.id+'_cnt').val(purchased[i].cnt); } totalprice+=msg.price; update_total(); } $('.tooltip').hide(); } }); } function findpos(id) { for(var i=0; i<purchased.length;i++) { if(purchased[i].id==id) return i; } return false; } function remove(id) { var i=findpos(id); totalprice-=purchased[i].price*purchased[i].cnt; purchased[i].cnt = 0; $('#table_'+id).remove(); update_total(); } function change(id) { var i=findpos(id); totalprice+=(parseInt($('#'+id+'_cnt').val())-purchased[i].cnt)*purchased[i].price; purchased[i].cnt=parseInt($('#'+id+'_cnt').val()); update_total(); } function update_total() { if(totalprice) { $('#total').html('total: $'+totalprice); $('a.button').css('display','block'); } else { $('#total').html(''); $('a.button').hide(); } } -- order2.php -- Code: [Select] <?php define('INCLUDE_CHECK',1); require "connect2.php"; if(!$_POST) { if($_SERVER['HTTP_REFERER']) header('Location : '.$_SERVER['HTTP_REFERER']); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="demo.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script> <script type="text/javascript" src="simpletip/jquery.simpletip-1.3.1.pack.js.txt"></script> <script type="text/javascript" src="script2.js"></script> </head> <body> <div id="main-container"> <div class="container"> <span class="top-label"> <span class="label-txt">Your order</span> </span> <div class="content-area"> <div class="content"> <?php $cnt = array(); $products = array(); foreach($_POST as $key=>$value) { $key=(int)str_replace('_cnt','',$key); $products[]=$key; $cnt[$key]=$value; } $result = mysql_query("SELECT * FROM internet_shop WHERE id IN(".join($products,',').")"); if(!mysql_num_rows($result)) { echo '<h1>There was an error with your order!</h1>'; } else { echo '<h1>You ordered:</h1>'; while($row=mysql_fetch_assoc($result)) { echo '<h2>'.$cnt[$row['id']].' x '.$row['name'].'</h2>'; $total+=$cnt[$row['id']]*$row['price']; } echo '<h1>Total: $'.$total.'</h1>'; } ?> <div class="clear"></div> </div> </div> <div class="bottom-container-border"> </div> </div> </div> </body> </html> There's one that I've found...but I'm just struggling applying it to what I'm doing. The idea is to have x number of teams, all starting with 1000 Ranking points. If team A plays team B and wins 1-0, team A should increase by 30 points, and team B should decrease by 30 points? (I think.. ) Then to rank the teams based on their points. The main problem is, I'd like to use a form to edit the teams. I've got as far as a drop down menu to choose the teams, and then Home goals and Away goals. It will already define what is a win/draw/loss. The Calculator code is: <?php class elo_calculator { public function rating($S1,$S2,$R1,$R2) { if (empty($S1) OR empty($S2) OR empty($R1) OR empty($R2)) return null; if ($S1!=$S2) { if ($S1>$S2) { $E=120-round(1/(1+pow(10,(($R2-$R1)/400)))*120); $R['R3']=$R1+$E; $R['R4']=$R2-$E; } else { $E=120-round(1/(1+pow(10,(($R1-$R2)/400)))*120); $R['R3']=$R1-$E; $R['R4']=$R2+$E; }} else { if ($R1==$R2) { $R['R3']=$R1; $R['R4']=$R2; } else { if($R1>$R2) { $E=(120-round(1/(1+pow(10,(($R1-$R2)/400)))*120))-(120-round(1/(1+pow(10,(($R2-$R1)/400)))*120)); $R['R3']=$R1-$E; $R['R4']=$R2+$E; } else { $E=(120-round(1/(1+pow(10,(($R2-$R1)/400)))*120))-(120-round(1/(1+pow(10,(($R1-$R2)/400)))*120)); $R['R3']=$R1+$E; $R['R4']=$R2-$E; }}} $R['S1']=$S1; $R['S2']=$S2; $R['R1']=$R1; $R['R2']=$R2; $R['P1']=((($R['R3']-$R['R1'])>0)?"+".($R['R3']-$R['R1']):($R['R3']-$R['R1'])); $R['P2']=((($R['R4']-$R['R2'])>0)?"+".($R['R4']-$R['R2']):($R['R4']-$R['R2'])); return $R; }} ?> Hi there, I'm trying to create a land transfer tax calculator. The formula is to be as follows Up to and including $55,000.00 0.5% plus $55,000.01 to $400,000.00 1.0% plus Over $400,000.00 2.0% FOR EXAMPLE: A home with a consideration value of $500,000.01 MLTT Rate Calculation 0 to $55,000.00 55,000.00 x 0.005 = $275.00 $55,000.01 to $400,000.00 $344,999.99 x 0.01= $3,450.00 $400,000.01 to $500,000.00 $99,999.99 x 0.02= $2,000.00 Total MLTT= $5,725.00 what I have so far is Code: [Select] <form method="GET" name="tax" action="http://www.abc.com/what-can-i-afford/"> <input type="hidden" name="comp_form" value="1"> <table cellpadding="2" cellspacing="0" border="0" width="100%" align="center"> <tr valign="top" bgcolor="#eeeeee"> <td align="right" width="150px">Home Cost</td> <td><input type="text" size="10" name="home_cost" value="<?php echo $home_cost; ?>"> (In Dollars)</td> </tr> <tr><td> </td></tr> <tr><td><input type="submit" value="Calculate"><br> <?php if ($comp_form) { print("<a href=\"" . $_SERVER['PHP_SELF'] . "\">Start Over</a><br>"); } ?><br></td> </tr> </table> <?php /* -----------------------------------------------*/ /* Affordability Calc */ /* Set Form DEFAULT values */ $home_cost = 0; /* Set the USER INPUT values */ if (isset($_REQUEST['comp_form'])) { $home_cost = $_REQUEST['home_cost']; if ($home_cost >= 55000) { $MLTT = 55000 * 0.005; if ( ($home_cost >= 55000.01) && ($home_cost <= 400000.01) ) { $MLTT = $MLTT + (($home_cost - 55000)*0.01); if ( ($home_cost >= 400000.01) && ($home_cost <= 500000) ) { $MLTT = $MLTT + (($home_cost - 400000.01)*0.02); } } echo $MLTT; } ?> <h2>MLTT is:<?php $MLTT ?></h2> <?php } ?> I'm only getting 275??? Please help as I'm unsure how to break up the home amount and perform each calculation is there a way for php to calculate age based on birthdate with mm/dd/yyyy format? or do I need some converter? if so, how? Website: http://novacms.vacau.com/index.php I'm trying to make a calculator for this game I play, it's fully developed, but with one bug. It doesn't do the math right. $goal = The amount of EXP (Experience Points) someone wants to get $exp = The amount of EXP they currently have $npcs_exp["exp"] = The amount of EXP the monster has But, when they enter in the information, the calculation is all screwed up. When I do it, it seems to give me the same number EACH time. The part where the calculation "goes down". Remember, I'm trying to see how many times you need to kill a NPC to achieve your goal. //math $npc_exp_extract = mysql_query("SELECT exp FROM npcs WHERE name='$npc'"); $npcs_exp = mysql_fetch_assoc($npc_exp_extract); $amount = $goal / $npcs_exp["exp"]; Full code: <?php $exp = $_POST["exp"]; $npc = $_POST["npc"]; $goal = $_POST["goal"]; mysql_connect("removed", "removed", "removed"); mysql_select_db("a2248602_npcs"); if(!$goal || !$npc || !$exp) { echo "<center><form action='index.php' method='POST'>GOAL: <input type='text' name='goal'> Current XP: <input type='text' name='exp'>"; echo "NPC: <select name='npc'>"; $npc_extract = mysql_query("SELECT * FROM npcs"); while($npcs = mysql_fetch_assoc($npc_extract)) { echo "<option name='". $npcs['name'] ."'>". $npcs['name'] ."</option>"; } echo "</select> <input type='submit'></form></center>"; } else { //math $npc_exp_extract = mysql_query("SELECT exp FROM npcs WHERE name='$npc'"); $npcs_exp = mysql_fetch_assoc($npc_exp_extract); $amount = $goal / $npcs_exp["exp"]; if($amount=="1") { echo "You will need to kill a <b/>". $npc ."</b> <b>". $amount ."</b> more time. You earn ". $npcs_exp["exp"] ." XP for each kill from this NPC. | <a href='index.php'>Do another</a><br/><br/>"; } else { echo "You will need to kill a <b/>". $npc ."</b> <b>". $amount ."</b> more times. You earn ". $npcs_exp["exp"] ." XP for each kill from this NPC. | <a href='index.php'>Do another</a><br/><br/>"; } } echo "<center>Made by Zaros from <a href='creation-x.net'>Creation-X</a></center>"; ?> Mod edit: DB credentials removed. Hey there, I recently started working on a PHP calculator, I tryed testing it out and the script is not executing... *NOTE* I found the error, I forgot to assign values to the options, all is good now Code: [Select] <?php /* Script Created by: Far Cry Started: August 20th, 2010 10:51 PM PST Completed */ $title = "Calculator"; $form = "<form action='calculator.php' method='POST'> <table> <tr> <td><input name='firstnumber' type='text'></td> </tr> <tr> <td><input name='secondnumber' type='text'></td> </tr> <tr> <td><select name='operation'> <option name='multiply'>*</option> </select></td> </tr> <tr> <td><input name='submitbtn' type='submit' value='Calculate!'></td> </tr> </table> </form>"; if ($_POST['submitbtn']){ $first = ($_POST['firstnumber']); $last = ($_POST['secondnumber']); $operation = ($_POST['operation']); } if ($operation == 'multiply'){ echo"The answer is " . $first * $last . $form; } echo $form; ?> Thanks in advance. hi ! I'm not a PHP master, now i'd like to program an online calculator on my website. it's not the classical calculator with + / - / x / ln etc... but a specific, simple though, calculator. I'd like even to be able to export the results of the calculations into a xls or csv file (that would be the next step) Is that possible to do that with PHP ? or i should look more at javascript or java (dont like that idea) or flash etc... Thanks for your replies ! Hi! Need some help with a piece of code. New to this, so it is quite a pain in the ass! I need to make a code that shows the what spare change you should give back. so for example. when i put in 7 it should give back: 1 x 5 euro 1 x euro Which it does. but i have some trouble putting in the 1 euro's. for example when i put in 21 it gives back 2 x 10 euro Who can help me out? <?php function results($value) { if ($value >= 10) { echo floor($value / 10) . ' X 10 euro ' . PHP_EOL; $modulf = $value % 10; if ($modulf >= 5) { echo floor($modulf / 5) . ' X 5 euro ' . PHP_EOL; $modult = $modulf % 5; if ($modult >= 2) { echo floor($modult / 2) . ' X 2 euro ' . PHP_EOL; } } } else if ($value >= 5) { echo floor($value / 5) . ' X 5 euro ' . PHP_EOL; $modult = $value % 5; if ($modult >= 2) { echo floor($modult / 2) . ' X 2 euro ' . PHP_EOL; } } else if ($value >= 2) { echo floor($value / 2) . ' X 2 euro ' . PHP_EOL; } else if ($value >= 1) { echo floor($value / 1) . ' X 1 euro ' . PHP_EOL; } } if (count($argv) > 1) { $input = $argv[1]; if (!(is_numeric($input))) { echo 'Geen wisselgeld' . PHP_EOL; } else { $input = intval($argv[1]); if ($input !== 0) { results($input); } else { echo 'Geld wisselgeld' . PHP_EOL; } } } else { echo 'Geen wisselgeld' . PHP_EOL; }
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 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 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. 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 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? 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. 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? 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 I need a PHP function to which I pass two postcodes and it works out the road distance, I dont mind using google or any other API I have managed to fing JS ways and php functions using crow route but I really really need a traffic distance in PHP Please advice, Help Thank you Hello People. I would like to build a small calculator in php for my website. Basically what it does is give a form to the user that looks like this The formula is as follows. number_from_box1 * number_from_box2 =result1 then take result1 *52 =result2 now take 60,000 /result2 =result3 Take result3 and make it a number with only 2 decimal places =result4 Then display the result on the form like this Your warranty would be "result4" years I know that there are some really good coders on here. Please could one of you talented people tell me what is the php to do the above on my site? |