PHP - Please Help Writing Small Php Calculator For My Website
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? Similar Tutorialsis 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? 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 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; }} ?> 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. 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. 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. 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; }
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 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 I'm trying to make a League of Legends (a video game) community website, both as a personal project and for practice. Now the game has a lot of champions, each of whom have 5 unique abilities. Now, I thought about manually inputting all the details about each champion into a MySQL database, but that would long and tedious, and I don't really have the time for it now. Also, the game patches very oftern (like, once every 2 weeks) which changes many of the stats, etc. of the champion, and it is not possible for me to keep manually updating these every time there is a patch. Fortunately, there is a League of Legends Wiki which has all the data I need in their specific champion pages, which they keep updated per patch. So I was wondering if there was any way to get the data from the divs in the wiki, and have it display on my site. What I want to do in my website is that whenever someone types a champion's name (in a post or whatever), I want it to display a hover-over dialog with some of the champions details. And a lot of other features such as that. In plain English I need a way to : > Tell PHP to go to the wiki's source code on a specific page > Find a specific div container > Get X data from there > Pass X data into a function to display the hover-over I think this way, I would not have to maintain a database as I can leech off the wiki's data. I have not coded anything like this before, so I would like a few pointers as to how to achieve this. Any help will be appreciated! Hey guys i have a contact form for my site working fine but when i receive the emails i get some unwanted texts after the email section. here they r : name1: ryan number: 343244 message1: hey email: ss@yahoo.com clearField: [type Function] label1: NAME label2: E-MAIL label3: PHONE label5: MESSAGE countField: 5 arrayLabel: undefined,NAME,E-MAIL,PHONE,undefined,MESSAGE i: 6 txtField: _level0.topmenu.page.pages.contactform.txtField5 _request: contact/email.php the script Code: [Select] <?php /***************************************************\ * PHP 4.1.0+ version of email script. For more * information on the mail() function for PHP, see * http://www.php.net/manual/en/function.mail.php \***************************************************/ // First, set up some variables to serve you in // getting an email. This includes the email this is // sent to (yours) and what the subject of this email // should be. It's a good idea to choose your own // subject instead of allowing the user to. This will // help prevent spam filters from snatching this email // out from under your nose when something unusual is put. $sendTo = "hey@email.com"; $subject = "helloy"; // variables are sent to this PHP page through // the POST method. $_POST is a global associative array // of variables passed through this method. From that, we // can get the values sent to this page from Flash and // assign them to appropriate variables which can be used // in the PHP mail() function. // header information not including sendTo and Subject // these all go in one variable. First, include From: $headers = "From: " . $_POST["firstName"] ." ". $_POST["lastname"] . "<" . $_POST["email"] .">\r\n"; // next include a replyto $headers .= "Reply-To: " . $_POST["email"] . "\r\n"; // often email servers won't allow emails to be sent to // domains other than their own. The return path here will // often lift that restriction so, for instance, you could send // email to a hotmail account. (hosting provider settings may vary) // technically bounced email is supposed to go to the return-path email $headers .= "Return-path: " . $_POST["email"]; // now we can add the content of the message to a body variable $message = $_POST['message']; $message = ""; foreach($_POST as $key=>$value) { $message .= $key.": ".$value."\n\r"; } // once the variables have been defined, they can be included // in the mail function call which will send you an email mail($sendTo, $subject, $message, $headers); ?> can some1 suggest me something iam a complete noob ! I'm trying to find the write coding to pull the First and Second words from the 2nd line and the entire 3rd line from this file and have them as $subject1 and $subject2 And I have no php background. http://www.weatherserver.net/text/CWTO/WOCN11.txt so $subject1 = WOCN11 CWTO and $subject2 = SPECIAL WEATHER STATEMENT I need help! I cant get this to write the correct way! What i need is based on the value of what is posted to the script it has to write it in the config file and also make a folder! Please help Code: [Select] <?php $start = '$uploadpath=\''; $structure = '../banner/images/'.$_POST['FOLDER'].'\';\n'; $myFile = "PHP/confup.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "<?\n"; fwrite($fh, $stringData); $stringData = "$start $structure"; fwrite($fh, $stringData); $stringData = "?>\n"; fwrite($fh, $stringData); fclose($fh); // Desired folder structure // To create the nested structure, the $recursive parameter // to mkdir() must be specified. if (!mkdir($structure, 0777, true)) { die('Failed to create folders...'); } // ... ?> Ok, I know how to write to a file, but what I'm looking for is to check if a line of code exists, and if it is, don't recreate it. It would also be nice to not recreate the file either. Code: [Select] $file = fopen("index.html", "w"); fwrite($file,"This is a line of text"); fclose($file); I have written some code to past information from one page to a diffrent page however all the variables are sent over but they are not writting to the database could anyone help me out please .... $ud_P_Id = $_POST['ud_P_Id']; $ud_LastName = $_POST['ud_LastName']; $ud_FirstName = $_POST['ud_FirstName']; $ud_GroupCode=$_POST['ud_GroupCode']; $ud_P_Unit1=$_POST['ud_P_Unit1']; $ud_P_Unit2=$_POST['ud_P_Unit2']; $ud_P_Unit3=$_POST['ud_P_Unit3']; $ud_P_Unit6=$_POST['ud_P_Unit6']; $ud_P_Unit14=$_POST['ud_P_Unit14']; $ud_P_Unit20=$_POST['ud_P_Unit20']; $ud_P_Unit27=$_POST['ud_P_Unit27']; $ud_P_Unit28=$_POST['ud_P_Unit28']; $ud_P_Unit42=$_POST['ud_P_Unit42']; $ud_P_Unit10=$_POST['ud_P_Unit10']; $ud_P_Unit11=$_POST['ud_P_Unit11']; $ud_P_Unit12=$_POST['ud_P_Unit12']; $ud_P_Unit13=$_POST['ud_P_Unit13']; $ud_P_Unit1454=$_POST['ud_P_Unit1454']; $ud_P_Unit15=$_POST['ud_P_Unit15']; $ud_P_Unit16=$_POST['ud_P_Unit16']; $ud_P_Unit17=$_POST['ud_P_Unit17']; $ud_P_Unit18=$_POST['ud_P_Unit18']; $con = mysql_connect('localhost', 'lccstude_progre', '********'); $db= "lccstude_pro"; if (! $con) die("Couldn't connect to MySQL"); mysql_select_db($db , $con) or die("Couldn't open $db: ".mysql_error()); mysql_query("UPDATE BTECL31113 SET FirstName='$ud_FirstName' , LastName='$ud_LastName' , GroupCode='$ud_GroupCode' , Unit1='$ud_P_Unit1' , Unit2='$ud_P_Unit2' , Unit3='$ud_P_Unit3' , Unit6='$ud_P_Unit6' , Unit14='$ud_P_Unit14' , Unit20='$ud_P_Unit20' , Unit27='$ud_P_Unit27' , Unit28='$ud_P_Unit28' , Unit42='$ud_P_Unit42' , Unit10='$ud_P_Unit10' , Unit11='$ud_P_Unit11' , Unit12='$ud_P_Unit12' , Unit13='$ud_P_Unit13' , Unit1454='$ud_P_Unit1454' , Unit15='$ud_P_Unit15' , Unit16= $ud_P_Unit16' , Unit17='$ud_P_Unit17' , Unit18='$ud_P_Unit18' WHERE P_Id='$ud_P_Id'"); echo "Record Updated"; mysql_close($con); Please any help would be great Hey Guys. I am trying to write to the file depending on which condition is met. The code works fine on my local machiene but not on my remote server. I have also tried to output any error messages to see if it would output anything, and I don't get anyting on my browser. Can anyone help me with this issue? Thanks <?php if($_SERVER['REQUEST_METHOD'] == "POST") { isset($_POST['interfax']) ? $option= "interfax" : $option= ""; isset($_POST['metrofax']) ? $option= "metrofax" : $option= ""; switch ($option) { case 'interfax': $file = "fax.php"; $fax_client = "interfax"; if(file_put_contents($file, "<?php ".'$fax_client = "' . $fax_client . '"'." ?>")) { echo "Successful"; } else { die("Can't write file"); } break; // By defualt all the orders go to metrofax so by selecting the variable it resets it self case 'metrofax': $file = "fax.php"; $fax_client = "metrofax"; file_put_contents($file, "<?php ".'$fax_client = "' . NULL . '"'." ?>"); break; } } ?> <form action="#" method="POST"> <input type="radio" name="interfax" value="interfax">Switch To Interfax<br> <input type="radio" name="metrofax" value="metrofax">Switch To Metrofax<br> <input type='submit' name="submit" > I'm writing a script that takes user input from a html form and updates the database with the new data. In this example the user is updating the data about the university they attend. The problem with this is, the script to update the database with the new information appears to be not working - the new data is not being added to the database. The SQL queries used in the script work in phpMyadmin, and the variables - $uni and $username - contain the data the correct data. This has me stumped, could someone look over this for me please and tell me what is going wrong here. Code: [Select] <?php include 'connect.php'; session_start(); $_SESSION['username']; if(!(isset($_SESSION['login']) && $_SESSION['login']!= " ")){ header("Location: login.php"); } $username = $_SESSION['username']; $tablename = 'usr_test'; $uni = $_POST['uni']; $uni = stripslashes($uni); $uni = mysql_real_escape_string($uni); $uni = trim($uni); if(isset($uni)) { $username = $_SESSION['username']; $loc = mysql_query("SELECT * FROM usr_test WHERE usr = '$username'"); if (mysql_num_rows($loc) == 0) header("Location:notlogged.php"); else { extract(mysql_fetch_array($loc)); mysql_query("UPDATE usr_test SET uni = ('$uni') WHERE usr = '$username'") or die (mysql_error()); header("Location:profile.php"); } } ?> I don't think the start of my code is right?! Code: [Select] echo '<button onclick=\"gohere(viewpub.php?PubID='.$row['PubID'].')" id="button" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">View Pub</span></button>'; Please help?! |