Be a Supporter!

mysql

  • 283 Views
  • 4 Replies
New Topic Respond to this Topic
yoyobebob
yoyobebob
  • Member since: Mar. 16, 2006
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
mysql 2009-10-06 19:31:26 Reply

I'm having trouble inserting data into a table:

function genRandomString() {
    $length = 10;
    $characters = "0123456789abcdefghijklmnopqrstuvwxyz";
     

    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }

    return $string;
}
			genRandomString();

			mysql_select_db("DATABASE", $con);
			$sql = "INSERT INTO hits VALUES ('3', " . $string . ")";
			mysql_query($sql);

Why doesn't this insert the data into the table?


I love xbox live and I like flash games too!

BBS Signature
fourthfrench
fourthfrench
  • Member since: Aug. 13, 2009
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to mysql 2009-10-06 19:49:57 Reply

You never stored getRandomString()...

$string=getRandomString();
yoyobebob
yoyobebob
  • Member since: Mar. 16, 2006
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to mysql 2009-10-06 19:53:31 Reply

thanks, but it still isn't working...


I love xbox live and I like flash games too!

BBS Signature
urbn
urbn
  • Member since: Jun. 10, 2007
  • Offline.
Forum Stats
Member
Level 18
Programmer
Response to mysql 2009-10-06 23:14:10 Reply

At 10/6/09 07:53 PM, yoyobebob wrote: thanks, but it still isn't working...

Just to clarify you did this didn't you? :

function genRandomString() {
    $length = 10;
    $characters = "0123456789abcdefghijklmnopqrstuvwxyz";
     

    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }

    return $string;
}
			$string = genRandomString();

			mysql_select_db("DATABASE", $con);
			$sql = "INSERT INTO hits VALUES ('3', " . $string . ")";
			mysql_query($sql);

and didn't include that guys typo?


BBS Signature
CronoMan
CronoMan
  • Member since: Jul. 19, 2004
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to mysql 2009-10-07 10:21:19 Reply

strings (varchar, nchar, nvarchar, text etc) must be enclosed in single-quotes in sql


"no sound in ass"