Re: what am i doing wrong..??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



well ofcourse it "keeps the get variables" as you put it. PHP_SELF is the path and arguments that php was called with. use phpinfo(); to find out which variables hold the real path, make sure to add some random "get variables" when calling that script so you see the difference

Jack Van Zanen wrote:
<?php $_SERVER['PHP_SELF'] ?> somehow keeps the $_GET variables. If you
change this to the real script name it seems to work

JACK

-----Original Message-----
From: Aalee [mailto:ayyaali@xxxxxxxxxxx] Sent: Thursday, November 04, 2004 1:54 PM
To: php-general@xxxxxxxxxxxxx
Subject: what am i doing wrong..??



Hi there please have a look the code below...I dont know wht am doing wrong here... This code is suppose to show the number of jokes in a mysql database and allows user to add a joke when the user clicks addjoke link. And when the joke is added, it suppose to say that "Joke inserted, Thank you" and list all the jokes below this line. So far am able to view all the jokes and take the user to add joke page. But the problem is when the user clicks insert joke button, it does not display the message "Joke inserted, Thank you" and the jokes are not listed. Infact it does not give any error aswell, it just stays on the add joke form page. I checked the database and no joke is added. Working on PHP ver 4.3.8 with register_globals turned OFF and Apache 1.3.31. MySQL ver 4.0.20a on winXP pro SP1. Recently i started using registre_globals OFF and all these probs strted coming up. This code was working fine with globals ON. But my hosting has it off. So need to do so. I was able to fix all the other issues came coz of this global thing in this code. But stuck on the issue i just mentioned. Any help would be GREATLY appreciated.

<?php
if (isset($_GET['addjoke'])){
?>
<form name="form1" method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
  Type your joke :<br>
  <textarea name="jokeText" id="jokeText"></textarea>
   <br>
  <input name="insert" type="submit" id="submit" value="Insert Joke">
</form>


<?php } else { // start main else statement if(isset ($_POST['insert'])) { $db = mysql_connect("localhost","homesite","test") ; mysql_select_db("jokes",$db); $query = mysql_query("INSERT INTO jokes SET JokeText = '".$_POST['jokeText']."' , JokeDate = CURDATE() "); echo " Joke inserted, Thank you <BR><BR>"; echo mysql_error(); } $color1 = "#66CCFF"; $color2 = "#66CC99"; $row_count = 1;

// ---------- Following lines list the jokes in the
database ----------------
echo "<b><H3> These are the jokes we have got so far</H3></B>"; $db =
mysql_connect("localhost","homesite","test")  or die(mysql_error());
mysql_select_db("jokes",$db); $sql = "SELECT id, JokeText, JokeDate from
jokes"; $query = mysql_query($sql); echo "<table border=1>
   <tr>
    <td><b>ID<b></td>
  <td><b>Joke Text<b></td>
  <td><b>Joke Date<b></td></tr>";
while ($myrow = mysql_fetch_array($query))
 {
 $row_color = ($row_count % 2) ? $color1 : $color2;
  echo"<tr bgcolor = $row_color>".
  "<td>". $myrow["id"]."</td>".
  "<td>". $myrow["JokeText"]. "</td>".
  "<td>". $myrow["JokeDate"]."</td></tr>";
  $row_count++;
 }
echo "</table>";

$current_url = $_SERVER['PHP_SELF'];
echo("<P><A HREF=".$current_url."?addjoke=1>" ."Add a Joke!</A></P>");


} // end main else statement ?>


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux