I wrote a program to generate a random code that the user would use to
gain access to a survey page. I got the code to generate fine;
however it will not store into the db. It gave me the generated code
then:
************************
hn3fXAaah1
Query failed cause: 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 '' '' at line 1
************************
Help please.
<?PHP
if(isset($_POST['getcodes']))
{
$num = $_POST['num'];
$got = 0;
while ($got < $num)
{
$random = " ";// Initialize the string to store random numbers
srand((double)microtime()*1000000);
$block = "ABCDEFGHJKLMNPQRSTUVWXYZ";
$block .= "abcdefghjkmnpqrstuvwxyz";
$block .= "0123456789";
for($i = 0; $i < 10; $i++)
{
$random.= substr($block,(rand()%(strlen($block))), 1);
}
echo "$random<BR>";
$sql= "INSERT into $db_table10 (id) VALUES '$random'" ;
mysql_query ($sql) or die('Query failed cause: ' . mysql_error());
$got++;
}
}
?> 6 1293
up2trouble wrote:
I wrote a program to generate a random code that the user would use to
gain access to a survey page. I got the code to generate fine;
however it will not store into the db. It gave me the generated code
then:
************************
hn3fXAaah1
Query failed cause: 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 '' '' at line 1
************************
Help please.
<?PHP
if(isset($_POST['getcodes']))
{
$num = $_POST['num'];
$got = 0;
while ($got < $num)
{
$random = " ";// Initialize the string to store random numbers
srand((double)microtime()*1000000);
$block = "ABCDEFGHJKLMNPQRSTUVWXYZ";
$block .= "abcdefghjkmnpqrstuvwxyz";
$block .= "0123456789";
for($i = 0; $i < 10; $i++)
{
$random.= substr($block,(rand()%(strlen($block))), 1);
}
echo "$random<BR>";
$sql= "INSERT into $db_table10 (id) VALUES '$random'" ;
mysql_query ($sql) or die('Query failed cause: ' . mysql_error());
$got++;
}
}
?>
what is the datatype of $db_table10 (id)?? Is ID a number? or varchar
field? My guess is a number - in which case you cannot store a text
value in a number field.
..oO(up2trouble)
>I wrote a program to generate a random code that the user would use to gain access to a survey page. I got the code to generate fine; however it will not store into the db. It gave me the generated code then: ************************ hn3fXAaah1 Query failed cause: 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 '' '' at line 1 ************************ [...]
echo "$random<BR>"; $sql= "INSERT into $db_table10 (id) VALUES '$random'" ; mysql_query ($sql) or die('Query failed cause: ' . mysql_error()); $got++;
$sql= "INSERT into $db_table10 (id) VALUES ('$random')";
Micha
..oO(up2trouble)
>while ($got < $num) { $random = " ";// Initialize the string to store random numbers
srand((double)microtime()*1000000);
$block = "ABCDEFGHJKLMNPQRSTUVWXYZ"; $block .= "abcdefghjkmnpqrstuvwxyz"; $block .= "0123456789";
for($i = 0; $i < 10; $i++) { $random.= substr($block,(rand()%(strlen($block))), 1); }
BTW:
You can access single characters in a string directly with [] instead of
substr() and calling srand() is not necessary anymore as of PHP 4.2:
$random = '';
$length = strlen($block)-1;
for ($i = 0; $i < 10; $i++) {
$random .= $block[rand(0, $length)];
}
Micha
On 20 Mar, 00:54, up2trouble <lynettesm...@gmail.comwrote:
I wrote a program to generate a random code that the user would use to
gain access to a survey page. I got the code to generate fine;
however it will not store into the db. It gave me the generated code
then:
************************
hn3fXAaah1
Query failed cause: 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 '' '' at line 1
************************
Help please.
<?PHP
if(isset($_POST['getcodes']))
{
$num = $_POST['num'];
$got = 0;
while ($got < $num)
{
$random = " ";// Initialize the string to store random numbers
srand((double)microtime()*1000000);
$block = "ABCDEFGHJKLMNPQRSTUVWXYZ";
$block .= "abcdefghjkmnpqrstuvwxyz";
$block .= "0123456789";
for($i = 0; $i < 10; $i++)
{
$random.= substr($block,(rand()%(strlen($block))), 1);
}
echo "$random<BR>";
$sql= "INSERT into $db_table10 (id) VALUES '$random'" ;
mysql_query ($sql) or die('Query failed cause: ' . mysql_error());
$got++;}
}
?>
Rather than publishing so much code it would have been so much easier
to just print $sql and send that in your posting. The code above won't
produce valid SQL because $db_table10 is not defined.
C.
up2trouble wrote:
I wrote a program to generate a random code that the user would use to
gain access to a survey page. I got the code to generate fine;
however it will not store into the db. It gave me the generated code
then:
************************
hn3fXAaah1
Query failed cause: 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 '' '' at line 1
************************
Help please.
<?PHP
if(isset($_POST['getcodes']))
{
$num = $_POST['num'];
$got = 0;
while ($got < $num)
{
$random = " ";// Initialize the string to store random numbers
srand((double)microtime()*1000000);
$block = "ABCDEFGHJKLMNPQRSTUVWXYZ";
$block .= "abcdefghjkmnpqrstuvwxyz";
$block .= "0123456789";
for($i = 0; $i < 10; $i++)
{
$random.= substr($block,(rand()%(strlen($block))), 1);
}
echo "$random<BR>";
$sql= "INSERT into $db_table10 (id) VALUES '$random'" ;
mysql_query ($sql) or die('Query failed cause: ' . mysql_error());
$got++;
}
}
?>
Store the gain access code in a session variable.. No need sql'ing
stuff...
Thanks. I have it working now and storing into db. Others problems
have now arisen. I think I'm supposed to put them in a new post cause
it is a new problem. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Manish Naik |
last post by:
Hi,
Using ASP.Net, I want to store and retrive documents (Word, excel,
etc) from SQL Server 2000 database. I have tried image type data
field, but could not succed. Can any one help me please.
...
|
by: Brad |
last post by:
I have written some code to manipulate data/records in a MASTER (order
header) and DETAIL (order details) tables.
What I have written is too extensive to post but essentially trying to:
1....
|
by: nacho222 |
last post by:
I'm currently in the middle of writing a persistence framework, and I
have to make a design decission. The framework will take care of all
the saving and restoring objects, and also the...
|
by: Robin Mark Tucker |
last post by:
Hi, apologies for the cross post, if you also subscribe to the
aspnet.webservices group, I'm new to asp.net so I'm still finding the
newsgroup sweet spots ;)
Anyway, my question is, how can I...
|
by: (PeteCresswell) |
last post by:
User wants to go this route instead of storing pointers in the DB and the
documents outside.
Only time I tried it was with only MS Word docs - and that was a loooong time
ago - and it seemed to...
|
by: Mark |
last post by:
I'm consuming a webservice that makes a simple object available. The object
class is marked in the web service as . I have a web
application that consumes and uses this web service's class. When...
|
by: quirdan |
last post by:
Hi,
I am after some advice about which data structures I should use. I'm developing a program and I am at the point where all the strings are being generated and printed one by one with...
|
by: RSH |
last post by:
Hi,
I have a situation where I have created an object that contains
fields,properties and functions. After creating the object I attempted to
assign it to a session variable so i could retrieve...
|
by: yomama |
last post by:
Hello,
I am writing a program in which I take a string (specifically, first and last name with a space in between) from the user and put it into a data member of a class node. I have tried various...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |