Jump to content

fesan

Members
  • Posts

    114
  • Joined

  • Last visited

About fesan

  • Birthday 10/23/1986

Contact Methods

  • MSN
    stefan@bahrawy.net
  • Website URL
    http://www.bahrawy.net

Profile Information

  • Gender
    Male
  • Location
    Norway
  • Interests
    PHP, Web-development, Downhill/Freeride, Offroad, Climbing
  • Age
    26

fesan's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi, is there possible to search and "choose" a certain arrey key by user input? And when the input is not "korrect" how to choose the closest one? Input = 22 $kz should chose key 21.3 => 1.17 $kz = array( 4.6 => 0.85, 6.1 => 0.90, 7.6 => 0.94, 9.1 => 0.98, 12.2 => 1.04, 15.2 => 1.09, 18 => 1.13, 21.3 => 1.17, 24.4 => 1.21, 27.4 => 1.24, 30.5 => 1.26, 36.6 => 1.31, 42.7 => 1.36, 48.8 => 1.39, 54.9 => 1.43, 61.0 => 1.46, 76.2 => 1.53, 91.4 => 1.59, 106.7 => 1.64, 121.9 => 1.69, 137.2 => 1.73, 152.4 => 1.77,); To explain some more, the array is part of a math solving. where the key is a height in meters and the value are the responding coefficient. $qz = 0.613 * $kz * 1 * 1 * pow($vind2, 2) *1;
  2. I really donĀ“t have a good answer for that! When i first started with PHP i got some code from another forum and i guess some of it is still left and in very much use unfortunately! Could i ask what the correct syntax would be? I guess it is time to convert to mysqli soon as well?
  3. create a completely new file and see if this could help you a bit:(i have not tested the code) <?php $status = !empty($_POST ['status']) ? $_POST['status'] : ''; if($_GET['task'] == 'edit') { $dbhost = ""; $dbusr = ""; $dbpass = ""; $db = ""; $dbtable = ""; $conn = mysql_connect($dbhost, $dbusr, $dbpass); mysql_select_db($dbtable, $conn); $sql = "UPDATE ${dbtable} SET status = '$staus' WHERE id = '$_GET[id]'"; $result = mysql_query($sql, $conn) or die (mysql_error()); echo "Success"; } else {echo "Trouble";} ?> <table> <tr> <td><strong>ID</strong></td> <td><strong>Contact Name</strong></td> <td><strong>Contact Number</strong></td> <td><strong>Contact second number</strong></td> <td><strong>Date Set</strong></td> <td><strong>Notes</strong></td> <td><strong>Status</strong></td> <td><strong>Save</strong></td> </tr> <?php $dbhost = ""; $dbusr = ""; $dbpass = ""; $db = ""; $dbtable = ""; $conn = mysql_connect($dbhost, $dbusr, $dbpass); mysql_select_db($dbtable, $conn); $query = "SELECT * FROM $dbtable"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<tr>\r\n"; echo "<form id='form1' name='form1' action='".$_SERVER['PHP_SELF']."?task=edit&id=".$row['id']."' method='POST'>\r\n"; echo "<td>".$row['id']."</td>\r\n"; echo "<td>".$row['contact_name']."</td>\r\n"; echo "<td>".$row['contact_number_primary']."</td>\r\n"; echo "<td>".$row['contact_number_secondary']."</td>\r\n"; echo "<td>".$row['date_set']."</td>\r\n"; echo "<td>".$row['notes']."</td>\r\n"; echo "<td><select name='status' id='status'> <option selected value='".$row['status']."' >". $row['status']."</option> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> </select></td>\r\n"; echo "<td><input type='submit' name='submit' id='submit' value='Save' /></td>\r\n"; echo "</tr></table>\r\n"; } ?> was a bit quick there!
  4. yea, that is just what the code should do. It is snipped from a page of mine that does the same thing: http://www.bahrawy.net/dev/cal_snip.PNG on the picture every green field is a input field where i can write directly into the table. hit enter or the button at the end saying "Lagre" and it saves. The output of your first code should go straight to a <form> with a <select> input. add an extra column to your HTML table to get the submit button. the URL not found seems like you have added the header code and not updated to the correct path of your page?
  5. you are so absolutely right Barand, but i actually have it in a code of mine here and it works just fine! It doesn't make it more right though! no, you don't have to have an ID column, but as far as i know it is good practice. It is a way of separating all the rows from each other with an unique id. If set to unique and auto increment. Unless you have some other unique column that makes us able to choose that particular row? The while function should print out every row in your DB and separate them by printing the row ID(or other sort of ID) in the action"" field of the <form>. After getting this to work you could choose to just print one row, or CSS it to something more view able.
  6. sorry for the missing bracket! what page turns out blank? the first or the second? The second page "proc.php" has no code after the row update. you could use a header to get back to the previous page header("Location: http://sitename"); Or you could just an a link: echo "<a href='updateform.php'>back...</a>
  7. You need a form to update fields without phpmyadmin. I'm very pro outputting my data directly into a form and change it on the fly. I tend to CSS the form so it does not look like an traditional form. Alternatively you could use Java/AJAX. example of code: $dbhost = "yourhost"; $dbusr = "yourusername"; $dbpass = "yourpassword"; $db = "yourbatabase"; $dbtable = "yourtable"; mysql_connect ($dbhost, $dbusr, $dbpass) || die("Could not connect to the server."); mysql_select_db($db) || die("Could not find the Data Base"); $conn = mysql_connect($dbhost, $dbusr, $dbpass); mysql_select_db($dbtable, $conn); $query = "SELECT * FROM $dbtable"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<form id='form1' name='form1' action='yourprocesspage.php&id=".$row['id']."' method='POST'>\r\n"; echo "<input type='text' name='yourfield' id='yourfield' size='6' value='". $row['your_DB_row']."' />\r\n"; echo "<input type='submit' name='submit' id='submit' value='Submit' />\r\n"; echo "</form>\r\n"; you would then need to process the data sent to the process page: //get the variables and making sure they are not empty $yourfield = !empty($_POST ['yourfield']) ? $_POST['yourfield'] : ''; $dbhost = "yourhost"; $dbusr = "yourusername"; $dbpass = "yourpassword"; $db = "yourbatabase"; $dbtable = "yourtable"; mysql_connect ($dbhost, $dbusr, $dbpass) || die("Could not connect to the server."); mysql_select_db($db) || die("Could not find the Data Base"); $conn = mysql_connect($dbhost, $dbusr, $dbpass); mysql_select_db($dbtable, $conn); $sql = "UPDATE $dbtable SET your_DB_row = '$yourfield', WHERE id = '$_GET[id]'"; //we sent the row id with the adressbar and are retreiveing it via $_GET[''] $result = mysql_query($sql, $conn) or die (mysql_error());
  8. Try setting the file permission to 744 in your script. http://php.net/manual/en/function.chmod.php change it back to 644 or whatever your correct mode is after executing the zip.
  9. fesan

    header

    Ahhh.... i found the error! Just me doing stupid things without thinking! My process page is not included in my index where the rest of my includes are. Therefore my variables where not set in the process page. Thanks for the push!!
  10. fesan

    header

    i did a var_dump() on all 3 variables: string(15) "www.bahrawy.net" string(13) "/dev/ballroom" string(9) "index.php" echo $host.$uri."/".$page; www.bahrawy.net/dev/ballroom/index.php I can't see the the difference between these two: - header("Location: http://$host$uri/$page"); - header("Location: http://www.bahrawy.net/dev/ballroom/index.php"); and thanks for the help by the way!
  11. fesan

    header

    yea, i missed out the dollar sign while copying! it is in the original code. There is no change in the pages except from i have changed the header goal from an direct URL to a PHP made url. Before i changed the code everything worked out as i wanted. The Index.php has a "session_start()" at the veyr start so it s re-declared every time the page is refreshed.
  12. fesan

    header

    Hi... Updating a small site of mine. I had a header that read header("location: full-web-page-url"). I replaced this code so it is a bit easier to update my pages in the future. I then added this code: host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'index.php'; The page has worked flawless before i did this and now i have a "refresh delay". The first page is a form that a user submits. This takes the user to a new page with the execute code(no visuals for user). after execution the page runs this code(se below) to take them back with info about the execution. _SESSION["message"] = "Eventinfoen er endret."; header("Location: http://$host$uri/$extra"); The header works fine and the code executes fine, but the session message is not echoed on the next page before i press refresh in my browser. In the php manual i find this: Does this involve every session variables? If that is the case how do i use a SID constant to transfer all my variables?
  13. fesan

    Functions

    ahh... Thanks. And if there are allot of variables i need to get out of the function? Do i have to return them all?
  14. Happy Saturday. Can someone explain why this code returns nothing? function test(){ $test = "test"; } test(); echo $test;}
  15. fesan

    Date

    Wow... Great guys! I'm gonna try to log inn to the shell and see if there is a other name etc. Thanks for all the help!!
×
×
  • 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.