Jump to content

colleyboy

Members
  • Posts

    142
  • Joined

  • Last visited

    Never

Everything posted by colleyboy

  1. Ah-ha ... many thanks. It worked with '$letter%' Think this is calling the first letter now - I hope :S
  2. Basically I am trying to call back results which start with the letter. I tried removing the ; but has not worked . If I replace with 'A%' or 'B%' it works fine but cant seem to get it to work with a variable.
  3. I am trying to call results from a database where a letter is equal to a letter. I have already called the variable $letter; to look at the url and use this result at the variables contents. I.E: $letter = A I am trying to call via MYSQL any rows matching a certain letter. This letter is defined by $letter. I cant seem to put this in correctly? can anyone help? $query="SELECT * FROM products WHERE product_name LIKE '$letter;%' ORDER by variety ASC";
  4. That would be nice but if it is not real-time then just a way to display the output so all the columns of code are not together when it shows what it has put in the db.
  5. Many Thanks. I have another question though? How would I display the results better on the page. At the moment it processes and displays it like: File dutchhouseproducts.csv uploaded successfully. Displaying contents: product_name,variety,description,price Red Flower,Roses,This is a description for the red flower,3.99 Yellow Flower,Roses,This is a lovely yellow flower,14.99 Import done I would like it to display a row at a time... Example: File dutchhouseproducts.csv uploaded successfully. Displaying contents: Row 1: Red Flower,Roses,This is a description for the red flower,3.99 Row2: Yellow Flower,Roses,This is a lovely yellow flower,14.99 Import Complete.
  6. I thought logically to what you said and added it and it worked //Upload File if (isset($_POST['submit'])) { if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>"; echo "<h2>Displaying contents:</h2>"; readfile($_FILES['filename']['tmp_name']); } //Import uploaded file to Database $handle = fopen($_FILES['filename']['tmp_name'], "r"); $data = fgetcsv($handle, 1000, ","); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import="INSERT into products(product_name,variety,description,price) values('$data[0]','$data[1]','$data[2]','$data[3]')"; mysql_query($import) or die(mysql_error()); } fclose($handle); print "Import done"; "Eureka!" - Thanks
  7. This is what I understand from the code: //Import uploaded file to Database $handle (variable for handling request to open CSV) = fopen($_FILES['filename']['tmp_name'] (opens the file from the temp directory), "r (retreives)"); (This is the loop part I think where it looks up the csv contents and fetches the data for the first 1000 rows of data) while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { (this bit imports the data into the database as per the column names in the database and the column count in the csv file) $import="INSERT into products(product_name,variety,description,price) values('$data[0]','$data[1]','$data[2]','$data[3]')"; (if there is an error importing stop) mysql_query($import) or die(mysql_error()); } (closes the csv opening session) fclose($handle); (echo's it has done) print "Import done"; This is what I understand from the code. Please let me know if I am thinking along the right lines?
  8. Sorry I am a bit new to loops. I got this code elsewhere and have done little things to it but am stuck on this bit. Please can you help me out. Much appreciated
  9. Do you mean like this? :S $handle = fopen($_FILES['filename']['tmp_name'], "r"); while (($data = fgetcsv($handle, 1000, ","($data = fgetcsv($handle, 1000, ","))) !== FALSE) { $import="INSERT into products(product_name,variety,description,price) values('$data[0]','$data[1]','$data[2]','$data[3]')"; mysql_query($import) or die(mysql_error()); } fclose($handle);
  10. Hi have found a great script to upload CSV files into a mysql database. Problem is that it uploads the first line of the file. I need it to skip this line as it only has headers for the columns. Is there any way to "skip this?" Upload.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Upload page</title> <style type="text/css"> body { background: #E3F4FC; font: normal 14px/30px Helvetica, Arial, sans-serif; color: #2b2b2b; } a { color:#898989; font-size:14px; font-weight:bold; text-decoration:none; } a:hover { color:#CC0033; } h1 { font: bold 14px Helvetica, Arial, sans-serif; color: #CC0033; } h2 { font: bold 14px Helvetica, Arial, sans-serif; color: #898989; } #container { background: #CCC; margin: 100px auto; width: 945px; } #form {padding: 20px 150px;} #form input {margin-bottom: 20px;} </style> </head> <body> <div id="container"> <div id="form"> <?php include "connection.php"; //Connect to Database $deleterecords = "TRUNCATE TABLE tablename"; //empty the table of its current records mysql_query($deleterecords); //Upload File if (isset($_POST['submit'])) { if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>"; echo "<h2>Displaying contents:</h2>"; readfile($_FILES['filename']['tmp_name']); } //Import uploaded file to Database $handle = fopen($_FILES['filename']['tmp_name'], "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import="INSERT into products(product_name,variety,description,price) values('$data[0]','$data[1]','$data[2]','$data[3]')"; mysql_query($import) or die(mysql_error()); } fclose($handle); print "Import done"; //view upload form }else { print "Upload new csv by browsing to file and clicking on Upload<br />\n"; print "<form enctype='multipart/form-data' action='upload.php' method='post'>"; print "File name to import:<br />\n"; print "<input size='50' type='file' name='filename'><br />\n"; print "<input type='submit' name='submit' value='Upload'></form>"; } ?> </div> </div> </body> </html>
  11. Hi, I am modifying a script which is a HTML5/Jquery drop down menu. I have done it all but cannot seem to center the menu images. Any idea what I need to edit? Nav.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>HTML5, CSS3 and jQuery Navigation menu</title> <link rel="stylesheet" href="css/nav.css"> <!--[if IE]> <script src="scripts/html5.js"></script> <![endif]--> </head> <body class="no-js" topmargin="0" rightmargin="0" leftmargin="0"> <nav id="topNav"> <ul> <li><a href="#" title="Nav Link 1"><IMG SRC="images/homepagebutton.png"></a></li> <li> <a href="#" title="Nav Link 1"><IMG SRC="images/companybutton.png"></a> <ul> <li><a href="#" title="Sub Nav Link 1">Sub Nav Link 1</a></li> <li><a href="#" title="Sub Nav Link 2">Sub Nav Link 2</a></li> <li><a href="#" title="Sub Nav Link 3">Sub Nav Link 3</a></li> <li><a href="#" title="Sub Nav Link 4">Sub Nav Link 4</a></li> <li class="last"><a href="#" title="Sub Nav Link 5">Sub Nav Link 5</a></li> </ul> </li> <li><a href="#" title="Nav Link 1"><IMG SRC="images/productandservicesbutton.png"></a></li> <li><a href="#" title="Nav Link 1"><IMG SRC="images/qualitybutton.png"></a></li> <li><a href="#" title="Nav Link 1"><IMG SRC="images/worldwidelocationsbutton.png"></a> <ul> <li><a href="#" title="Sub Nav Link 1">England</a></li> <li><a href="#" title="Sub Nav Link 2">France</a></li> <li><a href="#" title="Sub Nav Link 3">Sweden</a></li> <li><a href="#" title="Sub Nav Link 4">Poland</a></li> <li class="last"><a href="#" title="Sub Nav Link 5">Sub Nav Link 5</a></li> </ul> </li> <li><a href="#" title="Nav Link 1"><IMG SRC="images/enquiriesbutton.png"></a></li> </ul> </nav> <script src="js/jquery.js"></script> <script src="js/modernizr.js"></script> </body> </html> nav.css: /* JS disabled styles */ .no-js nav li:hover ul { display:block;} /* base nav styles */ nav { display:block; margin:0 auto 0px; position:relative; background-image:url('../images/menubg.png'); font:16px Tahoma, Sans-serif; } nav ul { padding:0; margin:0; } nav li { position:relative; float:left; list-style-type:none;} nav ul:after { content:"."; display:block; height:0; clear:both; visibility:hidden; } nav li a { display:block; padding:0px 0px; border-right:1px dashed #222; color:#eee; text-decoration:none; height:35px; } nav li a:focus { outline:none; text-decoration:underline; } nav li:first-child a { border-left:none; } nav li.last a { border-right:none; } nav a span { display:block; float:right; margin-left:5px; } nav ul ul { display:none; width:100%; position:absolute; left:0; background:#6a6a6a; } nav ul ul li { float:none; } nav ul ul a { padding:5px 10px; border-left:none; border-right:none; font-size:14px; } nav ul ul a:hover { background-color:#555; } Another thing... it appears fine in Chrome but has a border around the dashed breakers inbetween the images in IE. Any ideas please as I am a bit lost. Kind Regards, Ian
  12. No it is blank on the page source where it should say "like"
  13. Tried an elseif statement too (!=) but still isnt showing the echo... hmm
  14. Hello, I have gave you an extended snippet of the code and removed the && as I see I reference it twice (good spot ). The <FONT> tags are temp until I sort the code then I will cleanup with some CSS . <!-- LIKE BUTTON --> <?php if (isset($_SESSION['useridkey'])){ //check user id in url matches useridkey if ($_SESSION['useridkey']==$the_user_id){ // the following if the session id matches the variable //edit profile page echo "sessionid matches the user id variable"; } $loggedinuserid = $_SESSION['useridkey']; // if they are logged in $aretheyliked = mysql_query("SELECT * FROM boom_likes WHERE user_id=$loggedinuserid"); while($row = mysql_fetch_array($aretheyliked)) { //if they are liked by the user if (($row['liked_user_id']==$profileuserid))){ echo "<FONT SIZE=1 COLOR=BLUE>You Like This Artist"; } else { echo "Like"; } } // end of if they are logged in } else { // if they are not logged in echo "<FONT SIZE=1 COLOR=RED>You must be logged in to like this artist"; } ?> <!-- END OF LIKE BUTTON -->
  15. I have an if statement: // if they are logged in $aretheyliked = mysql_query("SELECT * FROM boom_likes WHERE user_id=$loggedinuserid"); while($row = mysql_fetch_array($aretheyliked)) { if (($row['liked_user_id']==$profileuserid)&&($row['user_id']==$loggedinuserid)){ echo "<FONT SIZE=1 COLOR=BLUE>You Like This Artist"; } else { echo "<FONT SIZE=2 COLOR=BLUE>Like"; } The idea is if the user is logged in they can click the "like". If they already like it it will say they already do like it. The else is not showing though. What am I doing wrong... it works when it matches but not when it dont
  16. I forgot an } lol! I have another problem though: $aretheyliked = mysql_query("SELECT * FROM boom_likes WHERE user_id=$the_user_id"); while($row = mysql_fetch_array($aretheyliked)) It turns around and says "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/boomchoon/pages/profileabout.php on line 73 " Line 73 is: while($row = mysql_fetch_array($aretheyliked)) Dont get it :S
  17. Hi I am having trouble getting the parser to parse this statement: if (($row['liked_user_id']==$user_id)&&($row['user_id']==$the_user_id)){ echo "<FONT SIZE=1 COLOR=BLUE>You Like This Artist"; } It spits out: Parse error: syntax error, unexpected T_ELSE in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/boomchoon/pages/profileabout.php on line 84 I am trying to combine two clauses where the "liked_user_id" row is equal to the variable "$user_id" AND the row "user_id" equals the variable "$the_user_id". Many Thanks!
  18. Hi there, Am trying to make a PHP mail script that is sent when the button is pressed. When the button is pressed it refreshes the page and does not send? Can anyone help please: <?php $emailaddress = "sales@systemshydroponics.co.uk"; //please replace this with your address $mail = $_POST['Email']; $porukaa = $_POST['Message']; $poruka = str_replace("\r", '<br />', $porukaa); //START OF THANKS MESSAGE //you may edit $thanks message. this is a message which displays when user sends mail from your site $thanks = " <p align='left' STYLE='font-family:arial;font-size:16px;color:#bed2df;'><br> <b>Your message has successfully been sent and we will contact you as soon as we can. Many Thanks!<br></b> <br> You will receive a copy of the message at your email address <b>($mail).<br>A member of our team will reply to you as soon as possible<br></b></p>"; //do not edit nothing below this line until comment (ME) say so if you don't have skills with PHP //END OF THANKS MESSAGE if($_POST['submitform']) { $Name = $_POST['Name']; $Email = $_POST['Email']; $Message = $_POST['Message']; $Phone = $_POST['Phone']; $Regarding = $_POST['Regarding']; $require = $_POST['require']; $browser = $HTTP_USER_AGENT; $ip = $_SERVER['REMOTE_ADDR']; $dcheck = explode(",",$require); while(list($check) = each($dcheck)) { if(!$$dcheck[$check]) { $error .= "You have not filled this field(s): <b>$dcheck[$check]</b>.<br>"; } } if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $Email))){ $error .= "Wrong e-mail.<br>This e-mail address <b>$Email</b> - is not valid. Please enter correct e- mail address."; } if($error) { echo $error; echo '<br><a href="#" onClick="history.go(-1)">Please try again.</a>'; } else { //START OF INCOMING MESSAGE (this message goes to your inbox) $message = " You have received a message from your websites contact us page: Name: $Name: E-mail: $Email Phone Number: $Phone Subject: $Regarding Message: $Message ----------------------------- Browser: $browser IP: $ip "; //END OF INCOMING MESSAGE (this message goes to your inbox) $subject = "Message from Systems Hydroponics Website - Message was sent by $Name"; //subject OF YOUR INBOX MESSAGE sent to you $subject2 = "You have successfully sent message from Systems Hydroponics!"; //subject of OUTGOING MESSAGE - edit this //OUTGOING MESSAGE TEXT $message2 = "You have sent a message to Systems Hydroponics: ----------------------------- Name: $Name E-mail: $Email Phone Number: $Phone Subject: $Regarding Message: $Message ----------------------------- "; //END OF outgoing MESSAGE mail($emailaddress,"$subject","$message","From: $Name <$Email>"); mail($Email,"$subject2","$message2","From: <$nasaadresa>"); echo "$thanks"; } } else{ echo ' <br> <form name="contactform" action="'.$PHP_SELF.'" method="post"> <input type="hidden" name="require" value="Name,Message"> <p align=left STYLE="font-family:arial;color:#bed62f;font-size:16px;">Name:<BR> <input name="Name" size="30" STYLE="font-family:arial;font-size:16px;color:#000000;text-align:left;"></p> <p align=left STYLE="font-family:arial;color:#bed62f;font-size:16px;">Telephone Number:<BR> <input name="Phone" size="30" STYLE="font-family:arial;font-size:16px;color:#000000;text-align:left;"></p> <p align=left STYLE="font-family:arial;color:#bed62f;font-size:16px;">E-mail*:<BR> <input name="Email" size="30" STYLE="font-family:arial;font-size:16px;color:#000000;text-align:left;"></p> <p align=left STYLE="font-family:arial;color:#bed62f;font-size:16px;">Subject:<BR> <select name="Regarding"> <option value="When is the store opening?">When is the store opening?</option> <option value="Hydroponics Products">Hydroponics Products</option> <option value="Hydroponics Brands">Hydroponics Brands</option> <option value="Making An Order">Making An Order</option> <option value="General Question">General Question</option> <option value="Other">Other</option> </select></p> <p align=left STYLE="font-family:arial;color:#bed62f;font-size:16px;">Message*:<BR> <textarea name="Message" rows="10" cols="70" STYLE="font-family:arial;font-size:16px;color:#000000;text- align:left;"></textarea></p> <p align=left STYLE="font-family:arial;color:#bed62f;font-size:16px;"> <input type="submit" value="Send Message to Systems Hydroponics" name="submitform" STYLE="font- family:arial;color:#000000;font-size:16px;font-weight:bold;background-color:#bed2df;"> </p> </form>'; } ?>
  19. Saying that... normally to check if the user is logged in I run this command at the top of each page. If a user is not having to register any more what do I change command to? <? session_start(); if(!session_is_registered(artistusername)){ header("location:login.php"); } ?>
  20. Because I am "including" the content pages I see I have no session start command. If I include that it works. What do we now use instead of session_register? Hmm?
  21. Ok, so sessions... it is a grey area for me but unfortunately on the system I am working on is kind of a must so I can get the website to work. I am trying to create a simple log in area on a website and I have got a log in form which goes to "checklogin.php". The "checklogin.php" script will check the users username and password against the db and if it matches it will forward them to their user control panel (using username and password in the URL). In the database the user_id which is an integer is the foreign key allowing me to reference a user for images/blog posts etc. The usercp.php page has a couple of inline querys which just set the page up. On the page I have set it to "register" the session called user_id. The problem is once a user logs in it registers and spits out the correct user_id. I need to keep this user_id in a session so it can be used on every page. Basically... what I intend to do is have a login box. This log in box should only show if the user is not logged in (i.e: something along the lines of "if (isset(['user_id_key'])) then show user panel button ELSE show login box. Really annoying me as currently when you log in it shows the user_id fine... but doesnt carry over to another page. HERE IS SOURCE CODE BELOW: checklogin.php (registers session and validates login details): $tbl_name="boom_users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['artistusername']; $mypassword=$_POST['artistpassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $myusername = mysql_real_escape_string($myusername); // Encrypt password to MD5 $encrypted_mypassword=md5($mypassword); $sql="SELECT * FROM boom_users WHERE Username='$myusername' and Password='$encrypted_mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "index.php" session_register("artistusername"); session_register("artistpassword"); $_SESSION['artistusername']=$myusername; $_SESSION['artistpassword']=$encrypted_mypassword; header("location:usercp.php?username=".$myusername."&sessionid=".$encrypted_mypassword.""); } else { include "wronglogin.php"; } ?> userpanel.php?username=".$myusername"&sessionid=".$encrypted_mypassword" (This is the users control panel WHERE the username and Password match a row and then spits out the name. In this example it spits out the "user_id". I store it as a session but doesnt stay saved when loading another page. <?php if (isset($_GET['username'])) { $username = $_GET['username']; } if (isset($_GET['sessionid'])) { $password = $_GET['sessionid']; } ?> <?php $usersession = mysql_query("SELECT * FROM boom_users WHERE Username='$username' && Password='$password'") or die(mysql_error()); while($row = mysql_fetch_array($usersession)) { $user_id_key = $row['user_id']; $_SESSION['useridkey']=$user_id_key; echo "the user id is ".$_SESSION['useridkey']; } ?> Basically... how do I store this session so it is available to call the "useridkey" value on any page? Kind Regards, Ian
  22. Single quotes Silly me! And sorry for not putting code in the script tags... will do next time... consider me told Once again... many thanks! Ian
×
×
  • 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.