Ok so this is my first post so please be kind 🙂
I have a random key generator that generates a subscription key that saves it to a database. It will be used for authentication purposes. However, I keep getting this error message:
"Resource id #2 Could not connect3: 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 'KEY) VALUES (1, '66ENV306wkNlrLDN')' at line 1"
Here is the script:
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex">
<link href="style.css" rel="stylesheet" type="text/css" />
<title>XXXXX</title>
</head>
<body>
<?php
$codelenght = 16;
while($newcode_length < $codelenght) {
$x=1;
$y=3;
$part = rand($x,$y);
if($part==1){$a=48;$b=57;} // Numbers
if($part==2){$a=65;$b=90;} // UpperCase
if($part==3){$a=97;$b=122;} // LowerCase
$code_part=chr(rand($a,$b));
$newcode_length = $newcode_length + 1;
$newcode = $newcode.$code_part;
}
echo $newcode . " ";
?>
<?php
include('secsac.php');
$conver = mysql_connect($db_host, $db_username, $db_password);
if (!$conver)
{
die('Could not connect: ' . mysql_error());
}
if(!mysql_select_db($db_database, $conver))
{
die ('Could not connect to database: ' . mysql_error());
}
$MaxIdVer = "SELECT MAX(VID) + 1 as MaxId FROM membersverify";
$result1ver = mysql_query($MaxIdVer, $conver);
//if (!$result) {
//die('Could not connect to database table: ' . mysql_error());
//}
$rowVer = mysql_fetch_array($result1ver);
$newEntryVer = $rowVer['MaxId'];
$queryVer = "INSERT INTO membersverify (VID, KEY) VALUES ($newEntryVer, '$newcode')";
ProcessVerQuery($queryVer);
print "<h3>Update Successful!</h3>";
echo "code " . $newcode . " uploaded to DB.<br>";
?>
<?php
//database double check than disconnect
function ProcessVerQuery($queryVer) {
include('secsac.php');
$conver1 = mysql_connect($db_host, $db_username, $db_password);
echo $conver1;
if (!$conver1)
{
die('Could not connect1: ' . mysql_error());
}
if(!mysql_select_db($db_database, $conver1))
{
die ('Could not connect2: ' . mysql_error());
}
[COLOR="Red"]$resultsetVer = mysql_query($queryVer, $conver1);
echo $resultsetVer;
if(!$resultsetVer)
{
die ('Could not connect3: ' . mysql_error());
}[/COLOR]
mysql_close($conver1);
}
?>
</body>
</html>
The red area is where the error is thrown I believe. In addition, I have basically copy and pasted a database connection and upload script I have been using many times before on my server that I know it should work (with the correct adjustments to table names, attributes, and variable names in the insert and select statements). But for some reason it is not working and I cannot for the life of me figure it out.
Thank you for your time and consideration in responding to my post!