How to submit data into the database??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
truce enough
Forum Newbie
Posts: 8
Joined: Fri Sep 02, 2011 12:53 am

How to submit data into the database??

Post by truce enough »

Hi,

Code: Select all

<?php 

$result3 = mysql_query("SELECT * FROM post_data ORDER BY id");
$content = $row['content'];


$dates = date("l, F d, Y " );

$id = $_GET['id'];
$result4 = mysql_query("SELECT id FROM user_comments WHERE id = '$id'");
$result3 = mysql_query("SELECT id FROM post_data WHERE id = '$id'");
$num_rows = mysql_num_rows($result3);
$num_rows1 = mysql_num_rows($result4);
$result = mysql_query("SELECT * FROM post_data WHERE id = '$id'");
$result2 = mysql_query("SELECT * FROM user_comments WHERE id = '$id' ORDER BY date_comment");
$row = mysql_fetch_array($result);



if (mysql_num_rows($result3)==0){
    header('location:viewquestions.php');
}else{

 
     // Your normal code




echo "<table class='backbtn' border='0'>";
echo "<tr>";
echo "<td class='backbtn'>" . "<a class='backbtn' href='viewquestions.php'>" . "Back" . "</a>" . "</td>";
echo "</tr>";
echo "</table>";


echo "<table class='title' border='0'>";

echo "<tr>";
echo "<td class='title'>" . $row['text'] . "</td>";  
echo "</tr>";
echo "<tr>";
echo "</table>";


echo "<table border = '0' class='post'>";





if (isset($_POST['Submit'])){
if (empty($_POST['name']) || empty($_POST['post']))
		{
		$Text = "Please fill in all the fields.";
echo "<script type='text/javascript'>alert('{$Text}');</script>";

	}
	else
	{
	
	
mysql_query("INSERT INTO user_comments (id,comment,date_comment,name)VALUES ('$id','$_POST[post]','$dates','$_POST[name]')");
header('location:view_place1.php?id=' . $id);
}
}
}


?>
<?php 
if($num_rows1 > 3){
	echo "This page has reached the maximum posts:D";
	
	
echo "<table class='comment' border='0'>";

while($row2 = mysql_fetch_array($result2))
{
	
	echo "<tr class='user_comment'>";
	echo "<td class='user'>"  . "<div class='commentuser'>" . $row2['name'] . "</div>" . "<div class='commentdate'>" . $row2['date_comment'] . "</div>" . "</td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td class='usercomment'>" . $row2['comment'] . "</td>";
	"</tr>";
}

echo "</table>";
}
else
{
if($num_rows1 < 1){
echo "	
<table class='commentbox' border='0'>
<tr>
<td>
<form class='comment' method='post' action=''>
Name<p align='center'><textarea name='name' tabindex='4' title='name' id='comment' class='forminput' rows='3' cols='30' name='comment'  ></textarea></p>
Comments<p align='center'><textarea name='post' tabindex='4'  id='comment' class='forminput' rows='3' cols='30' name='comment'></textarea></p>
<p align='center'><input type='submit' value='Submit' class='submitbtn' name='Submit' onclick='this.disabled=true' id='Submit' /></p>
</form>
</td>
</tr>
</table>";
}
else{
echo "<table class='comment' border='0'>";

while($row2 = mysql_fetch_array($result2))
{
	
	echo "<tr class='user_comment'>";
	echo "<td class='user'>"  . "<div class='commentuser'>" . $row2['name'] . "</div>" . "<div class='commentdate'>" . $row2['date_comment'] . "</div>" . "</td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td class='usercomment'>" . $row2['comment'] . "</td>";
	"</tr>";
}

echo "</table>";

echo "	
<table class='commentbox' border='0'>
<tr>
<td>
<form class='comment' method='post' action=''>
Name<p align='center'><textarea name='name' tabindex='4' title='name' id='comment' class='forminput' rows='3' cols='30' name='comment'  ></textarea></p>
Comments<p align='center'><textarea name='post' tabindex='4'  id='comment' class='forminput' rows='3' cols='30' name='comment'></textarea></p>
<p align='center'><input type='submit' value='Submit' class='submitbtn' name='Submit' onclick='this.disabled=true' id='Submit' /></p>
</form>
</td>
</tr>
</table>";
}
}
?>
After i echo the textbox inside php, my code doesn't work.
it can only work inside html and outside php, so can anyone please tell me where did i do wrong?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: How to submit data into the database??

Post by twinedev »

When you say "my code doesn't work", what do you mean? Is it generating an error? Are you not getting the code you are expecting? Or is is that it just doesn't "look right" in the browser (ie. if you do view source, do you see what was expected)?

-Greg
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: How to submit data into the database??

Post by twinedev »

Just noticed something I missed at first. You have name= twice on the textareas, and the second time you use it, you give the same name, name='comment'

Additionally you have repeated ID's and tabindex's.. Really looks like you took one piece of code and copied it over and over without properly changing all attributes of it.

-Greg
Post Reply