Jump to content

[SOLVED] Clearing Tables Data + HTML Table issues.


Dekken

Recommended Posts

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

 

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.

 

 

 

 

 

 

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);
?>

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.