Results 1 to 16 of 16

Thread: Whats Wrong

  1. #1

    Thread Starter
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734

    Whats Wrong

    Ever sense I formatted and install PHP, Mysql, Apache this script no longer works.

    It gives no errors, it just does not do anything, take a look mabye i screwed something up

    PHP Code:
    <?php

    $date 
    date("D,M,Y");

    if (
    $submit) {
       
      
    $body str_replace("\r\n|\n|\r""<br>""$body");
      
    $body str_replace("[q]""<blockquote><font class=quote>","$body");
      
    $body str_replace("[/q]""</blockquote></font>","$body");

      
    // process form

      
    $db mysql_connect("localhost""root");

      
    mysql_select_db("site",$db);

      
    $sql "INSERT INTO news (title,date,user,source,body) VALUES 

    ('
    $title','$date','$user','$source','$body')";

      
    $result mysql_query($sql);

      echo 
    "Thank you! Information entered.\n";

    } else{



      
    // display form



      
    ?>
      <form method="post" action="<?php echo $PHP_SELF?>">

      Title:<input type="Text" name="title"><br><br>

      UserName:<input type="Text" name="user"><br><br>

      Source:<input type="Text" name="source"><br><br>

    <textarea name="body" rows="20" cols="80" wrap="physical">

    </textarea>

    <P>


      <input type="Submit" name="submit" value="Enter information">

      </form>



      <?php



    // end if



    ?>

  2. #2
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    If you installed PHP 4.2 you have to use $_REQUEST['submit'] instead of $submit and the same goes with your other form variables.

    PHP 4.2 turns off super globals automatically now, and you can change that by editing the php.ini file and editing $register_globals

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  3. #3
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Here is your code converted into PHP 4.2 Standards
    PHP Code:
    <?php 
        $date 
    date("D,M,Y"); 
        if (isset(
    $_REQUEST['submit'])) {
            
    $body $_REQUEST['body'];
            
    $body str_replace("\r\n|\n|\r""<br>""$body"); 
            
    $body str_replace("[q]""<blockquote><font class=quote>","$body"); 
            
    $body str_replace("[/q]""</blockquote></font>","$body"); 

            
    // process form 
            
    $db mysql_connect("localhost""root"); 
            
    mysql_select_db("site",$db); 

            
    $sql "INSERT INTO news (title,date,user,source,body) VALUES 
            ('"
    .$_REQUEST['title']."','$date','".$_REQUEST['user']."','".$_REQUEST['source']."','$body')"
            
    $result mysql_query($sql); 
            echo 
    "Thank you! Information entered.\n"
        } else{ 
        
    // display form 
    ?> 
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    Title:<input type="Text" name="title"><br><br> 
    UserName:<input type="Text" name="user"><br><br> 
    Source:<input type="Text" name="source"><br><br> 
    <textarea name="body" rows="20" cols="80" wrap="physical"> 
    </textarea> 
    <P> 
    <input type="Submit" name="submit" value="Enter information"> 
    </form> 
    <?php 
        
    // end if 
    ?>
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  4. #4

    Thread Starter
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    Arg why did they do that.

    If I was making this for a online server, would I make it 4.2 compliant?

  5. #5
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    yes, b/c some online servers do not allow super globals.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  6. #6

    Thread Starter
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    Well Thanks a bunch it works now

  7. #7

    Thread Starter
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    One more question did something new happend to the line

    $body = str_replace("\r\n|\n|\r", "<br>", "$body");

    becuase it does not seem to work anymore

  8. #8
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    post your code so I can look.

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  9. #9

    Thread Starter
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    I am using the code you fixed up

  10. #10
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    PHP Code:
    <?php 
        $date 
    date("D,M,Y"); 
        if (isset(
    $_REQUEST['submit'])) {
            
    $body $_REQUEST['body'];

            
    // There shouldn't be quotes around $body
            // If this doesnt fix it take out the line above this $body = $_REQUEST['body']
            // and replace the below $body with $_POST['body'] or $_REQUEST['body']
            
    $body str_replace("\r\n|\n|\r""<br>"$body); 
            
    $body str_replace("[q]""<blockquote><font class=quote>",$body); 
            
    $body str_replace("[/q]""</blockquote></font>",$body); 

            
    // process form 
            
    $db mysql_connect("localhost""root"); 
            
    mysql_select_db("site",$db); 

            
    $sql "INSERT INTO news (title,date,user,source,body) VALUES 
            ('"
    .$_REQUEST['title']."','$date','".$_REQUEST['user']."','".$_REQUEST['source']."','$body')"
            
    $result mysql_query($sql); 
            echo 
    "Thank you! Information entered.\n"
        } else{ 
        
    // display form 
    ?> 
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    Title:<input type="Text" name="title"><br><br> 
    UserName:<input type="Text" name="user"><br><br> 
    Source:<input type="Text" name="source"><br><br> 
    <textarea name="body" rows="20" cols="80" wrap="physical"> 
    </textarea> 
    <P> 
    <input type="Submit" name="submit" value="Enter information"> 
    </form> 
    <?php 
        
    // end if 
    ?>
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  11. #11

    Thread Starter
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    tried both ways still doesnt work

  12. #12

    Thread Starter
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    Something odd because

    $body = str_replace("[q]", "<blockquote><font class=quote>","$body");

    works but the other doesnt

  13. #13
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    ohh, the | are throwing it off. You should only use \n\r
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  14. #14

    Thread Starter
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    OK ok closing in on the program

    $body = str_replace("\r\n|\n|\r", "<br>", $body); DOES NOT WORK

    $body = str_replace("\n", "<br>", $body); WORKS

    Odd eh?

    What does /r do anyway?

  15. #15

    Thread Starter
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    Originally posted by cpradio
    ohh, the | are throwing it off. You should only use \n\r
    Thanks for your time man

  16. #16
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Well the problem is \n\r|\n|\r is used in preg_replace and cannot work in str_replace as | means nothing in str_replace but in preg_replace it means or

    \n\r looks for new lines created by the keyboard.
    \r defines character return (aka the user pressed enter)
    \n linebreak.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width