PHP - Totally New To Php. Need Urgent Help With Form.
Basically, I have a series of radio buttons (wanted checkboxes) were people select either Latte, Mocha or Cappuccino. I have included a hidden field for a price and using that to bring in the prices and add them up.
Code: [Select] <label for"Latte">Latte <br />€ 2.15</label> <br /> <input type="radio" name="coffee" id="Latte" value="Latte"> <input name="LattePrice" type="hidden" value="2.15"> </p> <p> <label>Mocha <br /> € 2.25</label> <br /> <input type="radio" name="coffee" id="Mocha" value="Mocha"> <input name="MochaPrice" type="hidden" value="2.25"> </p> <p> <label>Cappucino <br /> €2.35</label> <br /> <input type="radio" name="coffee" id="Cappucino" value="Cappucino"> <input name="CappPrice" type="hidden" value="2.35"> </p> The next section they choose the size they want Small, Medium or Large. Code: [Select] <p> <label for="latteSmall">Small </label><img src="images/latte.png" alt="Small Latte" width="36" height="36"> <input type="radio" name="size" id="LatteSmall" value="Small"> <input name="SizePrice" type="hidden" value="0.00"> </p> <p> <label for="LatteMedium">Medium <br /> + € 0.25 </label> <img src="images/latte.png" alt="Medium Latte" width="42" height="42"> <input type="radio" name="size" id="LatteMedium" value="Medium"> <input name="SizePrice" type="hidden" value="0.25"> </p> <p> <label for="latteLarge">Large <br /> + € 0.45 </label> <img src="images/latte.png" alt="Large Latte" width="49" height="49"> <input type="radio" name="size" id="LatteLarge" value="Large"> <input name="SizePrice" type="hidden" value="0.45"> </p> I chose radio buttons to limit the users choice to one coffee and one size to make life easier (for myself). Ideally I wanted to use checkboxes but I could not get the php working. So basically, If Latte is selected echo it and the size. Code: [Select] echo "Hi ". $name. ", " . "here is your order:" . "<br /> <br />"; echo "<strong>" . "Coffee:" . "</strong>" . "<br />" . $size . " " . $coffee . "<br /><br />"; That works fine but the pricing is coming out wrong as I was using: Code: [Select] if ($coffee == "Latte") { $TotalCoffeePrice = $LattePrice + $SizePrice; echo "€ " . $TotalCoffeePrice . "<br /> <br />"; } elseif ($coffee == "Mocha") { $TotalCoffeePrice = $MochaPrice + $SizePrice; echo "€ " . $TotalCoffeePrice . "<br /> <br />"; } elseif ($coffee == "Cappucino") { $TotalCoffeePrice = $CappPrice + $SizePrice; echo "€ " . $TotalCoffeePrice . "<br /> <br />"; } What is happening here is if you select Latte and then Small it was adding Small, Medium and Large prices to the Latte. So instead of 2.15 I was getting 2.80 or something like that. Obviously when I recognised this I tried an array but that just went arseways!! Also, at the end of the php I was hoping to total up everything that they chose with: Code: [Select] $TotalPrice = ($TotalCoffeePrice + $SizePrice + $MuffinPrice + $SamboPrice); echo "<strong>" . "Total Price:" . "</strong>" . "<br />" . "€ " .$TotalPrice . "<br /><br />"; However, this was giving a total of 9.80 even when nothing was selected! Similar TutorialsHi, I have a school project and I would like to create a simple website (very simple) to ask some survey questions and record the answers into a text file. Could someone show me sample code that will present the question "Please discuss your best experience during the course:" presents a text box to provide the person a chance to respond and then appends the response to a file "experiences.txt" when the person selects a submit button. I have to do about 25 questions and will write the code and post an example of what I think it has to do. I just need some help getting started. I will be researching this for the next couple of weeks, anyone who can start pointing me in the right direction your help is greatly appreciated. If you feel you would be doing too much of my work for me, please point me toward a tutorial or guide document where I might be able to figure this out on my own. Thank you for the help! Mike Hi folks,
Please go easy on me - total newbie. I've read all sorts of stuff on the web about how to get up and running with PHP but even the basic instructions are too complicated for me!
Here's what I want to do:
I want to use PHP to generate dynamic web pages linked to a Microsoft Access 2007 database as a test on my laptop (no need to publish to the actual Internet). I am running Windows 7 Professional SP1.
I know I need to install PHP and a web server of sorts. I tried to get IIS7 working but was foxed by the requirement to use an admin account (I don't have the admin password and didn't know how to run things as admin from my own account).
I basically need a step-by-step guide that assumes I know nothing.
Sorry if this is a big ask,
Matt
hello. i have posted something similar before and people said i should go away and learn oop. I have since done the entire Linda training on oop, watched countless videos and build a photo gallery (from the training videos) but im still stuck on this silly little thing. so please please could some one help. thanks ok, so i have 2 classes. 1 called Pages and 1 called Templates. each page has an id for the layout it wants to use. so i want to get the layoutTemps_id from the pages class and use it in a function WHERE clause to get the correct layout for that page. I cant seem to pass the layoutTemps_id into my Templates class from my Pages Class ??? i tried using a global but couldnt get it to work. ANY IDEAS ?? thanks this is the Pages class function that gets all the information for each page. Code: [Select] public static function find_by_pageName($pName){ global $database; $sql = "SELECT * FROM ".self::$table_name." WHERE pageName='".$database->escape_value($pName)."'"; $result_array = self::find_by_sql($sql); return !empty($result_array) ? array_shift($result_array) : false; } that works just fine. it gets the $pName on the page and is different each time. i.e Code: [Select] $pName = "adminHome"; $page = Pages::find_by_pageName($pName); echo $page->id."<br />"; echo $page->layoutTemps_id.'<br/>'; so that all seems to work fine. now i want to use the $page->layoutTemps_id in my Templates class. this is the class class Templates extends Pages { this is the function im trying to write. i thought that because class Templates extends Pages i could put in $page->layoutTemps_id with no problem but in stuck. Code: [Select] public static function find_layoutTemp(){ $layoutTemps_id = Pages::layoutTemps_id; $sql = "SELECT * FROM ".self::$table_name." WHERE id='".$database->escape_value($layoutTemps_id)."'"; $result_array = self::find_by_sql($sql); return !empty($result_array) ? array_shift($result_array) : false; } this is the page where im echoing the layoutTemps_id Code: [Select] <?PHP require_once("../includes/initialize.php"); $temp = Templates::find_layoutTemp(); echo "layoutTemp id " .$temp->id . " <br />"; echo "layoutTemp name " .$temp->name ." <br />"; now, i'm 100% sure there's lots wrong with my code but i'm ill be happy if someone could help. thanks rick (I am not an expert or even a begineer at PHP, so sorry if none of this makes sense) Right ok, I have an invitation form built and tested working correctly between a php page and a mysql database and got the mail function to work but now the mail function is throwing all emails into the junk mail folder of outlook. The user of the invitation form has to enter a valid email address (the form has its own validation for each textbox and email has been set to required email address). So I have been asked to set up a mailto instead of using the mail function (dont ask me why...) And I cant, for the life of me, figure out how to get this to work. What I have thought of so far is: Index.html (Invitation page) V sendinvitation.php (previously the page with the mail function) now includes a confirmation of the data being sent to the database and a button to go to the next php V sendmail.php (I want this to be able to get the data from the database and then open up the users email client and pre populate the email with the body text) Is this even possible? If not, is there a reason why the email keeps getting thrown into the junk mail. Please, any help would be most appreciated! EDIT: Let me explain a bit more, just re-read over and its very brief (this probably will be too) I want to invitation form to submit the users data to my database in mysql, then when the form as been submitted, to be able to then grab the data and pre populate an email using variables that are in the php linked to the database (Im guess the php would go from POST to GET?) Please help me with this: with this code i have only fetched out the subjects and i need to fetch out value for the following too from the database 1. GRADE 2. Contious Assessment: 3. Exam Scores: 4. Exam Scores 5. Weighted Average: 6. Last Term Cummulative: 7. Cumulative (c+d)/2: 8. Comment: but now i can only get the foreach work for subject alone.. $l=mysql_query("SELECT * FROM result WHERE school_id='$id' AND student_reg_id='$st'") or die (mysql_error()); if (mysql_num_rows($l) > 0) { while ($row = mysql_fetch_array($l)) {// $pwrlist[$row['ajax_result_id']]=$row['subject']; //$ } $numpwr = count($pwrlist); $thresh = 3; $maxcols = 18; $cols = min($maxcols, (ceil(count($pwrlist)/$thresh))); $percol = ceil(count($pwrlist)/$cols); $powerchk = ''; $i = 0; foreach ($pwrlist as $id => $pwr) { if (($i>0) && ($i%$percol == 0)) { $powerchk .= "</td>\n<td valign='top'>";//echo "<br>"; } $powerchk .= " <table width='280px' class='hovertable'> <tr> <td width='251px' height='34' align='left' valign='middle' bgcolor='#D6DFEB'><span class='style19'><font size=2px>$pwr</font></span></td> <td width='19px' align='left' valign='middle' bgcolor='#D6DFEB'><span class='style1'>GRADE:</span></td> <td width='20px' align='left' valign='middle' bgcolor='#FFFFFF'><span class='style13'>B3</span></td> </tr> <tr> <td height='34' colspan='3' align='left' valign='top' bgcolor='#FFFFFF'><span class='style20'>» (a) Contious Assessment: 80<br /> » (b) Exam Scores: 90<br /> » (c) Weighted Average: 168<br /> » (d) Last Term Cummulative: 78<br /> » (e) Cumulative (c+d)/2: 123 </span></td> </tr> <tr> <td height='20' colspan='3' align='left' valign='top' bgcolor='#FFFFFF'><span class='style17'>Comment: His is a responsible boy</span></td> </tr> </table><br>\n"; $i++; } } I am creating a member site and I need help with coding the database. Here go the code Code: [Select] <?php function connect(){ $DB_USER = "root"; $DB_PASSWORD = ""; $DB_HOST = "localhost"; $dbc = mysql_connect ($DB_HOST, $DB_USER, $DB_PASSWORD) or $error = mysql_error(); mysql_select_db("membership") or $error = mysql_error(); mysql_query("SET NAMES `utf8`") or $error = mysql_error(); if($error){echo "<!-- $error -->";}} function disconnect_data(){ @mysql_close($dbc); @mysql_close(); } ?>I am suppose to fill it in with my database info but idk what to fill in! help me please! where do i enter the info! <?php $possibles[]; $alreadychosen[]; for ($i = 0; $i<20;$i++) $possibles =i+1; for (int $i = 0; $i<8; $i++) { $boolean= false; $randIndex=0; do { $randIndex = rand(1,20); for ($j = 0; $j< $i && !$hasInt; $j++) { if ($possibles[$randIndex] == $alreadyChosen[$j]) { $hasInt = true; } } } while ($hasInt); { $alreadyChosen = $possibles[randIndex]; echo($alreadyChosen); } for ($i = 0; $i<8;$i++) { if($alreadyChosen<10) { echo ('<a href="/mp/info130'+$i+'.htm"><img src="/mp/p130'+$i+'-1.jpg" height=180 width=120 align=left hspace=0 vspace=2 border=0 class=TopImages></a>'); } else if($alreadyChosen>10) { echo ('<a href="/mp/info13'+$i+'.htm"><img src="/mp/p13'+$i+'-1.jpg" height=180 width=120 align=left hspace=0 vspace=2 border=0 class=TopImages></a>'); it should select 8 images out of 20 but don't repeat please hI for all Am developping a script that allow to each user (seperatly ) upload or download his files and list all files in categories (such music or photos...) but i can 't achieve that the main problem is to upload files to server and store them in data base also i have to list for each user his files seperatly when he log in any idea please Hello dear friends , I'm under attack huge attack from spam bots and i need your help 1) i've a form with input text and input submit 2) no way to add html cause using js banned any < or > ..ect 3) the spam attack now post html code but it stored into database after automatically < and > removed as i mention in (2) okay add to your note i can't add captcha cuase my website for kids Now please allow me to explain this idea and let me know if it ture or there is another way else more simple 1) i will add hidden input with value shows "IP Number Of Poster" 2) by that way i will know the IP of the spammer 3) i will use php and mysql to create database table and store the IPs of spamming i collect so that when that spammer hit my website again , will not be able to view input form. What do you think ! is it right or bad solution or is there any any way the bad idea is that spam is not sure human cause it is stupid and post something meaningless and not ture and fake urls like this Code: [Select] theuzgfnpbmi, [url=http://gdtuaemvkpif.com/]gdtuaemvkpif[/url], [link=http://rsxtnszcpceq.com/]rsxtnszcpceq[/link], http://awpfgwtvqkdm.com/" theuzgfnpbmi, [url=http://gdtuaemvkpif.com/]gdtuaemvkpif[/url], [link=http://rsxtnszcpceq.com/]rsxtnszcpceq[/link], http://awpfgwtvqkdm.com/" please help if you have any suggestion or method how to stop such spammers thank you so much This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321874.0 hi for all am installing php security user mangement but i got some errors during install am using xampp 1.7.7 for windows but when i runed the script for the first time i got this message Warning: require_once(C:/xampp/htdocs/xampp/psumthemes/shared.js.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\xampp\psum\index.php on line 20Fatal error: require_once() [function.require]: Failed opening required 'C:/xampp/htdocs/xampp/psumthemes/shared.js.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\xampp\psum\index.php on line 20() any ideas please my document root is C:/xampp/htdocs I have an array and I'd like to find the most popular value in the array. example. $arr = array(1,1,1,1,2,2,3,4,5,5,5,5,5,5,5,3,4,198,10293,1,2); I would like only display 5 please. Okay so you may have noticed an earlier post from myself that problem have been fixed, Some background info, The website is currently on my test server so not connected to the internet. I have only been learning PHP for the last 3-4 days so I am fairly new to most things so please keep your explanations simple, The finished code here is being designed for use on large scale websites with a lot of users around 100,000+ per 24 hour period and therefor will need to be secure. Yet I have no idea how to do that, The script once finished will also be freely distributed and contributors will be fairly credited. I have some new problems that I need help fixing, So I am creating a PHP Blog connected to my MYSQL Database, Currently there is no admin backend that's a job for later but I do have the following files. index.php - This displays all blog posts for all my categorys news.php - This displays each blog post on there own config.php - This contains my server connect code I also have the following fields in my database articleid - Unique ID number of each blog post category - The category the blog post is in title - The title of each blog post body - The body of each post author - The name of the author date - date of posting But now I need to add some comments so can anyone please help out, The comments should only appear below the article on the 'news.php' page so I was hoping someone could write me a script to post and display the comments, (No login system needed I got that covered surprisingly.) if you can also give me a .sql file to add the needed tables to my database that would be greatly appreciated, Lastly would it be possible for someone to secure the script so it is invulnerable to SQL Injection attacks and any other form of attack that someone could pull off on the site. So bring on the code, Index.php Code: [Select] <?php include("config/config.php"); $data = mysql_query("SELECT * FROM blog ORDER by date ASC") or die(mysql_error()); while($row = mysql_fetch_array($data)) { echo "<table class='main'> <tr> <td> <a href='/news.php?articleid=" . $row['articleid'] . "' class='article_title'>" . $row['title'] . "</a> <p>" . $row['introduction'] . "</p></td><tr><td ALIGN='RIGHT' class='small'> Posted by:" . $row['author'] . ", on " . $row['date'] . ",</td></tr></table>"; } ?> Comments:I have removed all the junk out and left the basic script, news.php Code: [Select] <?php include("config/config.php"); $data = mysql_query("SELECT * FROM blog WHERE articleid = {$_GET['articleid']} ORDER by date ASC") or die(mysql_error()); while($row = mysql_fetch_array($data)) { echo "<table class='main'> <tr> <td> <a href='/news.php?articleid=" . $row['articleid'] . "' class='article_title'>" . $row['title'] . "</a> <p>" . $row['introduction'] . "</p></td><tr><td ALIGN='RIGHT' class='small'> Posted by:" . $row['author'] . ", on " . $row['date'] . ",</td></tr></table>"; } ?>Comments:So here's the complex bit if someone could please add the comments below the article here, Thanks again, Blaze, (Really bad PHP Programmer) Ok all I need some help with this. I have been stuck for two days. Basically I have a form that asks a registrant their gender and age, then my script spits out a list of race categories they qualify for. The situation calls for the registrant to be able to register for any category YOUNGER than them, but not older. Screen Shot #1 shows my database setup (this can be changed if you have any better ideas...) that holds the race category information. Here is the sql statement I am using to pull a female racer information, where $race_age is their submitted age. "SELECT * from counts where female=1 and $race_age < age_end and $race_age > age_start" This works, but doesn't pull any categories YOUNGER Than their age. I'm stumpped Thanks for any help in advance. hey ive got a page that lists a users bank accounts...when the user chooses to update an account it goes to a new page where they can edit the details...when it goes to this new page it takes the user's ID and the account ID with it in the URL (http://localhost/oswp/bank/updateaccounts.php?id=34&cid=1) so i know these variables are correctly being transferred. now when the user has made their changes and clicked the update button it should update the database and then re-locate back to the original page listing all accounts...to get back to this page and show the correct accounts for that user i thaught i needed to take the ID from the URL...give it a variable...and use it in the URL back to the original page. so for example the variable and update sql and re-locate code would look like this. $cid = $_GET['cid']; //updating the table $result=mysql_query("UPDATE accounts SET accno='$accno', pin='$pin', type='$type', name='$balance', balance='$balance', active='$active' WHERE accid=$id"); header("location:accounts.php?id=$cid"); however currently when the user clicks update and it tries to relocate back to the original page its not getting the variable in the URL. (http://localhost/oswp/bank/accounts.php?id=) and im getting the errors: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\uni\oswp\assignment\bank\accounts.php on line 26 's bank accounts Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\uni\oswp\assignment\bank\accounts.php on line 30 basically saying its expected a number up in the URL and its not finding one...but i dont know why...any ideas please its quite urgent. here is the relevant code for this section: Accounts.php: <a href="adminlogout.php">Logout</a><br /> <?php $id = $_GET['id']; if(!isset($_SESSION['myusername'])) { header("location:adminlogin.php"); } $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $db = 'bank'; $conn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($db); $result = mysql_query("SELECT * FROM customer WHERE cusid=$id"); $row2 = mysql_fetch_array($result); echo $row2['name'] . "'s bank accounts" . "<br><br>"; $result2 = mysql_query("SELECT * FROM accounts WHERE cusid=$id"); echo "<form method='post' action='accounts.php?id=$id'>"; while($row = mysql_fetch_array($result2)) { echo "<input type='hidden' value='$row[accid]' name='accid'>" . $row['accno'] . $row['name'] . $row['type'] . $row['balance'] . $row['active'] . "<a href='updateaccount.php?id=$row[accid]&cid=$id'>Update</a>" . "<br>"; } echo "</form>"; ?> updateaccounts.php: $id = $_GET['id']; $cid = $_GET['cid']; if(!isset($_SESSION['myusername'])) { header("location:adminlogin.php"); } $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $db = 'bank'; $conn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($db); if(isset($_POST['update'])) { $accno=$_POST['accno']; $pin=$_POST['pin']; $type=$_POST['type']; $name=$_POST['name']; $balance=$_POST['balance']; $active=$_POST['active']; // checking empty fields //if item field is empty if(empty($accno)) { echo "<font color='red'>account number field is empty.</font><br/>"; } elseif(empty($pin)) { echo "<font color='red'>pin field is empty.</font><br/>"; } elseif(empty($type)) { echo "<font color='red'>account type field is empty.</font><br/>"; } elseif(empty($name)) { echo "<font color='red'>account name field is empty.</font><br/>"; } elseif(empty($balance)) { echo "<font color='red'>balance field is empty.</font><br/>"; } elseif(empty($active)) { echo "<font color='red'>active field is empty.</font><br/>"; } else { //updating the table $result=mysql_query("UPDATE accounts SET accno='$accno', pin='$pin', type='$type', name='$balance', balance='$balance', active='$active' WHERE accid=$id"); header("location:accounts.php?id=$cid"); } } hello guys I need little help bro, I want to make application in which i want this look, I am from a company where we have over 12 companies license and all are those is renew after every year. so i want to make a application which will inform us 1 month before expireing their license. Mean if any company license is expire on 12 June, our application give us notification on 12 May. Could you please help me how can I do this? Thanks and regards Hey, I need a bit of help replacing some variables in a string. I know its done with preg_replace. Here is the string: Code: [Select] Header 1 <|header 2|> header 3 <b>header 4</b> I would like to get ONLY <|header 2|> from the above string. But "header 2" is variable so please its useless if the preg_replace isn't flexible to find whatever word is in there regardless. Thanks you. What is all dependent on PHP?
I mean lets say I removed echo from phps source code.
Then I add function my_echo() which is the exact same code basically, what all would I need to update to allow my_echo() to be implemented correctly
Obviously I would need to modify every one of my php scripts on my webserver to replace echo with my_echo, but is there anything else?
I know i could just append my_echo to phps source, or modify the echo function itself, but this is conceptually and thats not the actual process I'm looking for right now.
Any insight would be greatly appreciated!
|