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
Share on other sites

try inserting a marker in your insert statment, to make sure its really executed like

 

mysql_query($query) or die('Could not query: ' . mysql_error());

echo 'my query was executed';

 

also try making some error codes, maybe error reporting is off.

Link to comment
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>";

}

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.