Jump to content

NewbieBryan

Members
  • Posts

    19
  • Joined

  • Last visited

    Never

Everything posted by NewbieBryan

  1. My problem is fairly basic, I have created an input page for some financial calcs and this I then send to my "engine" page that does some pretty advanced PHP calcs (well advanced for me anyway ) and displays a resultant page... So far so good, Assuming my audience is impressed and wants to print out the page they hit print and the page is sent to the printer.... with @#$@#$@# header and footer info.... Which really makes all my clean output look terrible. Now it is fairly easy to go to the browsers print setings and delete the header and footer info and the problem is solved... BUT that sort of kills headers and footers for that browser permanatly... Is there some way of customising the print (through code) to ignore headers and footers for only MY app (either via code on the page or even manaual browser side) Tx
  2. http://www.tizag.com/mysqlTutorial/mysqlfetcharray.php :-[sorry GingerRobot, I have been battling with that one so so I had progressed to the next page: Correct (incorrect) link above... Have headed over to the tutorials section, they look great - Thank you for the advice - Have a great Sunday..
  3. Tx GingerRobot, Removed that line and it worked like a charm:... Bit frustrating though, I am teaching myself PHP and MySQL and have been using this site as a reference. http://www.tizag.com/mysqlTutorial/mysqlselect.php This is not the first time that some of the code example has been "not 100% correct".... Are there any other sites that you could point me to, and or "learning" suggestions? Tx again, Bryan
  4. This piece of code loops through a table that I have and returns all the info stored therin, EXCEPT for the first row in the table. From my basic grasp of arrays I know (read:think) that I need to subtract "1" from somewhere to get it to show all the results but I am battling. Any help would be appretiated. $query = "SELECT * FROM $DBtable"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo $row['ID'] . "---". $row['First'] . "---". $row['Sur'] . "---". $row['Com']; echo "<p>"; }
  5. Tx Box - Works like a charm: Feel like a right idiot now.....
  6. What I want to do is set the initial value of an input block based on a variable; I have tried a couple of things and am possitive that i am missing something elementary.... The default for the 3 test forms below is 1 - BLANK 2 - $name (the word not the variable) 3 - $name (the word not the variable) Where am I going wrong (tx in advance) <?php //set var name $name = "Bryan"; //Checking my vaiable is set echo "Var_name set to " . $name ?> <html> <body> <P>------------------------------------------------------------ FORM1 <form action="myengine.php" method="post"> Event:<input type="text" name="Event" value="<?php $name ?>" /> <P> <input type="submit" /> </form> <P>------------------------------------------------------------ FORM2 <form action="myengine.php" method="post"> Event:<input type="text" name="Event" value="$name" /> <P> <input type="submit" /> </form> <P>------------------------------------------------------------ FORM3 <form action="myengine.php" method="post"> Event:<input type="text" name="Event" value=$name /> <P> <input type="submit" /> </form> </html> </body>
  7. Tx cunoodle2... MUCH cleaner than the way I was trying to do it.
  8. Apologies Crayon Violent, it is 03h00 here local time and my brain is fried. The error is exactly that, I can't seem to be able to figure where to insert the last } ... I have though on a couple of occasions managed to get the thing into an endless loop where is displays 1 ODD Number! . . . . and repeat until I terminate the window.
  9. I have two sets of code This one calculates if a number is odd or even <?php // let's say you have a number $number = 24; // to test whether $number is odd you could use the arithmetic // operator '%' (modulus) like this if( $odd = $number%2 ) { // $odd == 1; the remainder of 25/2 echo 'ODD Number!'; } else { // $odd == 0; nothing remains if e.g. $number is 48 instead, // as in 48 / 2 echo 'EVEN Number!'; } ?> This one adds 1 to a number until 5 <?php $i=1; while($i<=5) { echo "The number is " . $i . "<br />"; $i++; }; ?> I tried combining them but keep on getting errors; where am I messing up? Erroneous code below <?php $i=1; while($i<=5) { echo "The number is " . $i . "<br />"; if( $odd = $i%2 ) { echo 'ODD Number!'; } else { echo 'EVEN Number!'; $i++; }; ?>
  10. I have a requirement whereby I need to update the price on items on my site: The pricing info is held is a very basic table with just 3 items: UniqueID | Description and | Price I have created an update for which works fine by displaying a table with the above items in it On the same page there is a form where I can input the Unique ID, Updated Description and Updated Price. Hitting Sumbit updates the Db and the webpage is up to date again. Now my items are very simple: Eg 1 Brick 0.87 2 Rock 1.22 but this got me to thinking; What would happen in had a very complex description - lets say 30 or 40 words and I discovered after entering the data I had made a typo. Well, I guess I go into the backend and change the raw data but that is a bit of an overkill to what should be a simple problem. so that leaves me with 2 choices (as far as I can tell) create another form where I enter the UniqueID which in turn goes to another page with text input blocks pre-poulated from the database (value = fromdB) or and this is the part where my logic is failing me and I need some help When I create my table I would like to dynamically include a 4th column with the choice EDIT If I push EDIT this would then take me to a page/section where the Description and price fields are prepopulated and all I would have to do is make the relevant (hopefully small change) - hit submit and update the db. Any advice on how to go about this would be greatly appretiated. Tx Bryan
  11. Worked like a charm, tx again Ignace - I really appretiate the assistance.
  12. Great, tx Ignace, Looking at the raw data in the dB I see that it is displayed naturally (ie: as it was written) but I assume the /n and whatnot are "hidden" when viewing the PhpMyadmin but this is a great start. Next bit; When I pull the data to display I am using the following echo "<tr>"; echo "<td>" . $row['Comment'] . "</td>"; echo "<td>" . $row['Author'] . "</td>"; echo "</tr>"; That works great as is; but Can I now be "clever" and insert nl2br in there somewhere? Maybe: . $row[nl2br('Comment')]
  13. Hi All, I have created an application that collects information for various people (form submissions) and writes this back to a MySQL db (VARCHAR) All works well but when I read back the "Comments" table then the string is improperly formated, well rather it doesn't remember the formatting. So - for example: If someone typed in: Hello all, I have the following A dog, A Cat when I write it to screen it displays Hello all,I have the following A dog,A Cat Is there a manner in which I can keep the formatting (spaces, etc): Tx
  14. Ok, Let me reply to my own post: Reason was user stupidity..... I was just revieving my code and saw that good old copy and paste had caught me out. ('$_POST[Event]','$_POST[Description]','$_POST[Priority]'),'$_POST[DateAdded]','$_POST[DateDue]','$_POST[spare]')))"; Way to many brackets in there )))))) But, still, in the interests of "good coding" Is the syntax in the code above [adding records to a Database] the most efficient way one would do this? Also, to prevent Code injections how would I apply the mysql_real_escape_string($abc) most effectivly? w
  15. I have created a simple form to "learn" as I progress with Php. So far I have been able to insert data (text and numbers) from a form to the db but last night for the first time I tried entering dates. ??? My input form code is this: <html> <body> <form action="dbinsert.php" method="post"> Event :<input type="text" name="Event" /> <P> Description :<input type="text" name="Description" /> <P> Priority :<input type="text" name="Priority" /> <P> DateAdded :<input type="text" name="DateAdded" /> <P> DateDue :<input type="text" name="DateDue" /> <P> Spare <input type="text" name="Spare" /> <P> <input type="submit" /> </form> <P><P> <a href="http://www.mysite/dbview.php">View Database</a> <P> </body> </html> Now all the text value transmit ok but when I add dates in the relevant fields I get the following error The (typed) syntax I have tried when entering my dates is 20090709 and 2009-007-09 and 2009/07/09 with no luck. The insertpage is this <?php $con = mysql_connect("server","uname","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("playdb", $con); $sql="INSERT INTO todo (Event, Description, Priority, DateAdded, DateDue,Spare) VALUES ('$_POST[Event]','$_POST[Description]','$_POST[Priority]'),'$_POST[DateAdded]','$_POST[DateDue]','$_POST[spare]')))"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; echo "</b>"; mysql_close($con) ?> Please could you let me know where I am going wrong. Tx
  16. Hi PFMaBiSmAd, Apologies if this is the incorrect section (still finding my feet around here) - If so, please point me in the right direction. Following on the initial post: Long and short is that I am posing data from a PHPform into a MySQL Db (ver5.x) My table fields are formated as either VARCHAR or DATE The problem is that when posting from the form it appears as if only the VARCHAR fields are populated (although there are values submitted for the DATE fields as well) when doing a query on the Db There are no errors displayed on posting whatsoever so I am at a loss.
  17. I have created a form that captures a couple of fields: Name; Description; Date The Database structure allows VARCHAR for the Name; DEscrip; etc and I have set the Date in the table to DATE The problem is that when I capture data from the form; all the VARCHAR fields are correctly completed but the Date field remains empty. I have tried a couple of sequences (20090708 and 2009-07-08 and 2009/07/08) I suspect this may have to do with the input type on the form itself : Is there a "date" type? Am I on the right track here with my logic? ADDED LATER: (Aplogies - Just read the requirements) Server version: 5.0.32-Debian_7etch10-log Query $result = mysql_query("SELECT * FROM todo");
  18. Works like a charm. Thank you NBarone, much appretiated...
  19. Hi All, I am extremely new to php (and this forum) and am hoping to get some assistance. If this is not the right place to ask this question, if not; MODs please move the post to the correct section and apologies What I am trying to do: create a form that asks for an image name and then display that image on the next page. Sounded easy when I thought about it .... but, doesnt appear so. ??? All the images I want to display are in the folder where the code is. Code: Input page Code: display.php page Now .... Clearly this doesn't work - I have triend putting the <imgscr> in the php section but that just bombs .... I have spent the last 5 hours on this (searching the net / trial and error / etc) and am going around in circles .... Any help would be appretiated. Thx Bryan
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.