martynball
New Member
- Messages
- 60
- Reaction score
- 0
- Points
- 0
Question 1:
Sorry about the vast amount of threads I am making, but don't want to confuse people by posting new questions in the same threads.
Here, I have a form, and action script. It updates my database with the values in the form. The only problem with it is that when I click submit, the script is loaded up and has the echo written on the screen.
I do not want this, I want it to write something like "Updated Successfully" under the submit button, or at least load a different page.
update.php
-------------------------------------------------
Question 2:
How can I make this php code display the results in a certain order, e.g. smallest "id" number first.
Sorry about the vast amount of threads I am making, but don't want to confuse people by posting new questions in the same threads.
Here, I have a form, and action script. It updates my database with the values in the form. The only problem with it is that when I click submit, the script is loaded up and has the echo written on the screen.
I do not want this, I want it to write something like "Updated Successfully" under the submit button, or at least load a different page.
PHP:
<form name="form1" method="post" action="scripts/update.php" onsubmit="return validate_form(this)">
<p class="g2">Name:</p>
<input type="text" class="contact-feild" name="name" size="20" />
<br />
<p class="g2">Email:</p>
<input type="text" class="contact-feild" name="email" size="20" />
<br />
<p class="g2">Message:</p>
<textarea name="message" class="contact-feild" style="width:300px; height:150px; overflow:scroll; overflow-x:hidden;">
</textarea>
<br />
<input type="submit" value="Submit" class="button" name="submit"/>
</form>
update.php
PHP:
<?php
// Connect to database
$con = mysql_connect("localhost","martynba_martynb","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Select table
mysql_select_db("martynba_comments", $con);
// Make varibles
date_default_timezone_set('GMT');
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$message = mysql_real_escape_string($_POST['message']);
$date = date("F j, Y, g:i a");
// Insert data
$query="INSERT INTO commentTable ( NAME, EMAIL, MESSAGE, DATE)
VALUES ('".$name."','".$email."','".$message."','".$date."')";
$result = mysql_query ($query);
echo "<p class=\"g2\">Thanks for your comment $name!</p>";
?>
-------------------------------------------------
Question 2:
How can I make this php code display the results in a certain order, e.g. smallest "id" number first.
PHP:
<?php
// Connect to the database server
mysql_connect('localhost', 'martynba_martynb', 'password') or die('Error connecting to the database: ' . mysql_error());
// Select the database
mysql_select_db('martynba_comments') or die('Error selecting database: ' . mysql_error());
//Get data...
$result = mysql_query("select * from commentTable");
while ($row = mysql_fetch_array($result))
{
$id=$row["ID"];
$name=$row["NAME"];
$message=$row["MESSAGE"];
$email=$row["EMAIL"];
$today= $row["DATE"];
//Display results
echo "<table class=\"comment-table\">";
echo "<tr>";
echo "<td class=\"comment-name\">Posted by: $name<div class=\"comments-date\">$today</div></td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"comment-message\">$message";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"comment-id\">ID: $id";
echo "<form method=\"post\" action=\"scripts/delete.php\" class=\"del-form\"><input name=\"id\" id=\"id\" type=\"hidden\" value=\"$id\"><input type=\"image\" src=\"../images/del.png\"></form></td>";
echo "</tr>";
echo "</table>";
echo "<br />";
}
?>
Last edited: