Jump to content

fefster

Newly Registered
  • Posts

    10
  • Joined

  • Last visited

fefster's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello, Please be gentle, I am a newbie! I was wondering if anyone would be kind enough to help me with this task which I am finding very difficult. I want to have a form on my Wordpress site where people can create a username, password, give a voucher code and their details. This will then query a database and if the voucher code is correct, then it will automatically log them in to Moodle. I have created the database, put a few test codes in and it seems to work okay, but it dosen't go to the login page for Moodle, despit me putting this URL in the action. Here is the code and URLs. If anyone can help, that would be great. I didn't write this code and I am a beginner so if you could keep it simple, that would be appreciated. <?php // Exit if accessed directly if ( !defined('ABSPATH')) exit; /** * Pages Template * * * @file page.php * @package Responsive * @author Emil Uzelac * @copyright 2003 - 2012 ThemeID * @license license.txt * @version Release: 1.0 * @filesource wp-content/themes/responsive/page.php * @link http://codex.wordpress.org/Theme_Development#Pages_.28page.php.29 * @since available since Release 1.0 */ if (isset($_POST['submit'])) { //Enter host, username and password respectively. $dbhost = 'localhost'; $dbuser = 'jennyfef_voucher'; $dbpass = 'EO7Qm44B'; $dbName = 'jennyfef_vouchers'; //Connect to Database -------------------------------- $connection = mysql_connect($dbhost, $dbuser, $dbpass); if (!$connection) { die('Could not connect: ' . mysql_error()); } @mysql_select_db($dbName) or die( "Not Possible to Connect to Database"); //END Connect to Database -------------------------------- $voucherTable = <<<CREATE create table vouchers ( ID int primary key not null auto_increment, voucherCode text, username text, password text, email text, firstname text, lastName text, house text, postcode text, street text, city text, contactNumber text, timeOfUpload int) CREATE; @mysql_query($voucherTable); $requiredFields=TRUE; $missingFieldsString=""; $postArray = array( "username" => "Username", "password" => "Password", "email" => "Email", "firstname" => "First Name", "lastName" => "Last Name", "house" => "House Name or Number", "postcode" => "Postcode", "street" => "Street", "city" => "Town or City", "contactNumber" => "Contact Number", "voucherCode" => "Voucher Code", ); foreach ($postArray as $key => $value) { if(($_POST[$key] == NULL) or ($_POST[$key] == "")){ $requiredFields = FALSE; $missingFieldsString .= $value.", "; } } if(strlen($missingFieldsString) > 2){ $missingFieldsString = substr($missingFieldsString, 0, strlen($missingFieldsString)-2); } if(!$requiredFields){ header( 'Location: http://www.institute-of-photography.com/voucher-redemption/?errorCode=100&missingFields='.urlencode($missingFieldsString)); exit; } $voucherCode=$_POST['voucherCode']; $sqlQueryToRun="SELECT * FROM vouchers WHERE voucherCode = '$voucherCode'"; $queryResult=mysql_query($sqlQueryToRun); $numberOfEntries=mysql_num_rows ($queryResult); if(($numberOfEntries != 0) && ($numberOfEntries < 2)){ $row = mysql_fetch_row($queryResult); //echo $row[0]; //mysql_query("UPDATE secure SET currentViews='$currentViews' WHERE username = '$currentUser'"); }else{ header( 'Location: http://www.institute-of-photography.com/voucher-redemption/?errorCode=200'); } } ?> <?php get_header(); ?> <style> table, .voucherTable td, .voucherTable th { border:0; } </style> <div id="content" class="grid col-620"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <?php $options = get_option('responsive_theme_options'); ?> <?php if ($options['breadcrumb'] == 0): ?> <?php echo responsive_breadcrumb_lists(); ?> <?php endif; ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h1 class="post-title"><?php the_title(); ?></h1> <?php if ( comments_open() ) : ?> <?php endif; ?> <div class="post-entry"> <?php the_content(__('Read more ›', 'responsive')); ?> <?php wp_link_pages(array('before' => '<div class="pagination">' . __('Pages:', 'responsive'), 'after' => '</div>')); ?> </div><!-- end of .post-entry --> <?php if ( comments_open() ) : ?> <div class="post-data"> <?php the_tags(__('Tagged with:', 'responsive') . ' ', ', ', '<br />'); ?> <?php the_category(__('Posted in %s', 'responsive') . ', '); ?> </div><!-- end of .post-data --> <?php endif; ?> <div class="post-edit"><?php edit_post_link(__('Edit', 'responsive')); ?></div> </div><!-- end of #post-<?php the_ID(); ?> --> <?php //comments_template( '', true ); ?> <?php endwhile; ?> <? switch ($_GET['errorCode']) { case 100: echo '<div style="border-radius:5px; display:block; background-color:#FF9494; width:100%; padding-top:10px; padding-bottom:10px; text-align:center; border:1px solid #f00; ">Error - Please fill in all compulsary fields: <div style=" font-weight:bold; ">'.$_GET['missingFields'].'</div> </div> '; break; case 200: echo '<div style="border-radius:5px; display:block; background-color:#FF9494; width:100%; padding-top:10px; padding-bottom:10px; text-align:center; border:1px solid #f00; ">Error - Invalid Voucher Code. Please try again. </div> '; break; } ?> <form action="http://www.institute-of-photography.com/moodle/login/index.php/ id="voucherForm" method="post" class="voucherForm"> <table width="400" border="0" class="voucherTable"> <tr> <td width="150" class="r"> Username: <span style="color:#f00;">*</span></td> <td colspan="2"> <input type="text" placeholder="Username" id="username" name="username" class="field" style="width:270px;" required="required" > </td> </tr> <tr> <td width="150" class="r"> Password: <span style="color:#f00;">*</span></td> <td colspan="2"> <input type="password" placeholder="Password" id="password" name="password" class="field" style="width:270px;" required="required" ></td> </tr> <tr> <td width="150" class="r">Email: <span style="color:#f00;">*</span></td> <td colspan="2"> <input type="text" placeholder="Email Address" id="email" name="email" class="field" style="width:270px;" ></td> </tr> <tr> <td width="150" class="r"> First Name: <span style="color:#f00;">*</span> </td> <td colspan="2"> <input type="text" placeholder="First Name" id="firstName" name="firstname" class="field" style="width:270px;" ></td> </tr> <tr> <td width="150" class="r"> Last Name: <span style="color:#f00;">*</span></td> <td colspan="2"> <input type="text" placeholder="Last Name" id="lastname" name="lastName" class="field" style="width:270px;" ></td> </tr> <tr> <td width="150" class="r"> House Name or Number:<span style="color:#f00;"> *</span></td> <td width="72"> <input type="text" placeholder="House #" id="house" name="house" class="field" style="width:100px;" ></td> </tr> <tr> <td width="150">Postcode: <span style="color:#f00;">*</span> </td> <td colspan="2"> <input type="text" placeholder="Postcode" id="postcode" name="postcode" class="field" style="width:100px;" ></td> </tr> <tr> <td width="150">Street: <span style="color:#f00;">*</span> </td> <td colspan="2"> <input type="text" placeholder="Street" id="street" name="street" class="field" style="width:270px;" ></td> </tr> <tr> <td width="150">Town/City: <span style="color:#f00;">*</span> </td> <td colspan="2"> <input type="text" placeholder="Town or City" id="city" name="city" class="field" style="width:270px;" > </td> </tr> <tr> <td width="150">Contact Number: <span style="color:#f00;">*</span> </td> <td colspan="2"> <input type="text" placeholder="Contact Number" id="contactNumber" name="contactNumber" class="field" style="width:270px;" ></td> </tr> </table> <hr /> <table width="400" bborder="0" class="voucherTable"> <tr> <td width="193" class="r" style="vertical-align:middle;"> Voucher Code: <span style="color:#f00;">*</span> </td> <td colspan="2"> <input type="text" placeholder="CODE" id="voucherCode" name="voucherCode" class="field voucherField" style="width:270px;" > </td> </tr> </table> <hr /> <br /><br /> <input type="submit" value="Redeem" id="submit" name="submit" class="submit"> </form> <?php else : ?> <h1 class="title-404"><?php _e('404 — Fancy meeting you here!', 'responsive'); ?></h1> <p><?php _e('Don't panic, we'll get through this together. Let's explore our options here.', 'responsive'); ?></p> <h6><?php _e( 'You can return', 'responsive' ); ?> <a href="<?php echo home_url(); ?>/" title="<?php esc_attr_e( 'Home', 'responsive' ); ?>"><?php _e( '← Home', 'responsive' ); ?></a> <?php _e( 'or search for the page you were looking for', 'responsive' ); ?></h6> <?php get_search_form(); ?> <?php endif; ?> </div><!-- end of #content --> <?php get_sidebar(); ?> <?php get_footer(); ?>
  2. Wow that sounds exactly the right thing to do, but I've gotten lost in the translation a bit. Sorry :-) That did work a bit, I changed it to the right page name which I found in the php file and it is now taking me to the Moodle login page, but when I use the username password to login, I get that ADO Database thing and I'm not sure what to do next.
  3. Well, what I'm trying to do is have a 'voucher redemption page'. Users would get a special code, fill in their details including the 'voucher code', this would query a database and if the code was recognised, it would allow login to Moodle. This is so that I can sell my online courses through Groupon for example. What do you think?
  4. It could be that. It is Moodle, so I wonder if I need to authenticate it. Anyone know anything about authentication in Moodle?
  5. Hello, Thanks for replying. I copied and pasted directly into another browser and the link is fine, it just dosen't work as an action. I thought I might have had a piece of code wrong.
  6. Thanks very much! So I have a contact form, which queries a SQL database and I want the action to go to my Moodle site, but I'm getting an error 404. The code is this: <form action="http://www.institute-of-photography.com/moodle/login/index.php"> id="voucherForm" method="post" class="voucherForm"> What have a I done wrong? Any ideas?
  7. Hello, I have a couple of questions, but I am a real beginner and don't want to make a faux pas by asking silly questions. Is this the right place for me? Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.