|
-
Jun 16th, 2002, 10:01 AM
#1
Thread Starter
Fanatic Member
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
?>
-
Jun 16th, 2002, 11:36 AM
#2
Fanatic Member
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
-
Jun 16th, 2002, 11:44 AM
#3
Fanatic Member
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
?>
-
Jun 16th, 2002, 02:11 PM
#4
Thread Starter
Fanatic Member
Arg why did they do that.
If I was making this for a online server, would I make it 4.2 compliant?
-
Jun 16th, 2002, 02:17 PM
#5
Fanatic Member
yes, b/c some online servers do not allow super globals.
-
Jun 16th, 2002, 02:26 PM
#6
Thread Starter
Fanatic Member
Well Thanks a bunch it works now
-
Jun 16th, 2002, 02:34 PM
#7
Thread Starter
Fanatic Member
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
-
Jun 16th, 2002, 02:40 PM
#8
Fanatic Member
post your code so I can look.
-Matt
-
Jun 16th, 2002, 02:43 PM
#9
Thread Starter
Fanatic Member
I am using the code you fixed up
-
Jun 16th, 2002, 04:10 PM
#10
Fanatic Member
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
?>
-
Jun 16th, 2002, 05:11 PM
#11
Thread Starter
Fanatic Member
tried both ways still doesnt work
-
Jun 16th, 2002, 05:16 PM
#12
Thread Starter
Fanatic Member
Something odd because
$body = str_replace("[q]", "<blockquote><font class=quote>","$body");
works but the other doesnt
-
Jun 16th, 2002, 05:25 PM
#13
Fanatic Member
ohh, the | are throwing it off. You should only use \n\r
-
Jun 16th, 2002, 05:26 PM
#14
Thread Starter
Fanatic Member
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?
-
Jun 16th, 2002, 05:27 PM
#15
Thread Starter
Fanatic Member
Originally posted by cpradio
ohh, the | are throwing it off. You should only use \n\r
Thanks for your time man
-
Jun 16th, 2002, 05:29 PM
#16
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|