Dekken Posted November 15, 2008 Share Posted November 15, 2008 Hey guys! well i know really basics in MYSql and PHP but iam still trying to make something that will allow me to Post New messages Thats my code so far: Php File: <?php $con = mysql_connect("localhost","XXXXXX",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dekken2_uk_db", $con); $sql="INSERT INTO Thenews (Datenow, Coursenow, Messagenow) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_select_db("dekken2_uk_db", $con); $result = mysql_query("SELECT * FROM Thenews"); echo "<center>"; echo "<table border='1' dir=rtl> <tr> <th>Date</th> <th>Course</th> <th>Message</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Datenow'] . "</td>"; echo "<td>" . $row['Coursenow'] . "</td>"; echo "<td>" . $row['Messagenow'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "</center>"; mysql_close($con); ?> Index.html: <html> <body> <form action="test2.php" method="post"> Date: <input type="text" name="firstname" /> <br> Course: <input type="text" name="lastname" /> <br> Message: <textarea name="age" dir=rtl width=40 height=40></textarea> <input type="submit" /> <br> </form> </body> </html> so i have 2Issues now. How do i clear all the Data inside the Tables and the Columns? lets say i have Table called Test and i have Column called iCheck in it. and in iCheck i have lots of Info. How do i clear the info in iChecks without Deleting the Column and the Table itself? Second one is, How do i fix my table issue? Sometimes whenever i post a new message there is lots of Spaces and Gaps in the table Example: http://img80.imageshack.us/my.php?image=problemtm1.jpg And also how do i make it so whenever i go down a line using enter(not sure how its called..Space? uh dunno) in the Textarea, it will go down a line in the Table..instead of 1Long line Quote Link to comment https://forums.phpfreaks.com/topic/132837-solved-clearing-tables-data-html-table-issues/ Share on other sites More sharing options...
Barand Posted November 15, 2008 Share Posted November 15, 2008 For the first of your two issues, UPDATE test SET icheck = '' For the third of your two issues, when you output $text to the browser echo nl2br($text); Quote Link to comment https://forums.phpfreaks.com/topic/132837-solved-clearing-tables-data-html-table-issues/#findComment-690900 Share on other sites More sharing options...
Dekken Posted November 15, 2008 Author Share Posted November 15, 2008 Thanks! works like a charm and for my last issue...i noticed that i makes spaces in the Table whenever you Refresh the page... well i know why it happens but i dont know how to fix it any help? Quote Link to comment https://forums.phpfreaks.com/topic/132837-solved-clearing-tables-data-html-table-issues/#findComment-690935 Share on other sites More sharing options...
Dekken Posted November 16, 2008 Author Share Posted November 16, 2008 Anyone? maybe adding if statement or something? iam clueless and i really need a way to fix it Sorry for the double :-\ Quote Link to comment https://forums.phpfreaks.com/topic/132837-solved-clearing-tables-data-html-table-issues/#findComment-691350 Share on other sites More sharing options...
l_kris06 Posted November 16, 2008 Share Posted November 16, 2008 Well, regardless of your browser POST retries, Its always a good idea to check for what you receive before you dump it to the database. example: $firstName= $_POST['firstname']; $find = array("'"," ","\r\n","\r"); $replace = array(" "); $firstName = str_replace($find,$replace,$firstName); ====>You spacing problem should get fixed here. How do i clear the info in iChecks without Deleting the Column and the Table itself? Your options, update the column cell to " " or set it to null. example: SQL = "update tablename set columname = null where <condition>"; nl2br is great, but if you want your table to stay clear of html tags, its better to do strip_tags() first and write to db, and then use the wordwrap() method for rendering. Quote Link to comment https://forums.phpfreaks.com/topic/132837-solved-clearing-tables-data-html-table-issues/#findComment-691425 Share on other sites More sharing options...
Dekken Posted November 16, 2008 Author Share Posted November 16, 2008 Thanks for the Reply but my spacing problem is not fixed... if you want you can take a look... my sisters site >_> http://mathmatic.info/index.php everytime you refresh it just adds another row...and another one and another one thats my code right now. <?php $save_file = $_POST['save_file']; $TestDate = $_POST['CurrentDate']; $con = mysql_connect("XXXXXX","XXXXXX","XXXXXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } //Create the Database mysql_select_db("XXXX", $con); $sql = "CREATE TABLE Thenews ( personID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(personID), Datenow varchar(30), Coursenow varchar(30), Messagenow varchar(255) )"; mysql_query($sql, $con); if(!$sql) { echo mysql_error(); } mysql_select_db("XXXXX", $con); $sql="INSERT INTO Thenews (Datenow, Coursenow, Messagenow) VALUES ('$_POST[CurrentDate]','$_POST[CourseName]','$_POST[MessgeContent]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_select_db("XXXX", $con); $result = mysql_query("SELECT * FROM Thenews"); echo "<center>"; echo "<table border=1 dir=rtl>"; echo "<tr>"; echo "<th>DATE</th>"; echo "<th>COURSE</th>"; echo "<th>MESSAGE</th>"; echo "</tr>"; // THE ISSUE IS PROBABLY HERE while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td width=100 valign=top valign=top><font size=1>" . nl2br($row['Datenow']) . "</font></td>"; echo "<td valign=top width=70><font size=2>" . $row['Coursenow'] . "</font></td>"; echo "<td width=600><font size=2><b><i>" . nl2br($row['Messagenow']) . "</i></b></font></td>"; echo "</tr>"; } // THE ISSUE IS PROBABLY HERE echo "</table>"; echo "</center>"; echo mysql_error(); mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/132837-solved-clearing-tables-data-html-table-issues/#findComment-691455 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.