Jump to content

edd12345678

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Everything posted by edd12345678

  1. Hi Guys, How can I send a session array through the URL and then use the values on the other page to create an SQL query? Any Ideas? Thanks in advance. Ed
  2. Hi everyone, Hope someone can help. Does anyone know why this is nor displaying any data? $qry = mysql_query("select * from product"); $data = array(); while($row = mysql_fetch_array($qry)){ $productName[] =$row['productName']; // Item name } for($i=0;$i<mysql_num_rows($row);$i++) { $data = $productName[$i]; } return $data; Thanks in advance Edd
  3. Thanks again for replying. I have managed to build an arra. The challenge nowi is to get the information from it in the correct format to send off to google checkouts. Is it possible to do this? I need the data displayed as below. So for each record stored in the array i will need to generate the below: $item_1 = new GoogleItem("product name ", // Item name "With S/N", // Item description $total_count, // Quantity 10.99); // Unit priceow? Thanks again for your help so far.
  4. Thankyou for your reply. Thats what I thought. What im struggling with is defining the array variable so that each row from the sql query is put into a seperate array and a new variable name for each product is created. eg. item1, item2 etc. Any ideas?
  5. Hi, I was wondering if someone can help. I am trying to implement a server to server Google checkout system on my website. I have built my own custom shopping basket which meets my needs however I need to get my data in the correct format to send off for the payment to be taken by Google checkout. At present I have a sql table called basket which stores all of the items that a user adds to thier basket. The google checkout examle requires the data in the below format: $item_1 = new GoogleItem("product name ", // Item name "With S/N", // Item description $total_count, // Quantity 10.99); // Unit price $item_1->SetURLDigitalContent('http://example.com/download.php?id=15', 'S/N: 123.123123-3213', "Download Item1"); $cart->AddItem($item_1); The above code is obviously for just the one item. Is it best to store the basket in a sql database and if so how would I go about retrieving the information from the database and then sending it to google in the above format bearing in mind there can be multiple items in the cart? Thanks in advance Edd
  6. Hi, Thankyou for your reply. I have now resolved the problem. I created a form to post the variables to another page. Then I saved them into a session variable and echoed them back on to the required page if that makes sense. Thanks anyway. Edd
  7. Hi, I wonder if I somebody can help me I have three drop down lists which are populated from data thats stored in my sql database. I also have a table which is echoed from the database all on the same page. What i want to do is allow users to select values in the drop down lists which will then echo different results below in the table. Is this possible. So on page load it will show all of the info in the html table. Then when the user changes the drop downs and clicks submit it will change the query to something SELECT dropdown1 value FROM users where Dropdown2 = 1 AND Dropdown3 = 2 etc. Is this possible to display this information on the same page using the dropdown list or does it need to load a different page as the client side is trying to edit a server side script? If its possible please can someone give me an example. Thanks in advance Edd
  8. Hi, Many thanks for your reply. Is the set timeout() needed for the timer or is it calling the submitFunction function every 5 seconds? At the moment I cannot get it to work. Also at the moment I do not have a form set up as such. I just have: if(isset($_POST["save"])){ Then run query } Thanks Edd
  9. Hello everyone, I wonder if anyone can help me. I have a timer which when the time expires I want any data in my form to be submitted to the database. Is it possible to use post without having a button to trigger it? So: e.g if(($_SESSION['endOfTimer'] - time()) < 0) { Insert values to the database? } How can I do this so it posts the data without the use of a button? Thanks in advance. Ed
  10. Hi, Thankyou for yoru replies. I do have more than one session variable in the quiz to handle other aspects of it but just really need to end the time variable although I guess I could end all of them to kill the timer. I have never used ajax calls before. Are they difficult? Is it possible to provide an example of how to end a session variable using one? Thanks again and apologies for my naivity . Edd
  11. Hi Everyone, I wonder if somebody could help me. I have been at this for hours and am really struggling. I have a timer which I have set up for a quiz. The quiz opens in a javascript shadow box. When the quiz is opened a session variable for the timer is set up to keep track of the time. What I need is for this session variable to end when the shadow box is closed. I have a onClose hook to peform actions when the shadow box is closed which is in javascript. Obviously I cannot end the session variable in the javascript function due to js being client side and php being server side. Has anyone any suggestions how I can resolve this issue. I need to end this session variable as if the user exits the quiz and then selects another quiz to do the timer uses the current time session rather than assigning the new time value for that particular quiz. Thanks in advance. Edd
  12. Thanks thats sorted it after a bit of research.
  13. Hi Guys, Not sure if this an be done but is it possible to check if a shadow box is closed by the user? The reason I ask is that I need to end a session variable depending on weather they have closed the window or not. Thanks in advance. Edd
  14. Thankyou thats just what I needed! Is it easy to set it so it works out the hours as well? Thanks again Ed
  15. Hi, Many thanks for both of your replies. I have implemented both and they do work. However they do not countdown like my timer did before. The time left is only displayed when the page is refreshed. Is there away to use the code you suggested and have it so it counts down the time? Thanks in advance. Edd
  16. Hi, I wonder if someone could possibly help me. I have a countdown timer which will count down from a value in my SQL database. However it count downs in seconds and I need it to show in format hh:mm:ss. I have tried using: <?php echo gmdate("H:i:s", $timeTilEnd);?> Which starts it off but soon as it counts down one second goes back to just showing the seonds. My full code for the timer is: <?php //Start of Timer Function if (!isset($_SESSION['endOfTimer'])){ $endOfTimer = time() + $time * 60; //multiplys the time in db by 60 to create second countdown. $_SESSION['endOfTimer'] = $endOfTimer; } if(($_SESSION['endOfTimer'] - time()) < 0) { $timeTilEnd = 0; } else { $timeTilEnd = $_SESSION['endOfTimer'] - time(); } if($timeTilEnd <= 0) { session_destroy(); } ?> <script type="text/javascript"> var TimeLeft = <?php echo $timeTilEnd; ?>; function countdown() { if(TimeLeft > 0) { TimeLeft -= 1; document.getElementById('timer').innerHTML = TimeLeft; } if(TimeLeft <= 60) { //add text here to change color of message when in the last minute } if(TimeLeft <= 0) { window.location = "Test-Finished.php" } } CountFunc = setInterval(countdown,1000); </script> <?php echo gmdate("H:i:s", $timeTilEnd);?> Has anyone got any ideas on how I can do this, Its driving me mad. Thanks in advance. Edd
  17. Hi Guys, I am having a small problem with an array. I want to push information from a form into an array. However each time I do it it just replaces the last entry in the array with the information in stead of adding a new value to the array. <?php // if generate is pressed if(isset($_POST['generate'])){ // get values from form $name = htmlspecialchars($_REQUEST['add']); array_push($stack, $name); print_r($stack); } ?> Can anybody help? Thanks Ed
  18. Hi, I wonder if some one could help me. I am trying to set up a few rules to make sure that users create safe passwords on my site: I have the below check which makes sure that the user enters a word of at least 8 charachters long: if( strlen($password) < $MaxPwdLength ){ $errmsg_arr[] = 'Password must be at least 8 charachters long '; $errflag = true; } Does anyone know how I could write an if function to make sure that the ser is entereing a password with at least one capital and one lower case letter in. Hope you can help. Thanks Ed
  19. Apologies, I have now resolved this issue. myself. Thanks anyone who was looking into it.
  20. Hi Guys, I wonder If I can call on this forums help once again. I am trying to add salt to my md5 password hash. However I think I am getting the syntax slightly wrong as it is not working properly. It works in the fact that when someone logs in and they have a 1 next to the member type it will direct them to the teachers page . However if no values are entered into the log in form and someone clicks log in it will still direct them to the students page when I thought it would direct them to log in failed. The code for the log in form is: //Sanitize the POST values $login = clean($_POST['login']); $password = clean($_POST['password']); $salt = "salt"; $EncryptedPassword=md5($password, $salt); //Create query $qry="SELECT * FROM users WHERE username='$login' AND password='$EncryptedPassword'"; $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['id']; $_SESSION['SESS_FIRST_NAME'] = $member['FirstName']; $_SESSION['SESS_LAST_NAME'] = $member['LastName']; $_SESSION['SESS_LAST_NAME'] = $member['Member_Type']; session_write_close(); } //if the member has an id equal to 0 send them to the member page if($member['Member_Type'] == 0){ header("Location: Student-Page.php"); //if the member has an id equal to 1 send them to the admin page } elseif($member['Member_Type'] == 1){ header("Location: Teachers-Page.php"); } // regardless of the outcome, we need to exit, so it can be done once after both checks exit(); } else { //Login failed header("location: login-failed.php"); exit(); } In case you need it the code for the registration form where the password is originally salted upon creation is: <?php //Start session session_start(); //Include database connection details require_once('config.php'); //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 $username = clean($_POST['username']); $FirstName = clean($_POST['FirstName']); $LastName = clean($_POST['LastName']); $Member_Type = clean($_POST['Member_Type']); $password = clean($_POST['password']); $Cpassword = clean($_POST['Cpassword']); $salt = "salt"; $EncryptedPassword = md5($password,$salt); //Check for duplicate login ID if($username != '') { $qry = "SELECT * FROM users WHERE username='$username'"; $result = mysql_query($qry); if($result) { if(mysql_num_rows($result) > 0) { } @mysql_free_result($result); } else { //die("query failed"); } } //Create INSERT query $qry = "INSERT INTO users(username, password, FirstName, LastName, Member_Type) VALUES('$username','$EncryptedPassword','$FirstName','$LastName','$Member_Type')"; $result = @mysql_query($qry); //Check whether the query was successful or not if($result) { header("location: register-success.php"); exit(); }else { die("Query Failed"); } ?> If someone could take a look and point me in the right direction. Also if there are any other mistakes let me know I would be very grateful. Thanks in advance. Edd
  21. Hi Guys, Thankyou both for your replies. With your help I have now got it sorted. onThanks for the heads up on adding the code to the pages I want to keep secure. Ive already got this part covered Also thanks xyph for the link on PHP passwords and log ins that will be a great help in the future. Cheers Edd
  22. Hi, I was hoping somebody could help me. I am a beginner to PHP/SQL and despite my efforts am struggling a bit. I have created a log in for my website which will divert to a webpage if the user enters their correct details. I would like to add a check which would check in the SQL databse what member ship type the user has. If they have admin membership then direct them to admin.php and if they have regular membership then direct them to regular.php. I have researched how I can do this and understand that I need to use a switch case statement? At the moment the check which is made when the user logs in is: //Create query $qry="SELECT * FROM users WHERE username='$login' AND password='$EncryptedPassword'"; $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['id']; $_SESSION['SESS_FIRST_NAME'] = $member['FirstName']; $_SESSION['SESS_LAST_NAME'] = $member['LastName']; session_write_close(); header("location: regular.html"); exit(); } else { //Login failed header("location: login-failed.php"); exit(); } } else { die("Query failed"); } As you can see at the moment the code will just direct to the regular.php page. I have tried to implement the switch case but have got in a bit of a muddle so reverted back to the code above. Please could someone shed any light into how I could add the switch case statement to my code. Thanks in advance for any help. Edd
×
×
  • 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.