Current location: Hot Scripts Forums » Programming Languages » PHP » Basic php help needed


Basic php help needed

Reply
  #1 (permalink)  
Old 05-20-09, 04:04 PM
raf raf is offline
Newbie Coder
 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Stop Basic php help needed

I need help! Something is wrong with this PHP script. It is short, and simple. I am just trying to get it work properly. The problem I get is...That I am not able to get the Add Joke link to work. It is supposed to "drop down" a text box. On the text box is a submit button that adds the joke to the database i have created. Can someone tell me what is wrong? Maybe the script is written in a older version of PHP. I am running PHP 5 along with MySQL 5. Thank you for your help...
PHP Code:

<?php
  
// If the user wants to add a joke
  
if (isset($addjoke)):
?>

<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD="POST">
<P>Type your joke here:<BR>
<TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP>
</TEXTAREA><BR>
<INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT">
</FORM>

<?php
  
else:

    
// Connect to the database server
    
$dbcnx = @mysql_connect("webhost.server""************""**************");
    if (!
$dbcnx) {
      echo( 
"<P>Unable to connect to the " .
            
"database server at this time.</P>" );
      exit();
    }

    
// Select the jokes database
    
if (! @mysql_select_db("jokes123") ) {
      echo( 
"<P>Unable to locate the joke " .
            
"database at this time.</P>" );
      exit();
    }

    
// If a joke has been submitted,
    // add it to the database.
    
if ("SUBMIT" == $submitjoke) {
      
$sql "INSERT INTO Jokes SET " .
             
"JokeText='$joketext', " .
             
"JokeDate=CURDATE()";
      if (
mysql_query($sql)) {
        echo(
"<P>Your joke has been added.</P>");
      } else {
        echo(
"<P>Error adding submitted joke: " .
             
mysql_error() . "</P>");
      }
    }
  
    echo(
"<P> Here are all the jokes " .
         
"in our database: </P>");
  
    
// Request the text of all the jokes
    
$result mysql_query(
              
"SELECT JokeText FROM Jokes");
    if (!
$result) {
      echo(
"<P>Error performing query: " .
           
mysql_error() . "</P>");
      exit();
    }
  
    
// Display the text of each joke in a paragraph
    
while ( $row mysql_fetch_array($result) ) {
      echo(
"<P>" $row["JokeText"] . "</P>");
    }
  
    
// When clicked, this link will load this page
    // with the joke submission form displayed.
    
echo("<P><A HREF='$PHP_SELF?addjoke=1'>" .
         
"Add a Joke!</A></P>");
  
  endif;
  
?>

Last edited by Nico; 05-20-09 at 06:05 PM.
Reply With Quote
  #2 (permalink)  
Old 05-21-09, 03:39 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
PHP Code:

<?php
  
// If the user wants to add a joke
  
if (!empty($_GET["addjoke"])&&$_GET["addjoke"]==1):
?>

<FORM ACTION="?addjoke=0" METHOD="POST">
<P>Type your joke here:<BR>
<TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP>
</TEXTAREA><BR>
<INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT">
</FORM>

<?php
  
else:

    
// Connect to the database server
    
$dbcnx = @mysql_connect("webhost.server""************""**************");
    if (!
$dbcnx) {
      echo( 
"<P>Unable to connect to the " .
            
"database server at this time.</P>" );
      exit();
    }

    
// Select the jokes database
    
if (! @mysql_select_db("jokes123") ) {
      echo( 
"<P>Unable to locate the joke " .
            
"database at this time.</P>" );
      exit();
    }

    
// If a joke has been submitted,
    // add it to the database.
    
if (!empty($_POST["submitjoke"])) {
      
$sql "INSERT INTO Jokes SET JokeText='".$_POST["joketext"]."',JokeDate=CURDATE()";
      if (
mysql_query($sql)) {
        echo(
"<P>Your joke has been added.</P>");
      } else {
        echo(
"<P>Error adding submitted joke: " .
             
mysql_error() . "</P>");
      }
    }

    echo(
"<P> Here are all the jokes " .
         
"in our database: </P>");

    
// Request the text of all the jokes
    
$result mysql_query(
              
"SELECT JokeText FROM Jokes");
    if (!
$result) {
      echo(
"<P>Error performing query: " .
           
mysql_error() . "</P>");
      exit();
    }

    
// Display the text of each joke in a paragraph
    
while ( $row mysql_fetch_array($result) ) {
      echo(
"<P>" $row["JokeText"] . "</P>");
    }

    
// When clicked, this link will load this page
    // with the joke submission form displayed.
    
echo("<P><A HREF='?addjoke=1'>" .
         
"Add a Joke!</A></P>");

  endif;

?>
__________________
Jerry Broughton
Reply With Quote
  #3 (permalink)  
Old 05-21-09, 11:38 AM
raf raf is offline
Newbie Coder
 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Thank you so much!

Thank you very much job0107!

Your work is very well appreciated

I do have one question... So what was the problem with my script?

Was it written in PHP4?

I am just so happy! I can't tell you how many hours I spent on trying to fix this script. Funny.
Reply With Quote
  #4 (permalink)  
Old 05-21-09, 01:21 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Quote:
Originally Posted by raf View Post
Was it written in PHP4?
No, but it was based on register globals, which has been disabled by default in PHP 5. And that's a good thing!
Reply With Quote
  #5 (permalink)  
Old 05-21-09, 01:26 PM
raf raf is offline
Newbie Coder
 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Can you help me with this script?

I think I have another script that needs to have the globals fixed.

I am a beginner to PHP. I am still learning how to do this.

Is there an easy way for me to do this myself?

If you want to take a look at this other script I have. It is very simple, lol. Not for me. It is basically a PHP template for a used car dealership. I suspect the script is written in PHP4 because it is not working at all. I suspect it has something to do with the globals as well. I downloaded the script, installed it in my web host, and nothing. I know I am doing everything correctly. It's the dang script that's messed up. Can anyone please help with this? I found the script, on Free-Car-Dealer-Website - Auto Dealer Inventory Software. Ignore the advertisements on there. Go straight to download towards the top of the stupid website.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Developer Needed for Open Source (LGPL) Project Olate Job Offers & Assistance 2 08-24-10 08:02 AM
ASP or PHP which is better? nepala The Lounge 9 07-14-10 05:48 AM
Sports Pick Em racingboy20 Script Requests 3 06-18-10 03:12 AM
PHP Programmer needed jaisiyaram Job Offers & Assistance 3 03-26-09 04:09 AM
php script needed for uploader rwhite2022 Script Requests 0 01-11-09 06:04 PM


All times are GMT -5. The time now is 08:36 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.