Jump to content

jeffshen

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jeffshen's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. the '' is basically a test for an empty string. If there is nothing behind the URL, ie. if you accessed www.phpfreaks.com, $_SERVER['REQUEST_URI'] will return an empty string. If you are running the script within a folder, you will need to add the folder name to the test parameters, ie. for your example above, array('/folder ', '/folder/index.php', '/folder/index.html', '/folder/').
  2. The correct value that is supposed to go into the UPDATE query. This then also becomes the $result1 value for some odd reason when it loads up the error The flight has been booked already by ".$result1.". Please click here to book another flight. I am very certain that when $result1 is defined $result1 = mysql_result($query1,0);, it should come up with an empty string as there is nothing stored on the mysql backend.
  3. You typed echo msyql_error(); it should be mysql_error();
  4. Type=MyISAM sets the storage engine to MyISAM AUTO_INCREMENT=2 sets the autoincrement to start at number 2. If no number is specified, it will start at 1. The script looks alright to me and it should work.
  5. <?php if (!isset($_GET['flightid'])) { echo "<table width='100%'><tr><td> </td></tr><tr><td><span class='boldblue'>There has been a problem. <br /><a href='index1.php?page=ivaorfe2010'>Please click here to book another flight.</a></span></td></tr><tr><td> </td></tr></table>"; } else { $flightid = $_GET['flightid']; $query1 = mysql_query("SELECT `pilot_id` FROM `ivaorfetmp` WHERE `flightno` = '$flightid'"); $result1 = mysql_result($query1,0); $pilot_id = $flyuk->pilotid; if ( $result1 == '' || empty($result1) ) { $query2 = "UPDATE ivaorfetmp SET pilot_id = '$pilot_id' WHERE flightno = '$flightid' LIMIT 1"; mysql_query($query2); echo "<table width='100%'><tr><td> </td></tr><tr><td><span class='boldblue'>Your flight has been booked successfully.<br />You will be redirected to your 'My Bookings' page in 3 seconds...</span></td></tr><tr><td></td></tr></table>"; echo "<script type='text/javascript'>"; echo "setTimeout(\"window.location.href = 'index.php?page=my_booked_flights';\", 3000);"; echo "</script>"; } else { echo "<table width='100%'><tr><td> </td></tr><tr><td><span class='boldblue'>The flight has been booked already by ".$result1.". <br /><a href='index1.php?page=ivaorfe2010'>Please click here to book another flight.</a></span></td></tr><tr><td> </td></tr></table>"; } } ?> What I am trying to do with this script is 1. if flightid is not passed in the URL -> produce @There has been a problem. Please click here to book another flight." 2. see whether pilot_id in the mysql table is empty with respect to a flight number which equals the flight id 3. If it is empty, then put the pilot_id in and echo the message and javascript 4. If it is not empty, then echo the message The flight has been booked already by ".$result1.". Please click here to book another flight. What the above script does is: When there is no flightid passed, it produces the correct error message When there is a flightid passed, it runs UPDATE ivaorfetmp SET pilot_id = '$pilot_id' WHERE flightno = '$flightid' LIMIT 1 no problem and inserts the pilot_id, then it shows me The flight has been booked already by ".$result1.". Please click here to book another flight, with $result1 being filled in with the pilot_id I just put into the database. I am sure there isnt any file acting on the database and it is very confusing, as I only run the script once and dont refresh the page. I have even put in extra javascript alert boxes to see whether more than 1 box comes up and it dosent. Does anybody know how I can fix this? Thank you very much in advance,
  6. Dear All, at the moment I have this [code]echo $stockname; echo "<br>"; echo $array[0]; echo "<br>"; echo $numstocks; echo "<br>"; echo $inprice; echo "<br>"; echo $currtime; echo "<br>"; echo $uniqueid; echo "<br>"; $mysqlinsert = "UPDATE `stocks` SET `code` = $stockname , `name` = $array[0] , `owned` = $numstocks , `buy_price` = $inprice , `timestamp` = $currtime WHERE `key` = $uniqueid"; echo $mysqlinsert; echo"<br>"; mysql_query($mysqlinsert) or die ("Error inserting records");[/code] where all the random echos are used for debugging... I still cant find the mistake though, when I send that to the browser, the result I get is 0003 HK & CHINA GAS 123 142 1155151474 72 UPDATE `stocks` SET `code` = 0003 , `name` = HK & CHINA GAS , `owned` = 123 , `buy_price` = 142 , `timestamp` = 1155151474 WHERE `key` = 72 Error inserting records where the last line indicates that the UPDATE function has failed, but I cant see whats wrong with my update function. can someone please help? thanks a lot in advance Jeff
  7. Hey all, I found the mistake at like 18, I forgot the ) and ; 15  //Connect to MySQL Database     include("login.php");     mysql_connect("localhost",$username,$password);     @mysql_select_db($database) or die("Unable to select database"); <-- ) after $datavase and ; wasnt in the original script Thanks a lot for everybody's prompt reply, Jeff
  8. Hey Thanks for yet spotting another silly mistake... however it still states that Parse error: parse error, unexpected T_VARIABLE in /var/www/html/stocks/test.php on line 21 Thanks, Jeff
  9. Thank you for pointing out my silly mistakes, however the problem on line 21 still exists... Can anyone spot the error please? Thanks a lot, Jeff
  10. Hey all, I've written this piece of code and an error is coming up as: Parse error: parse error, unexpected T_VARIABLE in /var/www/html/stocks/test.php on line 21 I've tried googling the topic and see that its something to do with missing punctuation... but I cant find the mistake... can someone please help? [code] 1  <table border="1" cellspacing="2" cellpadding="2">     <tr>     <th><font face="Arial, Helvetica, sans-serif">Symbol</font></th>     <th><font face="Arial, Helvetica, sans-serif">Name</font></th> 5  <th><font face="Arial, Helvetica, sans-serif">Time</font></th>     <th><font face="Arial, Helvetica, sans-serif">Date</font></th>     <th><font face="Arial, Helvetica, sans-serif">Last</font></th>     <th><font face="Arial, Helvetica, sans-serif">Change</font></th>     <th><font face="Arial, Helvetica, sans-serif">High</font></th> 10 <th><font face="Arial, Helvetica, sans-serif">Low</font></th>     </tr>         <?php     15  //Connect to MySQL Database     include("login.php");     mysql_connect("localhost",$username,$password);     @mysql_select_db($database or die("Unable to select database")     20  //Select All Records from Stocks Database     $query = "SELECT * FROM stocks";     $result = mysql_query($query);         //returns the row of the MySQL Query 25  $row = mysql_num_rows($result);     $i = 0         //Selects the Stock Code of the Stock     $asking = mysql_result($result,$i,"code") 30      //add .hk to the end of the stocknumber, required for Yahoo! Finance     $standard = ".hk";     //Put the two together to allow one stock number with .hk at the end for YahoO! 35  $findquote = "$asking$standard";         //Connects to Yahoo! and retrives the records from Yahoo!'s database     Class yahoo     { 40  function get_stock_quote($symbol)     {     $url = sprintf("http://finance.yahoo.com/d/quotes.csv?s=%s&f=snl1d1t1c1ohgv" ,$symbol);     $fp = fopen($url, "r");     if(!fp) 45  {     echo "error : cannot recieve stock quote information";     }     else     { 50  $array = fgetcsv($fp , 4096 , ', ');     fclose($fp);     $this->symbol = $array[0];     $this->name = $array[1];     $this->last = $array[2]; 55  $this->date = $array[3];     $this->time = $array[4];     $this->change = $array[5];     $this->open = $array[6];     $this->high = $array[7]; 60  $this->low = $array[8];     $this->volume = $array[9];     }     }     } 65        //loop the function for multiple database entries     while ($i < $row) {         //Executes the script for the records retrival 70  $quote = new yahoo;     $quote->get_stock_quote("$findquote");     ?>     //Print the information into a tabular format 75  <tr>     <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->symbol"; ?></font></td>     <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->name"; ?></font></td>     <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->time"; ?></font></td>     <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->date"; ?></font></td> 80  <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->last"; ?></font></td>     <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->change"; ?></font></td>     <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->high"; ?></font></td>     <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->low"; ?></font></td> 85     </tr>     </table>     <? 90  ++$i     ?> [/code] Thanks, Jeff
  11. Hey, I have a previous snippet of code which I have been using for ages now, [code]<?PHP include("login.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM people"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>2005-2006</center></b><br><br>"; ?> <table border="1" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Nickname</font></th> <th><font face="Arial, Helvetica, sans-serif">Class</font></th> <th><font face="Arial, Helvetica, sans-serif">E-Mail</font></th> </tr> <?PHP $i=0; while ($i < $num) { $surname=mysql_result($result,$i,"surname"); $name=mysql_result($result,$i,"name"); $nickname=mysql_result($result,$i,"nickname"); $class=mysql_result($result,$i,"class"); $email=mysql_result($result,$i,"e_mail"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><? echo "$name"; echo" $surname"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$nickname"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$class"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo "$email"; ?>"><? echo "$email"; ?></a></font></td> </tr> <? ++$i; } echo "</table>";?>[/code] but however when I port the whole thing to another environment it dosent work... the MySQL query only returns the first line in this case rather than all the database entries as specified in the code... [code]<table border="1" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Symbol</font></th> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Time</font></th> <th><font face="Arial, Helvetica, sans-serif">Date</font></th> <th><font face="Arial, Helvetica, sans-serif">Last</font></th> <th><font face="Arial, Helvetica, sans-serif">Change</font></th> <th><font face="Arial, Helvetica, sans-serif">High</font></th> <th><font face="Arial, Helvetica, sans-serif">Low</font></th> </tr> <?php include("login.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM stocks"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $quote = mysql_result($result,$i,"symbol"); $standard = ".hk"; $findquote = "$quote$standard"; Class yahoo { function get_stock_quote($symbol) { $url = sprintf("http://finance.yahoo.com/d/quotes.csv?s=%s&f=snl1d1t1c1ohgv" ,$symbol); $fp = fopen($url, "r"); if(!fp) { echo "error : cannot recieve stock quote information"; } else { $array = fgetcsv($fp , 4096 , ', '); fclose($fp); $this->symbol = $array[0]; $this->name = $array[1]; $this->last = $array[2]; $this->date = $array[3]; $this->time = $array[4]; $this->change = $array[5]; $this->open = $array[6]; $this->high = $array[7]; $this->low = $array[8]; $this->volume = $array[9]; } } } $quote = new yahoo; $quote->get_stock_quote("$findquote"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->symbol"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->name"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->time"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->date"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->last"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->change"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->high"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->low"; ?></font></td> </tr> <? ++$i; } ?> </table>[/code] Can someone please help? Thanks a lot, Jeff
×
×
  • 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.