Web Hosting Talk







View Full Version : PHP > MySql Query Help With Form Pls..


MyWinsVPS
06-28-2008, 04:37 PM
I have a signup form that I want to add a invite function to. Meaning I have a table called "invite" with a column name "code" with different numerical entries in the column that are already assigned to each member already.

I know how to do the html part of the form calling the "name" entry from the php action file. The problem that I have having is, the php file calling the

SELECT code FROM invite

to to enter in the invite "text" block on the on the signup form for new users. I dont want new users to sign up unless they have a code that is defined in the invite column which is assigned to an already member. Any help with this I would be deeply grateful.

Codebird
06-28-2008, 07:11 PM
don't know if I understood well but from what I understood the table invite should have something like id_member (id of the member that has that certain code) which is a foreign key that links table invite to table members.
here is the php code to use if what I understood is fine:


$code_query=mysql_query("SELECT `code` FROM `invite` WHERE `id_member`='$idMember'");
$code_array=mysql_fetch_assoc($code_query);
$code=$code_array["code"];


$code is the code of that member.

MyWinsVPS
06-28-2008, 08:50 PM
Ok I am going to try to explain a little better. What I am wanting to do is turn the sites security function in to a invite function. Security function being one of those "what is 1+1=answer" on the create account form.

Basically I am needing help on what to replace in the invite_code.php to make this work for the "answer" in the account.php file. I want it pulled from column 'code' from 'users' instead of a file like it is now. Hope this explains it a little better and thank you for your help.

So what I have in the account.php is

include("invite_code.php");
$scode_index=intval($_POST["security_index"]);
if ($security_code[$scode_index]["answer"]!=$_POST["scode_answer"])
{
err_msg($language["ERROR"],$language["ERR_IMAGE_CODE"]);
stdfoot();
exit;and in the invite_code.php it originally had

$security_code=array();
$security_code[]=array(
"question"=>"1+3",
"answer"=>"4"
);This is how the information should now be pulled. I put the code in with the users tables now to make it more simple instead of pulling from two tables.

mysql_query("SELECT `code` FROM `users` WHERE `id`='$id'");

MyWinsVPS
06-28-2008, 09:02 PM
The question part is defined by this. Not to worried about this, since this will not be used anyway. I can define that in the html part of the website. Just posting this for reference. If you think it would be easier to not use any of this and just make another "text" block on the create account form. Can you please post what I would need to put in the php part of the account file so if the code does not match what is in sql, it will give an error.

I have got everything else lines up with the codes showing up in the users control panel and all, this is the part that is just killing me.


include("invite_code.php");
$scode_index = rand(0, count($security_code) - 1);
$scode="<input type=\"hidden\" name=\"security_index\" value=\"$scode_index\" />\n";
$scode.=$security_code[$scode_index]["question"];
$tpl_account->set("scode_question",$scode);

Codebird
06-29-2008, 05:49 AM
I guess this would be invite_code.php:


$code_query=mysql_query("SELECT `code` FROM `users` WHERE `id`='$id'");
$code_array=mysql_fetch_assoc($code_query);
$code=$code_array["code"];


this would be account.php



//Id of the member should be set before including invite_code
$id=xxx;
include("invite_code.php");
//Testing the code with what the user entered
if ($code!=$_POST["scode_answer"])
{
err_msg($language["ERROR"],$language["ERR_IMAGE_CODE"]);
stdfoot();
exit;