Jump to content

HTML submit button within PHP


ArizonaJohn

Recommended Posts

 

Hello,

 

The first section of code below returns a message that says "The topic 'x' has not been added." if a user enters a topic that is not in my database.  I would like to give the user the option to add "x" to the database by clicking on an HTML submit button.  So I guess my problem is that I don't know how to add an HTML submit button within PHP that would post $name=$find to tprocess.php and then trigger the code in tprocess.php.  How do I do that?

 

Thanks.

 

$anymatches=mysql_num_rows($result);
if ($anymatches == 0)
{

print "<p class=\"topic2\">The topic \"$find\" has not been added.</p>\n";

print "<p class=\"topic2\">Add the topic \"$find\".</p>\n";

<form action="tprocess.php" method="post">;
$name=$find;
<input type="submit" value="Submit">";
</form>; 

 

Below is what I have on tprocess.php.  It is code that adds a topic to my database:

 

if (isset($_POST['name']) && !empty($_POST['name'])) {
mysql_connect("mysqlv10", "username", "password") or
die(mysql_error());
mysql_select_db("database") or die(mysql_error());

$table = mysql_real_escape_string($_POST['name']);

$query = "CREATE TABLE `$table` (id INT(11) NOT NULL auto_increment, site VARCHAR(150) NOT NULL, votes_up BIGINT(9) NOT NULL, votes_down BIGINT(9) NOT NULL, PRIMARY KEY(id), UNIQUE (site))";
$result = mysql_query($query) or die(mysql_error());


}

 

Link to comment
https://forums.phpfreaks.com/topic/160557-html-submit-button-within-php/
Share on other sites

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.