Jump to content

headrush

New Members
  • Posts

    8
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

headrush's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. what I mean in above is its now showing the errors its showing the result as either the below and not showing the test errors I created. ​The only time it shows the error message is when I don't enter in one or both boxes and submits and echos out the error "You need to enter a username and password" So I know its doing the checks if user and password correct its displaying below int 1 2. 3.int 1 4. 5.Array ( ) if user and password incorrect int 1 2. 3.int 1 4.int 0 5.Array ( ) if not registered int 02. 3.int 0 4.int 0 5.Array ( )
  2. Hi Thank you so much for your response. ​What I have done is created a login form. and on click submit it checks this <?php if (empty($_POST) === false) { $username = $_POST['username']; $password = $_POST['password']; // If submited without entering in 1 box or both if(empty($username) === true || empty($password) === true) { $errors[] = 'You need to enter a username and password'; // If submited but username not in database } else if (user_exists($username) === false) { $errors[] = 'No username found. have you registered?'; } else if (user_active ($username) === false) { $errors[] = 'You need to activate your account to allow log in!'; } else { //somthing } print_r($errors); } ?> And using what you have provided it uses the functions. However When I login if I enter nothing in the username and password it does say 'please enter username and password'. However if I enter the correct username and password. it shows this? int 1 int 1 Array ( ) login.php <?php function user_exists($username) { $db = new mysqli('localhost','','','testing'); $user_exists_stmt = $db->prepare ('SELECT EXISTS (SELECT 1 FROM users WHERE username = ?)'); // Bind values to the parameters $user_exists_stmt->bind_param('s', $username); // Execute statement $user_exists_stmt->execute(); // Bind results to variables and fetch them $user_exists_stmt->bind_result($user_exists); $user_exists_stmt->fetch(); // Inspect result var_dump($user_exists); } function user_active($username) { $db = new mysqli('localhost','','','testing'); $user_active_stmt = $db->prepare ('SELECT EXISTS (SELECT 1 FROM users WHERE username = ? AND active =1)'); // Bind values to the parameters $user_active_stmt->bind_param('s', $username); // Execute statement $user_active_stmt->execute(); // Bind results to variables and fetch them $user_active_stmt->bind_result($user_exists); $user_active_stmt->fetch(); // Inspect result var_dump($user_exists); } ?>
  3. Hi I am trying to create 2 functions. ​one to check that user exists and the other to check that user is active. However I keep getting the error unexpected ',' on line 4 When I remove the ',' I still get errors. ​Does anyone have any idea where I'm going wrong and how to resolve? ​Thanks <?php function user_exists($username) { $username = sanitize($username); $result = $mysqli->query($db,"SELECT COUNT(`user_id`) FROM `users` WHERE `username` ='$username'"), 0) == 1) ? true : false; } function user_active($username) { $username = sanitize($username); $result = $mysqli->query($db,"SELECT COUNT(`user_id`) FROM `users` WHERE `username` ='$username' AND `active` = 1 "), 0) == 1) ? true : false; } ?>
  4. Hi Barand Thank you for your help In this matter It now works! ​I will have a look at the $age query and result Thanks again and have a great day!
  5. Thanks for your reply I understand I can not mix them, I'm just trying to figure out what I should write using Mysqli for the below code, ​ $age = mysql_result($age, 0); Any ideas? Thanks again
  6. Hi, ​On the below script I get this error Warning mysql_result() expects parameter 1 to be resource, object given in data.php on line 33 On another page there is a text box and button,when button is pressed the below file checks if there's a value in the text box, if it's in the database and if it is in the database it displays the results. The below case results being the name and age. In the below I tried to change the MSQL to MSQLI as much as I could except I'm stuck with line 33 which contains $age = mysql_result($age, 0); Any help with this would be much appreciated. Thanks This is the Data.php that the error is contained <?php $db = new mysqli('localhost','user','pass,'testing'); if($db->connect_errno) { //echo $db->connect_error; die('<br>Oops! we are having some problems, this is currently being fixed.'); } $name = mysqli_real_escape_string($db,$_POST['name']); if($name==NULL) echo "Please enter a name!"; else { $age = mysqli_query($db,"SELECT age FROM rates.People2 WHERE name='$name'"); $age_num_rows = mysqli_num_rows($age); if($age_num_rows==0) echo "Name does not exists!"; else { $age = mysql_result($age, 0); echo "$name's age is $age"; } } ?>
  7. I am trying to install the rich text editor in my userarea so I can edit pages on my website. I have already got the functionality working which is in a file called EditPages.rqd but, only using a text box, I tryed putting the rich text editor in the place of the text box, but when display in my browser and I select a file to edit using my drop down menu, it does not show the rich text editor only the Save File button. where as if I just have a text box there it works great. Heres is what on my pages2.html (With the Rich text editor)page: <?php require_once ("EditPage.rqd"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Page Editor</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="css/style.css" rel="stylesheet" type="text/css" /> <link href="styles/styles.css" rel="stylesheet" type="text/css" /> <script language="JavaScript" type="text/javascript" src="richtext_compressed.js"></script> </head> <body> <?php include ('structure/head.inc');?> <div class="clear"> </div> <div id="sidebar"> <?php include ('structure/menu.inc');?> </div> <div id="content"> <h3>Edit Pages</h3> <br /> <form name="myform" action="pages2.html" method="post" onsubmit="return submitForm();"> <script language="JavaScript" type="text/javascript"> <!-- function submitForm() { //make sure hidden and iframe values are in sync before submitting form updateRTE('$filename'); //use this when syncing only 1 rich text editor ("rtel" is name of editor) //updateRTEs(); //uncomment and call this line instead if there are multiple rich text editors inside the form alert("Submitted value: "+document.myform.$file.$filename.) //alert submitted value return true; //Set to false to disable form submission, for easy debugging. } //Usage: initRTE(imagesPath, includesPath, cssFile) initRTE("images/", "", ""); //--> </script> <label for="file">Choose which page content to edit:</label> <select name="file" id="file"> <optgroup label="Pages to Edit"> <option value="home"<?php select('home'); ?>>Home</option> <option value="general"<?php select('general'); ?>>General - Club Info</option> <option value="kit"<?php select('kit'); ?>>Kit</option> <option value="training"<?php select('training'); ?>>Training</option> <option value="coaching"<?php select('coaching'); ?>>Coaching</option> <option value="fees"<?php select('fees'); ?>>Fees</option> <option value="pitches"<?php select('pitches'); ?>>Pitches</option> <option value="social"<?php select('social'); ?>>Social</option> <option value="latest"<?php select('latest'); ?>>Latest News</option> </optgroup> </select> <input type="submit" name="load" value="Load File" /> <hr /> <?echo $Message?> <?php if(isset($file) && !empty($file)) { echo '<script language="JavaScript" type="text/javascript"> writeRichText("'.$filename.'", "'.$file.'", 400, 200, true, false); </script><br> <input type="submit" name="save" value="Save File" />'; } else { echo '<strong>Please choose a file to edit from the dropdown list above.</strong>'; } ?> </form> </div> <div class="clear"> </div> </div> </body> </html> Here is whats on my EditPages.rqd <?php function stripstring($string) { if(get_magic_quotes_gpc()) { return stripslashes($string); } else { return $string; } } $files = array( /** Drop-Down Value => File Path **/ 'home' => './text/home.txt', 'general' => './text/general.txt', 'joining' => './text/joining.txt', 'kit' => './text/kit.txt', 'news' => './text/news.txt', 'fees' => './text/fees.txt', 'pitches' => './text/pitches.txt', 'training' => './text/training.txt', 'coaching' => './text/coaching.txt', 'social' => './text/social.txt', 'latest' => './text/latest.txt' ); if($_SERVER['REQUEST_METHOD'] == "POST") { if(isset($_POST['load'])) { if(!empty($_POST['file']) && array_key_exists($_POST['file'],$files)) { $file = file_get_contents($files[$_POST['file']]); $filename = $_POST['file']; } } elseif(isset($_POST['save'])) { if(!empty($_POST['filecontents']) && array_key_exists($_POST['filename'],$files)) { $filecontents = stripstring($_POST['filecontents']); if(phpversion() > '5.0.0') { if(!file_put_contents($files[$_POST['filename']],$filecontents)) { $Message = "<a href=\"#\">Error writing to file</a><br>"; } else { $Message = "<a href=\"#\">Saved to file successfully</a><br>"; } } else { $fhandle = fopen($files[$_POST['filename']],'w'); if(fwrite($fhandle,$filecontents) == false) { $Message = "<a href=\"#\">Oops! There was an Error writing to file: contact chantal@pglc.co.uk</a><br>"; } else { fclose($fhandle); $Message = "<a href=\"#\">File Update successfully</a><br>"; } } } } } function select($file) { global $filename; if($filename == $file) { echo ' selected="selected"'; } } ?> Here is the WORKING script with the use of just the text box on pages2.html: <?php require_once ("EditPage.rqd"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Page Editor</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="css/style.css" rel="stylesheet" type="text/css" /> <link href="styles/styles.css" rel="stylesheet" type="text/css" /> </head> <body> <?php include ('structure/head.inc');?> <div class="clear"> </div> <div id="sidebar"> <?php include ('structure/menu.inc');?> </div> <div id="content"> <h3>Edit Pages</h3> <br /> <form action="pages2.html" method="post"> <label for="file">Choose which page content to edit:</label> <select name="file" id="file"> <optgroup label="Pages to Edit"> <option value="home"<?php select('home'); ?>>Home</option> <option value="general"<?php select('general'); ?>>General - Club Info</option> <option value="kit"<?php select('kit'); ?>>Kit</option> <option value="training"<?php select('training'); ?>>Training</option> <option value="coaching"<?php select('coaching'); ?>>Coaching</option> <option value="fees"<?php select('fees'); ?>>Fees</option> <option value="pitches"<?php select('pitches'); ?>>Pitches</option> <option value="social"<?php select('social'); ?>>Social</option> <option value="latest"<?php select('latest'); ?>>Latest News</option> </optgroup> </select> <input type="submit" name="load" value="Load File" /> <hr /> <?echo $Message?> <?php if(isset($file) && !empty($file)) { echo '<textarea name="filecontents" id="filecontents" cols="60" rows="20">'.$file.'</textarea> <input type="hidden" name="filename" value="'.$filename.'" /><br /><input type="submit" name="save" value="Save File" />'; } else { echo '<strong>Please choose a file to edit from the dropdown list above.</strong>'; } ?> </form> </div> <div class="clear"> </div> </div> </body> </html>
×
×
  • 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.