fefster Posted October 23, 2012 Share Posted October 23, 2012 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/269824-wordpress-and-moodle-integration/ Share on other sites More sharing options...
Christian F. Posted October 23, 2012 Share Posted October 23, 2012 Please use the [code][/code] tags around your code, as it helps make both your post and your code a lot easier to read. Quote Link to comment https://forums.phpfreaks.com/topic/269824-wordpress-and-moodle-integration/#findComment-1387263 Share on other sites More sharing options...
fefster Posted October 23, 2012 Author Share Posted October 23, 2012 OK will do Quote Link to comment https://forums.phpfreaks.com/topic/269824-wordpress-and-moodle-integration/#findComment-1387269 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.