Jump to content

form with php self wont show up.


Russia

Recommended Posts

I currently have this code:

 

<?php

mysql_connect("localhost", "brian_keys", "******") or die(mysql_error());
mysql_select_db("brian_keys") or die(mysql_error())

if (isset ($_POST['submit'])) // if the form was submitted, display their name
{

$key = addslashes(htmlentities($_POST['key']));
if ($key == "") {
die("No key found");
}
$query = "SELECT * FROM keys WHERE key='".$key."'";
$result = mysql_query($query) or die("Could not execute query");
if (mysql_num_rows($result) > 0) {
echo "Key valid";

// Setting the key activated

$query = "UPDATE keys SET activation='yes' WHERE key='".$key."'";
$result = mysql_query($query);
} else {
echo "Key invalid";
}



}
else // form hasn't been submitted, so display the form
{
echo '<form method="POST" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
<input type="text" name="key">
<input type="submit" value="Submit!">
</form>';
}

?>

 

Its a form to check if the licence key someone provided during an installation of a script is valid or not, you enter the key in the form and it tells you if its valid, used or invalid.

 

For some reason the form wont show up at all and there seems to be no errors in the coding, does anyone spot the problem?

 

Thanks in advance.

Link to comment
Share on other sites

<?php

mysql_connect("localhost", "brian_keys", "123321") or die(mysql_error());
mysql_select_db("brian_keys") or die(mysql_error())

if (isset ($_POST['submit'])) // if the form was submitted, display their name
{

$key = addslashes(htmlentities($_POST['key']));
if ($key == "") {
die("No key found");
}
$query = "SELECT * FROM keys WHERE key='".$key."'";
$result = mysql_query($query) or die("Could not execute query");
if (mysql_num_rows($result) > 0) {
echo "Key valid";

// Setting the key activated

$query = "UPDATE keys SET activation='yes' WHERE key='".$key."'";
$result = mysql_query($query);
} else {
echo "Key invalid";
}



}
else // form hasn't been submitted, so display the form
{
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="key">
<input type="submit" value="Submit!">
</form>
<?php
}

?>

 

ALright I fixed it, but it still wont show up... Whats the problem in the coding???

Link to comment
Share on other sites

ALright, I found and fixed the error, but now the form shows up and doesnt work, it goes to pho self but doesnt give an error when there is no key entered, invalid or valid, it just reshows the form, what am I doing wrong???

 

<?php


if (isset ($_POST['submit'])) // if the form was submitted, display their name
{
mysql_connect("localhost", "brian_keys", "******") or die(mysql_error());
mysql_select_db("brian_keys") or die(mysql_error());


$key = addslashes(htmlentities($_POST['key']));
if ($key == "") {
echo "no key found";
}
$query = "SELECT * FROM keys WHERE key='".$key."'";
$result = mysql_query($query) or die("Could not execute query");
if (mysql_num_rows($result) > 0) {
echo "Key valid";

// Setting the key activated

$query = "UPDATE keys SET activation='yes' WHERE key='".$key."'";
$result = mysql_query($query);
} else {
echo "Key invalid";
}



}
else // form hasn't been submitted, so display the form
{
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<input type="text" name="key">
<input type="submit" value="Submit!">
</form>
<?php
}

?>

Link to comment
Share on other sites

Oh, got it to work, now it gives me a new error when I proccess the form, it says:

 

Could not execute query

 

Its part of the OR DIE thing.

 

Is it because it cannot find the table or why?

 

 <?php


if (isset ($_POST['submit'])) // if the form was submitted, display their name
{


mysql_connect("localhost", "brian_keys", "123321") or die(mysql_error());
mysql_select_db("brian_keys") or die(mysql_error());


$key = addslashes(htmlentities($_POST['key']));
if ($key == "") {
echo "no key found";
}
$query = "SELECT * FROM keys WHERE key='".$key."'";
$result = mysql_query($query) or die("Could not execute query");
if (mysql_num_rows($result) > 0) {
echo "Key valid";

// Setting the key activated

$query = "UPDATE keys SET activation='yes' WHERE key='".$key."'";
$result = mysql_query($query);
} else {
echo "Key invalid";
}



}
else // form hasn't been submitted, so display the form
{
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="key">
<input type="submit" name="submit" value="Submit!">
</form>
<?php
}

?>

 

Is it unable to get the table or the column?

 

 

Link to comment
Share on other sites

Only form fields that have name="..." attributes are submitted to the server. Your submit form field does not have a name and the php code testing if (isset ($_POST['submit'])) is always false.

 

In my experience submit is SET, but it's empty, so that works.

 

ALright, I found and fixed the error, but now the form shows up and doesnt work, it goes to pho self but doesnt give an error when there is no key entered, invalid or valid, it just reshows the form, what am I doing wrong???

 

if ($key == "") {
echo "no key found";
}

 

You don't do anything if the key is empty.. :) return false or die() it. :)

Link to comment
Share on other sites

Oh, got it to work, now it gives me a new error when I proccess the form, it says:

 

Could not execute query

 

Its part of the OR DIE thing.

 

Is it because it cannot find the table or why?

 

Is it unable to get the table or the column?

 

Print out mysql_error() after the simple error message, so you can see what's wrong.

mysql_query() or die("Could not execute query. ".mysql_error())

Link to comment
Share on other sites

Alright, I was able to fix that too.

 

Now I have another problem, some kind of syntax error:

no key found You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'keys WHERE key=''' at line 1

 

This is the line its talking about

$query = "SELECT * FROM keys WHERE key='".$key."'";

 

I think its that last part, were its using the $key variable.

 

Are the single quotes, periods, or quotes around it messing it up?

 

from this whole script:

 

<?php


if (isset ($_POST['submit'])) // if the form was submitted, display their name
{


mysql_connect("localhost", "brian_keys", "*******") or die(mysql_error());
mysql_select_db("brian_keys") or die(mysql_error());


$key = addslashes(htmlentities($_POST['key']));
if ($key == "") {
echo "no key found";
}
$query = "SELECT * FROM keys WHERE key='".$key."'";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
echo "Key valid";

// Setting the key activated

$query = "UPDATE keys SET activation='yes' WHERE key='".$key."'";
$result = mysql_query($query);
} else {
echo "Key invalid";
}



}
else // form hasn't been submitted, so display the form
{
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="key">
<input type="submit" name="submit" value="Submit!">
</form>
<?php
}

?>

Link to comment
Share on other sites

 

Now I have another problem, some kind of syntax error:

no key found You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'keys WHERE key=''' at line 1

 

This is the line its talking about

$query = "SELECT * FROM keys WHERE key='".$key."'";

 

What kind of data is that key? If it's INT you don't need quotes.

Link to comment
Share on other sites

WOO!! that simple.... crap i feel like an idiot, also, can I ask for one more thing, I would also like to add a message if the key has already been used, that means that if activation column is already set to yes it gives an error message saying like License key already used.

 

How am I able to do that?

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.