...

View Full Version : Don't input into database



zubat
12-31-2011, 07:18 AM
Hello,

i got my slef a problem with my code with the databaste input. I got an random code generator that i want to send a code when you call on the address with an sms function i got on a site. But when i do that i just get the code back but it wont get into the database. But if i do it manualy and go the site the code gets to database so if someone can take a look at the code i would be glad.




<?php
$con = mysql_connect ("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$code = mt_rand();
if (strlen($code) > 6)
{

$length = strlen($code);
$take = $length - 6;
$finalcode = substr($code, $take);

mysql_select_db("vip", $con);

$pw="INSERT INTO pw (code)
VALUES ('$finalcode')";

if (!mysql_query($pw,$con))
{
die('Error: ' . mysql_error());
}

echo "Din kod är $finalcode //Zobat";
}

mysql_close($con)
?>


//zubat

_Aerospace_Eng_
12-31-2011, 08:25 AM
Are you getting any errors? Can you post your table structure?

zubat
12-31-2011, 08:33 AM
Are you getting any errors? Can you post your table structure?

No im not getting any errors and the table struture or the one i did use to execute it is



CREATE TABLE pw
(id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
code VARCHAR(255),
datum date)

_Aerospace_Eng_
12-31-2011, 08:47 AM
Change this

$pw="INSERT INTO pw (code)
VALUES ('$finalcode')";

if (!mysql_query($pw,$con))
{
die('Error: ' . mysql_error());
}
to this

$pw="INSERT INTO pw (code) VALUES ('$finalcode')";
$result = mysql_query($pw,$con) or die('Error: ' . mysql_error());
echo $pw.'<br>';

Post the results.

zubat
12-31-2011, 04:17 PM
Edit: I did solve the problem :) i just needed to move down the database input to the end of the code instead of shearing it up in diffrent peases over the code :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum