Jump to content

jacko_162

Members
  • Posts

    405
  • Joined

  • Last visited

Everything posted by jacko_162

  1. ok so if i wanted to write the query to be more than and less than how would i do this from the variables with my above coding? and also the page is viewed without the variables, if this is the case i have the start date 6 months less than the current date. can this be done?
  2. thats a version i have triend with no results being received, but also no errors; here is my code snippet. (yes im connected to DB in header file also; <table width="100%" border="0" cellspacing="0" cellpadding="4"> <tr> <td colspan="2" valign="top"> <?php $todaydate = date("F j, Y"); $oldDate = date("F j, Y", strtotime("6 months ago")); ?> <form method="GET"> Start: <input name="graph_start" type="text" class="date" id="datepicker" value="<?php echo $oldDate; ?>" size="16"/> End: <input name="graph_end" type="text" class="date" id="datepicker2" value="<?php echo $todaydate; ?>" size="16"/> <input type="submit" value="Submit" /> <br /> <br /> Viewing Results Between: <strong><span class="time"><?php $start = $_GET['graph_start']; if ($start) { echo "$start"; } else { echo "$oldDate"; } ?></span></strong> - <strong><span class="time"> <?php $end = $_GET['graph_end']; if ($end) { echo "$end"; } else { echo "$todaydate"; } ?></span></strong> <br /> </form> </td> </tr> <tr> <td colspan="2" valign="top"><?php function imp($char,$tag){ foreach($char as $key=>$value){ $char[$key] = $value; } $char = implode($tag,$char); return $char; } $sql = "SELECT * FROM tests WHERE date BETWEEN '$start' AND '$end' ORDER BY ID ASC LIMIT 0,10"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)){ $date[] = $row[date]; $day[] = $row[day]; $test1[] = $row[test1]; $test2[] = $row[test2]; $test3[] = $row[test3]; $test4[] = $row[test4]; $test5[] = $row[test5]; $test6[] = $row[test6]; $test7[] = $row[test7]; $test8[] = $row[test8]; $test9[] = $row[test9]; $test10[] = $row[test10]; $test11[] = $row[test11]; $test12[] = $row[test12]; $test13[] = $row[test13]; $test14[] = $row[test14]; } ?>
  3. I thought i would start a new thread to make it easier for people to understand what im rying to achieve. i am querying my database to pull down data between 2x dates set in the URL. i will have the following url: test.php?graph_start=November+3%2C+2009&graph_end=May+9%2C+2010 which is the following dates; Start November 3, 2009 End May 9, 2010 my format in the database is stored as May 9, 2010 $todaydate = date("F j, Y"); what im trying to do is query database between the 2x variables passed in the URL. can anyone help me?
  4. i fixed my echoing variable command; <?php $end = $_GET['graph_end']; if ($end) { echo "$end"; } else { echo "$todaydate"; } ?> all i need now is help creating a SQL command to pull data between the 2x date variables.
  5. thank you for reply, i have the form made and upon selecting the date range and clicking submit it enters the URL as follows: test.php?graph_start=November+9%2C+2009&graph_end=May+9%2C+2010 i can then echo the variables just fine. i enter the date format into the database across the site as: $todaydate = date("F j, Y"); which outputs May 9, 2010 when echo'd. problem i need help with is the mysql query. i need to select * from table "BETWEEN HE ABOVE VARIABLES IN URL" i also need a helping hand with echoing the variable; <?php echo $graph_start; ?> - WORKS FINE but if i echo $graph_start and it returns nothing, i.e nothing in URL can i echo "NO DATE"
  6. As above, i have a page that pulls down information from the database and graphs said information using the google graph code. next i want to make a page with 2x date selectors, and the page shows information from database within that range. problem is i dont know a great deal about PHP so im after some sample coding snippets i can use, or if somone can help me out with where to look. not sure if i should use the from and to date in the URL and when running the sql query to fetch the data from the URL to perform the sql commands.
  7. can anyone help me gather data from a sql command and allow it into the above array please? according to the code posted by google; // Create some random text-encoded data for a line chart. header('content-type', 'image/png'); $url = 'http://chart.apis.google.com/chart'; $chd = 't:'; for ($i = 0; $i < 150; ++$i) { $data = rand(0, 100000); $chd .= $data . ','; } $chd = substr($chd, 0, -1); the above generates random numbers, and outputs $chd as: "t:40,20,50,20,100" so if i can pull my tests results from database in same way i would be 1 step closer.
  8. thanks for the links, i have been reading through them and found the following code: <?php // Create some random text-encoded data for a line chart. header('content-type', 'image/png'); $url = 'http://chart.apis.google.com/chart'; $chd = 't:'; for ($i = 0; $i < 150; ++$i) { $data = rand(0, 100000); $chd .= $data . ','; } $chd = substr($chd, 0, -1); // Add data, chart type, chart size, and scale to params. $chart = array( 'cht' => 'lc', 'chs' => '600x200', 'chds' => '0,100000', 'chd' => $chd); // Send the request, and print out the returned bytes. $context = stream_context_create( array('http' => array( 'method' => 'POST', 'content' => http_build_query($chart)))); fpassthru(fopen($url, 'r', false, $context)); ?> how can i query the database and turn the information into an array, i want to show test results from my "tests" table, each result has a date and a value. each graph only need to chart 1 piece of information and show the last 8 test results.
  9. can anyone help me out, point me in right direction. just want an image based nice looking chart
  10. anyone used this before? im looking into charting a set of data in a table for each given user and displaying a graph such as; i want to call the data from the database using php and mysql, but i can manually add the title, and axis names. can anyone help me code something please??
  11. i have the following if statement which works perfect; <?php $val1 = '379'; //----- CHANGE LOW VALUE $val2 = '391'; //----- CHANGE HIGH VALUE $val3 = '$test10'; //----- CHANGE TEST NUMBER $label = 'Potassium: '; //----- CHANGE TEST LABEL if (in_array('test10',$arr)){ //----- CHANGE TEST NUMBER echo '<tr>'; echo "<td width='40%' align='right'><em><strong>$label</strong></em></td>"; echo "<td width='15%'>$test10 ppm</td>"; //----- CHANGE TEST NUMBER if (($test10 > $val1) && ($test10 < $val2)) { echo '<td width="15%"><img src="img/icons/beaker_green.png" /></td>';} else { echo '<td width="6%"><img src="img/icons/beaker_red.png" /></td>';} echo '</tr>'; }else{ echo '';} ?> what i wanted to do next was not only check if 'test10' was in the array but also that $active10 had a '1' value in the database. so i tried the following; if (in_array('test10',$arr) && ($active10 = '1')){ but even if the $active10 variable had a '0' in database it still shows? i have assigend $active10 variable in the top of the php page like follows; <?php if ($ID) { $sql = "SELECT * FROM $table2 WHERE ID=$ID AND member_id=$_SESSION[sESS_MEMBER_ID]"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); $ID = $myrow["id"]; $member_id = $myrow["member_id"]; $test10 = $myrow["test10"]; $active10 = $myrow["active10"]; { $result2=mysql_query("SELECT * FROM $table3 WHERE member_id=$_SESSION[sESS_MEMBER_ID]"); $row2 = mysql_fetch_array($result2); $arr = array(); $arr = explode(';',$row2['settings']); ?> can anyone help me word it rightly please?
  12. thank you ken2k7 it worked a treat now. now to figure out how to validate an email address
  13. now it doesnt throw up error at all?? if(preg_match("/^[a-zA-Z_0-9-.]$/", $login)) { //Check for strange characters in username & names $errmsg_arr[] = 'Username has illegal chacters you can only use; Aa-Zz, 1-9 and _'; $errflag = true; } and it lets me put other characters in the signup form such as where=?ID=0'
  14. still having problems, no matter what i type in username it still produces the error; //Check for strange characters in username & names if (!preg_match('/[^a-zA-Z0-9\_\-\]+$/', $login)); { $errmsg_arr[] = 'Username has illegal chacters you can only use; Aa-Zz, 1-9 and _'; $errflag = true; } i want to allow a-z, A-Z, 0-9, -, and _ am i doing something wrong?
  15. aah yes both typos, got it working now. thanks guys
  16. sounds interesting, i tried to use your example and modified it for $login, if(preg_match("/\A[a-zA-Z_0-9]{1,12}^/",$login)) { $errmsg_arr[] = 'Username cannot contain illegal characters please us a-Z, 1-9 and underscores ONLY!, '; $errflag = true; } this wont work and i am able to add other characters in the $login box, can u see why its doing it?
  17. Hey all, i want to be more secure on my web application, i have a register form with the following fields; firstname lastname username email password confirmpassword and here is my register-exec.php script; <?php //Start session session_start(); //Include database connection details require_once('Includes/config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $fname = clean($_POST['fname']); $lname = clean($_POST['lname']); $login = clean($_POST['login']); $email = clean($_POST['email']); $password = clean($_POST['password']); $cpassword = clean($_POST['cpassword']); //Input Validations if($fname == '') { $errmsg_arr[] = 'First name missing, '; $errflag = true; } if($lname == '') { $errmsg_arr[] = 'Last name missing, '; $errflag = true; } if($login == '') { $errmsg_arr[] = 'Login ID missing, '; $errflag = true; } if($email == '') { $errmsg_arr[] = 'Email Address is missing, '; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing, '; $errflag = true; } if($cpassword == '') { $errmsg_arr[] = 'Confirmation password missing, '; $errflag = true; } if( strcmp($password, $cpassword) != 0 ) { $errmsg_arr[] = 'Passwords do not match!!'; $errflag = true; } //Check for duplicate login ID if($login != '') { $qry = "SELECT * FROM members WHERE login='$login'"; $result = mysql_query($qry); if($result) { if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Login ID is already in use!<br />'; $errflag = true; } @mysql_free_result($result); } else { die("Query failed"); } } //Check for duplicate email if($email != '') { $qry = "SELECT * FROM members WHERE email='$email'"; $result = mysql_query($qry); if($result) { if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'E-Mail address is already in use!'; $errflag = true; } @mysql_free_result($result); } else { die("Query failed"); } } //If there are input validations, redirect back to the registration form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: signup.php"); exit(); } //Create INSERT query $qry = "INSERT INTO members(firstname, lastname, login, email, passwd, settings, avatar, membership, roles) VALUES('$fname','$lname','$login','$email','".md5($_POST['password'])."','test1;test9;test2;test10;test3;test11;test4;test12;test5;test13;test6;test14;test7;test8','avatar011','Free','Member')"; $result = @mysql_query($qry); //Check whether the query was successful or not if($result) { header("location: register-success.php"); exit(); }else { die("Query failed"); } ?> here is my form page; <? require_once('header.php');?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-style-type" content="text/css" /> <meta http-equiv="content-script-type" content="text/javascript" /> <title>Registration</title> <style> .style2 {color: #EC1A3F} .style5 {color: #999999; font-style: italic; } </style> </head> <body> <?php if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) { echo '<div class="notification error png_bg"><a href="#" class="close"><img src="img/cross_grey_small.png" title="Close this notification" alt="close" /></a><div>'; foreach($_SESSION['ERRMSG_ARR'] as $msg) { echo $msg; } echo '</div></div>'; unset($_SESSION['ERRMSG_ARR']); } ?> <div> <div> <div> <div> <div class="block"> <form name="loginForm" method="post" action="register-exec.php"> <table border="0" align="center" cellpadding="4" cellspacing="0"> <tr> <td> <label><img src="img/icons/name.png" alt="" width="16" height="16" /> First Name:</label> <br /> <input class="text" name="fname" type="text" /> <span class="style2">*<br /> </span></td> </tr> <tr> <td> <label><img src="img/icons/name2.png" alt="" width="16" height="16" /> Last Name:</label> <br /> <input class="text" name="lname" type="text" /> <span class="style2">*</span></td> </tr> <tr> <td> <label><img src="img/icons/username.png" alt="" width="16" height="16" /> Username:</label> <br /> <input class="text" name="login" type="text" /> <span class="style2">*<span class="style5"> Used to login to the site</span><br /> </span></td> </tr> <tr> <td> <label><img src="img/icons/email.png" alt="" width="16" height="16" /> E-Mail Address:</label> <br /> <input class="text" name="email" type="text" /> <span class="style2">* </span><span class="style5">Address is needed to confirm forgotten passwords!</span></td> </tr> <tr> <td> <label><img src="img/icons/key.png" alt="" width="16" height="16" /> Password:</label> <br /> <input class="text" name="password" type="password" /> <span class="style2">* </span><span class="style5">Must be more than 6 characters long.</span> </td> </tr> <tr> <td> <label><img src="img/icons/key.png" alt="" width="16" height="16" /> Confirm Password:</label> <br /> <input class="text" name="cpassword" type="password" /> <span class="style2">*</span></td> </tr> <tr> <td align="left"><br /> <input class="Button" type="submit" name="submit" value="Register Me!" /></td> </tr> </table> </form> </div></div></div></div></div> </body> it has some validation but not a great deal, how can i change this to stop users entering information such as: "'where%201=1" etc.... any help and code would be much appreciated;
  18. ok i managed to get the following to work if i edit manually; <?php session_start(); $_SESSION['divclosed']=1; ?> then i echo: <?php if($_SESSION['divclosed']) { echo "<table width='100%' border='0' cellspacing='0' cellpadding='4' id='header_notification' style='opacity: 0.9;'><tr><td><div align='center'><img src='img/exclamation_octagon_fram.png'>"; echo "Please Note, this site is still in BETA version and changes can occur, please bear with us while we rectify any problems."; echo "</div></td></tr></table><br>"; } ?> this then allows me to show/hide the message if i change "1" to "0" how can i edit the above coding to allow members to see the message, then click an image to close it.?
  19. oops what i ment to say is that this message is not just for logged in users, i need anyone who visits site to see the message and being able to click close and not show it again. can i initiate a temporary session to show the message?
  20. sounds interesting, how can i initiate the session, i already have sessions on the login script can i edit the php on that to create a new one? here is my login exec php file: <?php //Start session session_start(); //Include database connection details require_once('Includes/config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['login']); $password = clean($_POST['password']); //Input Validations if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-failed.php"); exit(); } //Create query $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); header("location: login-success.php"); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?>
  21. i want to display a <div> with a class upon a user entering my site on the header.php file, but i want it to only show the notice once and user can close it, i already have a jquery notification which allows me to have a nicely styled <div> which the user can close, but it shows every time the header.php file is loaded, can i change the way the div is shown using php and perhaps the database to show only untill the user closes it and it wont load again untill i reset it?
×
×
  • 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.