Jump to content

[SOLVED] My form isn't working


helpmeplease2

Recommended Posts

Why doesn't this work? Is it because the $php_self doesn't work with pages like www.example.com?p=vgrgr&gerr=S&video=name

 

if($_POST['submityes']=="yes"){
$name=$_POST['name'];
$comment=$_POST['comment'];
$query="INSERT INTO comments (Name,Comment) VALUES ('$name','$comment')";
mysql_query($query) or die('Could not query: ' . mysql_error());

}else{

echo "<form name=\"commentsform\" action=\"$PHP_SELF\" method=\"post\">
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr><td>Name: </td><td><input type=\"text\" name=\"name\" size=\"30\"><br></td></tr>
<tr><td>Comments: </td><td><textarea name=\"comment\" rows=\"6\" cols=\"40\" wrap=\"virtual\"></textarea></td></tr></table>
<input type=\"hidden\" name=\"submityes\" value=\"yes\">
<input type=\"submit\" value=\"Add Comments\"></form>";

}

Link to comment
https://forums.phpfreaks.com/topic/46372-solved-my-form-isnt-working/
Share on other sites

It turns out it was inserting it, but not everything I wanted. I modified the code, but its still not inserting the Game and Video. The $gtitle and $vtitle are from the url.

 

if($_POST['submityes']=="yes"){
$gtitle=$_GET['game'];
$vtitle=$_GET['video'];
$result = mysql_query("SELECT * FROM videos WHERE GTitle='$gtitle' AND VTitle='$vtitle'")
or die(mysql_error());
while($row = mysql_fetch_row( $result )) {
$name=$_POST['name'];
$game=$row['GTitle'];
$video=$row['VTitle'];
$comment=$_POST['comment'];

$query="INSERT INTO comments (Name,Game,Video,Comment) VALUES ('$name','$game','$video','$comment')";
mysql_query($query) or die('Could not query: ' . mysql_error());
}
}else{

echo "<form name=\"commentsform\" action=\"$PHP_SELF\" method=\"post\">
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr><td>Name: </td><td><input type=\"text\" name=\"name\" size=\"30\"><br></td></tr>
<tr><td>Comments: </td><td><textarea name=\"comment\" rows=\"6\" cols=\"40\" wrap=\"virtual\"></textarea></td></tr></table>
<input type=\"hidden\" name=\"submityes\" value=\"yes\">
<input type=\"submit\" value=\"Add Comments\"></form>";

}

Arghhh I was trying to do it the hard way! I could've just put

$name=$_POST['name'];
$game=$_GET['game'];
$video=$_GET['video'];
$comment=$_POST['comment'];
$query="INSERT INTO comments (Name,Game,Video,Comment) VALUES ('$name','$game','$video','$comment')";
mysql_query($query) or die('Could not query: ' . mysql_error());

 

That is working, thanks for the help!

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.