Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 26-12-2006, 05:18 PM
Novice Webmaster
 
Join Date: Aug 2006
Location: Seri Kembangan
Posts: 12
Rep Power: 0
marukochan is on a distinguished road
Why my Query Not Working??

I have a script that when the user request for verification code, it will generate the verification code, store the verification code in the database and send the code to the user.

However, the code is not stored in the database. Can anybody check my script?

My script is :

<?php
$title = "Process Request";
include ("header_footer_function.php");

header_start();

// Connect to database to store verification code
mysql_connect("localhost", "root", "admin") or die(mysql_error());
mysql_select_db("project_db") or die(mysql_error());


// Function to generate random alphabets and numbers
function generate_str ($length) {
$characters = array('a','b','c','d','e','f','g','h','i','j','k', 'l','m','n','o','p','q','r','s','t','u','v','w','x ','y','z','0','1','2','3','4','5','6','7','8','9') ;
$random_str = "";
for ($i = 0; $i < $length; $i++) {
srand((double)microtime()*1000000);
$random_chr = round(rand(0, count($characters)-1));
$random_str .= $characters[$random_chr];
}
return ($random_str);
}

$code = generate_str(12);

// Store code in database
mysql_query("INSERT INTO code (code_string) VALUES ('$code')");

// Send e-mail
$subject = "Verification Code Request";
$email = $_POST['email'] ;
$name = $_POST['name'];
$company = $_POST['company'];
$message = "Name: $name\r\n"."Company: $company\r\n"."Verification Code: $code\r\n";
$headers = "From: xxxxx@xxx.com.my";

ini_set("SMTP","mail.xxx.com.my");
$sent = mail($email, $subject, $message, $headers) ;
if($sent)
{print "Please check your e-mail for verification code"; }
else
{print "We encountered an error sending your mail"; }

footer();
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 26-12-2006, 09:04 PM
robot's Avatar
Senior Webmaster
 
Join Date: Jul 2006
Location: My
Posts: 969
Rep Power: 46
robot will become famous soon enough
please check your db table field name is correct or you may discard the field name in the insert query by using this code

mysql_query("INSERT INTO code VALUES ('$code')");
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-01-2007, 11:11 AM
New kid on the block
 
Join Date: Jan 2007
Location: Sarawak
Posts: 9
Rep Power: 0
patcjh is on a distinguished road
Plz check if your value for $code fix into the column code_string.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-04-2007, 02:10 PM
genzy's Avatar
Nowhere Webmaster
 
Join Date: Aug 2006
Location: Malaysia
Posts: 1,581
Rep Power: 56
genzy is on a distinguished road
For tracing/debugging purpose, you may try to create a "testing" script just to test that particular lines of codes, i.e. executing the query.
- Validate the SQL query syntax, the table name, field name and field length against the input length etc.
- Or even, display out the SQL query and plug the query into the SQL front-end tool or the SQL console to manually execute the statement to ensure it is correct.

Suggest you can wrap up the lines that execute the SQL query as a method, in line with the concept of DAL (Data Access Layer) instead of scattering the SQL queries everywhere in different scripts, so that when it can be called in the testing script and then later reused in the development or production script.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Working at Home. mx_duo Job Vacancies 4 19-05-2008 03:57 AM
getURL() not working in IE7 ccool Website Programming 9 07-04-2007 06:10 AM
my 2CO a/c is not working.Help! ronan E-Commerce 4 03-12-2004 05:10 PM
Sql query untuk A+B-C ... nixx Website Programming 5 06-10-2004 04:51 PM
how to secured query string vash Website Programming 3 28-04-2004 02:47 PM



All times are GMT +8. The time now is 01:32 AM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59