Cory94bailly Posted May 8, 2008 Share Posted May 8, 2008 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 More sharing options...
pocobueno1388 Posted May 8, 2008 Share Posted May 8, 2008 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. Link to comment https://forums.phpfreaks.com/topic/104645-solved-help-with-a-php-news-script/#findComment-535652 Share on other sites More sharing options...
Cory94bailly Posted May 8, 2008 Author Share Posted May 8, 2008 Edit: My mistake! Didn't copy the whole code! Link to comment https://forums.phpfreaks.com/topic/104645-solved-help-with-a-php-news-script/#findComment-535654 Share on other sites More sharing options...
Cory94bailly Posted May 8, 2008 Author Share Posted May 8, 2008 Thanks! Worked perfectly. And that "username" thing was my mistake I actually had "News" but I accidently copied username in it.. Link to comment https://forums.phpfreaks.com/topic/104645-solved-help-with-a-php-news-script/#findComment-535656 Share on other sites More sharing options...
dezkit Posted May 8, 2008 Share Posted May 8, 2008 oops sorry cory94, i didn't notice you messaged me, sorry edit: LOL PANCAKES R GOOD Link to comment https://forums.phpfreaks.com/topic/104645-solved-help-with-a-php-news-script/#findComment-535660 Share on other sites More sharing options...
dezkit Posted May 8, 2008 Share Posted May 8, 2008 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 Link to comment https://forums.phpfreaks.com/topic/104645-solved-help-with-a-php-news-script/#findComment-535662 Share on other sites More sharing options...
Cory94bailly Posted May 8, 2008 Author Share Posted May 8, 2008 Edit: DIdn't seem to do anything Anyways, thanks Dezkit for the script! Link to comment https://forums.phpfreaks.com/topic/104645-solved-help-with-a-php-news-script/#findComment-535665 Share on other sites More sharing options...
dezkit Posted May 8, 2008 Share Posted May 8, 2008 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> Link to comment https://forums.phpfreaks.com/topic/104645-solved-help-with-a-php-news-script/#findComment-535667 Share on other sites More sharing options...
Cory94bailly Posted May 8, 2008 Author Share Posted May 8, 2008 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 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 ) Link to comment https://forums.phpfreaks.com/topic/104645-solved-help-with-a-php-news-script/#findComment-535672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.