Jump to content

[SOLVED] Help with a php news script..


Cory94bailly

Recommended Posts

I am trying to get a script working that Dezkit made me... Any help?

 

 

 

Here's test2.php:

 

<?php
if(isset($_POST['submit'])) {
?>
<?php
// Make a MySQL Connection
mysql_connect("***", "***", "***") or die(mysql_error());
mysql_select_db("***") or die(mysql_error());

// Insert a row of information into the table "example"
mysql_query("INSERT INTO news 
(news) VALUES('".$_POST['username']."') ") 
or die(mysql_error());   

echo "News posted!";

?>
<?php
} else {

?>
<form action="<? $_SERVER['PHP_SELF']; ?>" method="post">
<textarea name="news"></textarea>
<input type="submit" value="submit">
</form>
<?php
}
?>

 

 

 

Here's test1.php:

 

<?php
mysql_connect("***", "***", "***") or die(mysql_error());
mysql_select_db("***") or die(mysql_error());

$query = "SELECT * FROM news"; 

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
        echo "<table>";
        echo "<tr><td>";
      echo $row['news'];
      echo "<br />";
}
?>

 

 

 

It does not work!

 

http://www.etsoldiers.com/testing123/test1.php

http://www.etsoldiers.com/testing123/test2.php

 

Thanks in advanced guys.. ;)

Link to comment
https://forums.phpfreaks.com/topic/104645-solved-help-with-a-php-news-script/
Share on other sites

Try this for test2

 

<?php
if(isset($_POST['submit'])) {

   // Make a MySQL Connection
   mysql_connect("***", "***", "***") or die(mysql_error());
   mysql_select_db("***") or die(mysql_error());
   
   $news = mysql_real_escape_string($_POST['news']);
   
   // Insert a row of information into the table "example"
   $query = mysql_query("INSERT INTO news (news) VALUES ('$news')")or die(mysql_error());   
   
   echo "News posted!";

} else {

?>

   <form action="<? $_SERVER['PHP_SELF']; ?>" method="post">
      <textarea name="news"></textarea>
      <input type="submit" name="submit" value="submit">
   </form>

<?php
}
?>

 

EDIT:

 

The problems I fixed were:

 

-You were using $_POST['username'] instead of $_POST['news']

-Your submit button wasn't named "submit", so the insert code would have never executed.

-I used mysql_real_escape_string() on your variable from the form, which is the least you could do.

also...

 


<?php
mysql_connect("***", "***", "***") or die(mysql_error());
mysql_select_db("***") or die(mysql_error());

$query = "SELECT * FROM news"; 

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
        echo "<table>";
        echo "<tr><td>";
echo $row['news'];
        echo "<tr><td>";
}
?>
</table>

 

will b better on the layout i think

mah bad...

 


<table>
<?php
mysql_connect("***", "***", "***") or die(mysql_error());
mysql_select_db("***") or die(mysql_error());

$query = "SELECT * FROM news"; 

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
        echo "<tr><td>";
echo $row['news'];
}
?>
</table>

mah bad...

 


<table>
<?php
mysql_connect("***", "***", "***") or die(mysql_error());
mysql_select_db("***") or die(mysql_error());

$query = "SELECT * FROM news"; 

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
        echo "<tr><td>";
echo $row['news'];
}
?>
</table>

 

Ahh.. looks a bit better :P

 

It stopped the text from going to the right...

 

Again, thanks.. lol.

 

 

(Hmm, that could be made into a chatbox pretty easily.. Just need to capture IPs and have a function to delete ;))

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.