veedeoo 474 Junior Poster Featured Poster

Hi,

Can you mark this solved, so that people stop clicking on the linked question.

Thanks....

veedeoo 474 Junior Poster Featured Poster

try,

<?php
   $scookie = "hi";
   setcookie("Cookie",$scookie);
   $someString = "5";

   echo $_COOKIE["Cookie"].$someString;
?>
veedeoo 474 Junior Poster Featured Poster

Can you please verify, if I am understanding your question fully well.

this
12345 Rihanna - Song #1

is roughly the output of this?

echo $row['id']." ".$row['artiste'] ." Song # ".$i;

If so, you don't have to put for loop within the while loop. You can let the $i increment while piggy back ridding on the while loop.. For example,

 $i = 0;

 while($row = mysql_fetch_array($result)){

$i++;

}

As long as the above remain true, $i will continue to increment until row returns false.

veedeoo 474 Junior Poster Featured Poster

copy, paste to notepad, save as anyNameYouWant.php, upload to your server, and then direct you browser to it.

  <?php phpinfo(); ?>

Look for the server API value and the loaded configuration file value..

  1. If Server API says anything about apache, then you can use the .htaccesss trick.

  2. If Server API says anything about CGI, fast CGI.. then you can add a new php.ini file in the root directory of your script. copy and save as php.ini and then upload to your server . Change 100M to your desired maximum upload file size. DO NOT use MB... this is very tempting in the minds of other to type MB.

        upload_max_filesize = 100M
        post_max_size = 100M
    
  3. Although not really necessary, except when you will be installing ffmpeg, mencoder on your server, then loaded configuration file value matters a lot. This is the php.ini file using by your server. This can be edited by way of SSH client like the PUTTY.

In most cases, people only need either 1 or 2 above.., but never both.

veedeoo 474 Junior Poster Featured Poster

What type of hashing the password had? It could be md5 or something? Look at you mysql database and look for the password value..

Change your input form code above to this

 <input type = "text" name="username"/>

If you use md5 to hash the password, we should hashed it to md5, before sending it to the query

   $password = mysql_real_escape_string($password);
   ## you only include codes below if you are sure that the password is md5 hashed.
   $password = md5($password);

   ## do your database query below like this.. you replace your codes above with this.
    $sql="SELECT * FROM user WHERE user_name='".$username."' and password='".$password."'";
veedeoo 474 Junior Poster Featured Poster

try chaning this

echo "<b><font color="red">".$data[0]." - Inactive Account / Invalid Pass</font></b><br />";

to this

  echo '<b><font color="red">'.$data[0].' - Inactive Account / Invalid Pass</font></b><br />';

change line 74 to this

echo '<b><font color="green">'.$data[0].' - SUCCESS!</font></b><br />';
veedeoo 474 Junior Poster Featured Poster

Hi,

Did the book ever mention about the PDO connector? It looks like or very similar to this.....

 <?php

  $host = 'localhost';
  $user = 'db username';
  $pass = 'db password';

 try {
$thisDb = new PDO("mysql:host=$host;dbname=mysql", $user, $pass);

echo 'We are connected';
}
 catch(PDOException $e)
{
echo $e->getMessage();
}
?>

The reason I am asking, because in the middle of your codes, you are using a PDO statement. In fact, you can use my sample code above, that should allow you to connect.

PDO is easy, but you need to have a reliable PDO connector class..Search for PDO connection class, or Database Singleton class.

veedeoo 474 Junior Poster Featured Poster

By the way, youtube allows 25 items per query and per username. If you want to parse all of those included in the rss feeds, then you must modify this part of the class above..

change this

 private $user;

to this

private $user;
private $total;

then just change the method to this

 public function getVideo(){
 $xml = simplexml_load_file("http://gdata.youtube.com/feeds/api/users/".$this->user."/uploads");
$this->total = count($xml->entry);
    $data = array(); 
    for($i = 0; $i < $this->total; $i++) {
$author = $xml->entry[$i]->author->name;
$id = $xml->entry[$i]->id;
$id = str_replace("http://gdata.youtube.com/feeds/api/videos/","",$id);
$data['title'] = (string)($xml->entry[$i]->title);
$data['content'] = (string)($xml->entry[$i]->content);
$data['id'] = (string)($id);
$vidInfo[] = $data;
}
return $vidInfo;
}

if you want to show the thumbnails, you must change the codes below the instantiated class to this.

  foreach ($show as $item){
  echo "<p><img src='http://i.ytimg.com/vi/".$item['id']."/0.jpg' width='100' height='100'/><br/>";
  echo $item['id']."<br/>";
  echo $item['title']."<br/>";
  echo $item['content']."<br/></p>";
 }
veedeoo 474 Junior Poster Featured Poster

ok, here is a simple class to get you started.. all you need to do provide the script witht the valid youtube username

<?php

    class GetUserVideo{

        private $user;

        function __construct($user){

            $this->user = $user;
        }

        public function getVideo(){
            $xml = simplexml_load_file("http://gdata.youtube.com/feeds/api/users/".$this->user."/uploads");
            $data = array(); 
            for($i = 0; $i < 10; $i++){
             $author = $xml->entry[$i]->author->name;
             $id = $xml->entry[$i]->id;
             $id = str_replace("http://gdata.youtube.com/feeds/api/videos/","",$id);
                $data['title'] = (string)($xml->entry[$i]->title);
                $data['content'] = (string)($xml->entry[$i]->content);
                $data['id']  = (string)($id);
                $vidInfo[] = $data;

            }
            return $vidInfo;
        }
    }

  ## instatntiate the class and setting the user
  $items = new GetUserVideo("Sindrannaras");
  ## we show the result
  $show = $items->getVideo();
  foreach ($show as $item){
    echo "<p>".$item['id']."<br/>";
    echo $item['title']."<br/>";
    echo $item['content']."<br/></p>";
} 
veedeoo 474 Junior Poster Featured Poster

HI,

Running xampp in windows, the directories are CHMOD'ed at 777 or writtable by default, so I can assure you there is not permission problem there.

Try, go to your localhost, the click on phpinfo(), find the value of upload_max_filesize and post_max_size. These values should be at least change to 60M or better yet make it as hight as 300M depending on what types of file your server will be accepting for uploads.

By looking at your script above, you are attempting to rename the uploaded file. Am I right? If so, we need to find the file extension of the uploaded file first, and then move the uploaded file to your target directory.

Something like this. I have no time to test this , but this is pretty much you will need.

 ## this is your uploaded file in the tmp directory e.g. C:\xampp\tmp\php9634.tmp
 $tempfile = $_FILES['file']['tmp_name'];

 ## the file name of uploaded file as shown on your desktop e.g. somefile.jpg
  $filename =($_FILES['file']['name']);

 ## we get the extension of the uploaded file
 $ext = substr( $filename, strrpos($filename, '.') + 1);

 ## we define new filename without extension
 $newFilename = $res['id'];

 ## we check if directory exist
 $upload_dir = "users/".$_SESSION['ID'];

 if (!file_exists( $upload_dir)){
 ## create directory
 mkdir( $upload_dir, 0777, true);
 ## we set permission to 0777 or 777
 ## this may not work in windows, and should be commented, but should work in linux servers.
 chmod($upload_dir, 0777);

 }

 ## we are done checking if everything are ok, …
veedeoo 474 Junior Poster Featured Poster

I am currently using Cleditor. It's pretty light 1 js file, one css file, and two images, a total bandwidth consumption of less than 10k.

diafol commented: Nice +14
veedeoo 474 Junior Poster Featured Poster

You need to post the remainder of your codes.. this is the page responsible for displaying your content. Just post the ones that has $_GET['page'], or $_POST['page'];

Here is the demo of my suggested approach above. It only took less than 20 munutes. I even made it without page reload, and it is using PDO the rest are just pretty much the same as any pagination script out there.

If you search my previous post, bout two weeks back, I wrote a full pagination function. It is the same pagination script I used on the demo above.

veedeoo 474 Junior Poster Featured Poster

Hi,

I agree with the above response. You will have to understand it, and use it to your application.

Let me write a simple skeleton on what you have above..

 class SomeYtApi{
 ## define properties
 private $url;
 private $id;

 ## followed by the constructor
 function __construct($url, $id){
 $this->url = $url;
 $this->id = $id;
 }
 ## this is method of the class
 public function doSomethingWithUrlAndId(){
 if(!empty($this->url)&& (!empty($this->id)){
 ## do something with the valid url and id above here

 return output;
} ## end of method.
} ## end of class

## if needed be, we extend the class above by doing like this

class newApi extends SomeYtApi{
## define property unique to this class
private $unique;

## this is the constructor of this extended class. I want you to pay attention on what are the properties inside the parenthesis.
 public function __construct( $url, $id, $unique ) {

 ## since that the parent class already have these properties, we need to envoke parents constructor. This is very important in learning OOP in php you can this->this and this->that, but if you don't understand this pretty well, you will be completely lost even for years.

 parent::__construct( $url, $id );
 ## this is the only time we can define the propert of this class

 $this->unique = $unique;

 }

 public function getThisUnique(){

 ## do whatever

 }

 ## you can even extend the parent class one more time to do another things.

The beauty of oop is that you can instantiate the class several …

veedeoo 474 Junior Poster Featured Poster

This is just an idea... others may have a better one..

 if($page !=$lastpage){
 ## add this at the end of the page number block
 ?>
 <input type="text" name="goto"><input type="button" name="this_button" value="go">
 <?php
 }
 else{
 ## you hide the go button because we are already at the end of the pagination count
 ## show nothing..
 }
 ?>

Then somewhere in the remainder of your script, process or catch the users click on "this_button" and then grab the value of "goto".. that would be equal to the page number jump.

veedeoo 474 Junior Poster Featured Poster

Hi,
You can try logging in the admin first, and then generate a random security salt, assign this salt to session e.g. $SESSION['security'] = 1653e9gg4r99s@$7700)llls434rf853~, and then on your member's database table, you must insert this in session column. While the admin hops over pages, you can double check if the session salt still matches with the one recorded on the database. Session expiration will help also e.g. 45 minutes to generate a new salt, update database session column. Upon logout of the admin database session entries should also be unset. In my logged in sytem, I post salt as session, and then the IP address of logged in members.

veedeoo 474 Junior Poster Featured Poster

Hi,

I think your code will only take up to 6 thumbnails. To put more thumbnails, thumbnails needs to scroll ..There is a jquery that can do this. If my memory still serves me well, I think it was called jmycarousel it is free , and there is this jquery plugin written by makers of the flowplayer, it is called scrollable. Let me know if you need help in setting it up, so that I can help you writing the layout.

veedeoo 474 Junior Poster Featured Poster

Ok guy,

Here we go.. obviously I over slept up to the point where my professor sent someone in my dorm to wake me up.

I will just paste it here so that if other people may find this post useful, for whatever it's worth.....Ready?

Step One: In your htdocs directory, create a new directory called blob, inside the blob directory create another and name it uploads, and the rest are simple as copy and pasting. Copy sql below to create a new database table and name it "test". You are welcome to add more columns to your need.

 CREATE TABLE IF NOT EXISTS `images` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `image` longblob NOT NULL,
 `thumb` varchar(100) COLLATE latin1_general_ci NOT NULL,
 `title` varchar(255) COLLATE latin1_general_ci DEFAULT NULL,
 PRIMARY KEY (`id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci ;

The above sql is pretty common, with one EXEMPTION.. I used longblob. This will allow you to upload or store bigger files at least 3-5mb.

Step Two: Create a file named settings.php..actually this is just the database credentials file. pretty basic

 <?php
 ## filename settings.php
 $user = "root";
 $pass = "";
 $host = "localhost";
 $db_name = "test";
 ?>

Step Three: Create a new file called function.php

 <?php
 ## filename: function.php
 ## simple class
 function simple_func($sql){
 ## define your database connection credentials
 include 'settings.php';

$conn = mysql_connect($host,$user,$pass) or die(mysql_error());
$db = mysql_select_db($db_name,$conn)  or die(mysql_error()); 

$result = mysql_query($sql, $conn) or die(mysql_error()); 
## we check and make sure we are getting a …
phorce commented: You are amazing lol. +4
veedeoo 474 Junior Poster Featured Poster

It's getting really late in my time zone .. not late it is already early in the morning,,, I'll just give you the files I have created in my localhost, before I head up for scholl in about 6 hours from now. I'm going to pick up a short snooze...

It includes upload capability, insert and retrieve to and from database as blob, then confirmation page where the uploaded file can be viewed as blob..

If I don't run out of time, I will also give you the blob thumbnails function I used for testing. Although I don't recommend using this function, because it is using too much memory I think people in this community deserve to see how it can be done..Just make sure you have the GD support enabled on your xampp, before attempting to run this script.

be right back later for this thread......my starbucks energy is slowly fading away....

veedeoo 474 Junior Poster Featured Poster

Images table has ID, Image itself, UserID(who uploaded that), Status and Date(Uploaded). I store images as BLOB

That refers to the id column of your images table. I use it, because you said you have an image table with id.. just replace it with whatever you have e.g. ID.. the view.php will use this id to send query to your database and show the single image.

I set up the query to pass the result $row into array $data[], then we loop this as $images. This is a good approach, especially if you will be separating the logic of your application from view. By setting it up like that, we can easily use any templating system that will come to mind at a later time. Setting it up with..not too much html mixing with the php codes. Mixing them in uncrotrolled proportion, will create problems in maintaining your application.

Because we are using php without the benefit the of any templating system, it is difficult to use the dot notation e.g. images.id . Templating system can easily achieve this, but that is out of the scope of this topic. It is nice to have the database connection be included in a simple function, so that if some time later, you need to re-write everything into simple class, the output of the query is already inside of a function. All you have to do is define the properties , and this simpe function is still in good shape working …

veedeoo 474 Junior Poster Featured Poster

before editing your php.ini file, you need to know which configuration file is currently loaded on your server. There are two php.ini files one is located in the apache and one is in the php directory.

if you run phpinfo(); you should be able to see the value of the loaded configuration file. Then wherever it is that's the php.ini file you need to edit.

don't forget to restart your server..

veedeoo 474 Junior Poster Featured Poster

Ok.. let's modify this one again . Sorry, it took me a while... my wireless keyboard ran out of battery. I need to recharge...

foreach($data as $images )
 {
 $img = $images['imageItself'];
header('Content-type: image/jpg');
 ?>
 <a href="location"><?=$img?></a>
<?php
 }

Change the above code to this

foreach($data as $images )
{


?>
<a href="view.php?id=<?=$images['id']?">View this image.<?=$images['id']?></a>
<?php
}

Then we can create a file view.php using your own codes above to show single image

 ## filename view.php
 ## add your database configuration file here

 if(isset($_GET['id'] && (!empty($_GET['id'])){
 $query = mysql_query("SELECT * FROM images WHERE id='".$id."'");
 $row = mysql_fetch_array($query);
 $content = $row['image'];

 header('Content-type: image/jpg');
 echo $content;
 }
 else{

 //do nothing this is just a test
 }

I set it up on my localhost like that and it is working... If it works for you, we just to make thumbnails so that you can use the thumbnails from the thumbnail directory as links..

ADDED LATER: I attempted to generate thumbnails from the blob . It was successfull, BUT it is using tremendous amount of memory. My test images sizes are 1mb, 2mb, and 10mb. For a much bigger database.. this will cause the mysql server to ran out of memory...I am running it on 16GB localhost. server type apache ->xampp on ubuntu..hard drive installed and not portable..

veedeoo 474 Junior Poster Featured Poster

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'steve_wff'@'208.113.246.18' (using password: YES) in /home/steve_wff/worldfamousflags.com/usssa/system/database/mysql.php on line 6

Like the error already said, check your database username's password. Make it is using the right password for the username defined in your msql.php file line 6.

veedeoo 474 Junior Poster Featured Poster

ok, hold on let me write a working demo script for you to use.. including upload script.. I wrote something like this long time ago. It is in my hard. I just need to find it and set it up for live server.. Wait for a few minutes...

veedeoo 474 Junior Poster Featured Poster

Can you put up the snippet of your codes repsonsible for inserting image as blob? This has to be binary.. Just hold on let me write a simple script that will do this... I think we need to add header type .. Let try this first.

change this

 foreach($data as $images )
 {
 ?>
<a href="location"><img src="<?=$images['imageItself']?>" width = "100" height="100"/></a>
<?php
}

to this

 foreach($data as $images )
 {
 $img = $images['imageItself'];
 header('Content-type: image/jpg');

 ?>
<a href="location"><?=$img?></a>
<?php
}

What we are trying to achieve with the modified codes is to show images in their actual size. I also use the header php function. This may work... please let me know so that I can continue writing a demo if it does not work..

veedeoo 474 Junior Poster Featured Poster

This one Click Here. But it is not free though. With a little knowledge of basic php programming, you can probably create one for yourself.., then just implement the things you already know in ajax, css, html..

veedeoo 474 Junior Poster Featured Poster

I don't know if they still have it now, but this is the high school I graduated from 3 years ago.. Click Here., Where the future harvard, princetonian, caltech candidates are being created all year round in southern california..

veedeoo 474 Junior Poster Featured Poster

Have you ever consider php powered gallery? It is more manageable than just pure html gallery type.. PHP should be able to give you the options to edit, delete, or even upload your files...

veedeoo 474 Junior Poster Featured Poster

If we want the page containing the images to be inserted in an iframe, then you can create the page dynamically..or write a simple php function to retrive the images data from the database and call it within the iframe.

example of dynamically created page. Let's say, we have a page called iframecontents.php.. this is the file that will be called by the iframe ... e.g.

<iframe src="iframecontents.php"></iframe>

Let's make sense out of the iframecontents.php..

  ## filename : iframecontents.php

  ## normally, I get pretty lazy this time of the day, but I am fighting for it as much as I could, let us write a simple function. I want it reusable at any page if needed be.

  function show_images($sql){
  ## define all of your database credentials below
  $db = "someDb";
  $db_host = "localhost";
  $db_user = "someUser";
  $db_pass = "somepassword";


  ## let's connect to database..
  $connect = mysql_connect($db_host,$db_user,$db_pass) or die(mysql_error());
  $db = mysql_select_db($db,$connect)  or die(mysql_error()); 
  $result = mysql_query($sql, $connect) or die(mysql_error()); 

  ## now that we are connected we can loop through the result

  while($row = mysql_fetch_array( $result )) 
  {
  $data[] = $row;
  }
  ## we return the data

  return $data;

  }  
  ## end of our little function

  ## code below is responsible for generating the actual result given by query..

  ## define the query
  $query = "(SELECT * FROM images )"; 

  ## call the function above
   $data = show_images($query);
    ## iterate through the results returned by the function 
   foreach($data as $images ){
      ?>
      <p><a href="location"><img src="<?=$images['imageItself']?>" width = "100" …
veedeoo 474 Junior Poster Featured Poster

Hi,

Ans 1. FTP is a lot faster than your conventional file management in cpanel. It will be a lot easier to change file and directory permission using FTP program e.g. filezilla.

Ans 2. Yes, anything that refers to instruction such as create a new directory in your root directory.. will be beneath the public_html directory (please read extra info. below). The reason is that above public_html are not viewable to the browser. However, there are cases where some scripts e.g. php, perl can be placed above the public_html, but that out of the scope of your question.

Ans3. The image directory should be created inside the public_html directory.. Normally, your hosting provider will tell you where to put all of your files, but by default it is the public_html.

Extra info.

file permission. sometimes, books will instruct you to give permission to files or directory. To change or set permission to specific directory or files using FTP, just right click on the directory or file, and then select file permission.. type in the number suggested by the author.. e.g. 0777, 777, 0755, 755. again it all depends on server settings e.g apache module, cgi or fast cgi. Most servers, will assign persmission to a newly created directory with 755.. again it all depends in the server configuration.. e.g apache module or fast cgi?

In environment like shared hosting account, you would notice that you can easily add new domains under one account. So, the files inside the public_html belongs …

JorgeM commented: well done! +4
veedeoo 474 Junior Poster Featured Poster

Hi,

try reading this one Here. That is one of many implementation I found.

While this one Here is pretty good I think. It all depends on how fancy you want it to be..

veedeoo 474 Junior Poster Featured Poster

Correction, look for the class android, and for the method called filedir as in

  $android = new Android();

 define('BASE_DIR', $android->filedir);

Inspect all the methods in the android class.. one of them is responsible for what you are looking for.. If you don't find it, just extend the android class like so..

 class YourClass extends android{
 private $yourProperty = null;

 public function __construct('redefinePropertyNeededByYourMethodAndMustBeInheritedByYourClass_YourClass,$yourProperty){
 ## below is pretty much the copy of the parents constructor
 parent::__construct('redefinePropertyNeededByYourMethodAndMustBeInheritedByYourClass_YourClass);
 $this->YourProperty = $whatEverIsYourNewProperty;

 ## define your method declare it as public if it is set as private above.
 public function get_yourMethodOrFunction(){

 ## this is the part where you need to do your changes

 }

 return $this->get_changesYouMadeOutOftheParentsMethod;

 }
 ## end of class YourClass
veedeoo 474 Junior Poster Featured Poster

Hi,

Look for the class file, and the method called $android.. OOP have setThisFunction and getThisFunction.. in your case look for the seThisFunction.. e.g. public function fetchFile()..

The item you are looking for is probably located in the constructor, if not look up somewhere above the property block.

By the way, you already asked this question? Why double post it?

veedeoo 474 Junior Poster Featured Poster

Hi,

In response to question 1, you have two options here. First is storing the images as BLOB(which I don't really recommend, unless you have a superly expensive copyrighted images.) , second, just have the image filename stored in database.

Say you have a database called image, and this image table have the following columns id, name, status, access. Simple explanations of columns: id is set to auto-increment, name is for the filename e.g. somejpg.jpg, status can be set to true or false, and finally access can be set to public or private.

Using the above image's parameters, we can then build our database query based on those columns. e.g. select from image where status='true' (this pull out all of the images with the status set as true).

For question two, You don't have to use iframe for this type of application, you can just send query to the database and just iterate the results, thus showing these results on the page.. Again I am assuming here that you already have a database setup for your members, and a login system to validate your users.

Depending on your login system validation for members logged in or not.., we can use a query based on this validation like

 if ($loggedIn){
 ## we make the image href url live
 echo '<a href="locationOfYourImages/'.$row['name'].'.jpg"><img src="locationOfThumb"/></a>';

 }
 else{
 ## show thumbnail without link

 ## if you allow the public to view sample images, just to intice prospective new members

 ## you can then show …
veedeoo 474 Junior Poster Featured Poster

Hi,

Just place your cursor before > and then hit back-space . I think the arrow operator has been separated. Do the same on line 20. -> should not be separated as shown on your codes - >

veedeoo 474 Junior Poster Featured Poster

Good luck, I am looking at my joomla in my localhost. I have the oldest version way back in the late 2010. So, I really have to update it before I can take a look at their classes.

Its just probably just something that needs to be extended... in their database connection class. It is good to just go for extending the responsible class, this way you can write it specific to your needs..

veedeoo 474 Junior Poster Featured Poster

Hi,

let me test it on my joomla, but try dschuett's suggestion first. It should work...

UPDATE: Sorry, when I editied my response the array sample got deleted. Here it is again.

$thisArray = array('item1','item2','item3','item4')

$_SESSION['items'] = $thisArray;

## to access the array, you just have to start session
## for example,
session_start();

## item1 to 4 
$_SESSION['items'][0];
$_SESSION['items'][1];
$_SESSION['items'][2];
$_SESSION['items'][3];
dgibbons82 commented: Thanks for the help! My apologies for taking so long to respond. +0
veedeoo 474 Junior Poster Featured Poster

Hi,

Yes you can do it.. here is sample. This example demonstrate how to assign array in session.

1.php

<?php
session_start();
   ## page one
   $sku = "12345678_SKU";
   $itemID = "580007";
   ## make sure the above are not empty
   if((!empty($sku))&&(!empty($itemID))){

   $itemAr = array( $sku, $itemID );
   $_SESSION['items'] = $itemAr;

   }

   echo '<a href="2.php">Go to page 2</a>';
?>

2.php . I am not a big fan of php shorthand tags, but I will use it here..

 <?php
   ## filename 2.php
   session_start();
   ## let's access items in the session and move them to form input
?>
   <form method="post" action="3.php">
    <p>
   <label>SKU</label>
   <input type="text" name="sku" value="<?=$_SESSION['items'][0]?>"/><br/>
   </p>
   <p>
   <label>Item ID</label>
   <input type="text" name="itid" value="<?=$_SESSION['items'][1]?>"/><br/>
   </p>
   <p>
   <input type="submit" name="submit" value="Next"/><br/>
   </p>
   </form>
   <!-- end of form -->

3.php This file demonstrate how we can unset session for specific array assign to it, and then assign a new set of array.

 <?php
   ## filename 3.php
   session_start();

   ## since that this page is now relying on the items submitted in the form, we can unset our session['items']


   if((isset($_POST['submit']))&& (!empty($_POST['sku']))&& (!empty($_POST['itid']))){
   ## unset session from two previous page to set these form items
   ## if browser is going to go back and forth between pages, do not unset the first session, instead create a new one.
   unset($_SESSION['items']);

   ## I added a suffic -> _two on the posted items, for 4.php checkpoint. We want to make sure the session has been unset if wa
   ## we want it unset.
   $sku1 = $_POST['sku']."_two";
   $itid = …
LastMitch commented: Thanks for the example! +2
veedeoo 474 Junior Poster Featured Poster

did you try?

 while($row = mysql_fetch_array($result)) {
 $thisArray[] = $row;

 }
veedeoo 474 Junior Poster Featured Poster

Please double check on my added Later info. above. I normally type in the codes raw in this text area, so changes on my posted codes can occur between the time I posted it upto the set time, I can no longer edit.. it should work. Your corrected code should be like this...

$result = mysql_query("SELECT * FROM track ORDER BY rand()");
    while($row = mysql_fetch_array($result)) {
     $url = preg_replace("/^http?\/\/(.+)$/i","\\1", $row['car']);

    ?>
    <td> <a href="http://<?php echo $url; ?>" class="mylink" target="_parent"><?php echo $row['tag'];?></td>
    <?php
    }

I remove the short tags, because I don't know your server settings. It is a lot safer this way..

Yes, it will strip http// ONLY, and not www.someurl from your database as row['car'] value. the link of the corrected codes above should be like this http://www.whateverDotCom.

Kniggles commented: missed a : however very helpful and very quick and thank you,jerrijeff. +2
veedeoo 474 Junior Poster Featured Poster

I suspected that might have been the case, that's why I want the echo row['car'].. The problem here is the http//www got inserted on your database. If you don't have any way of correcting them, because your database has already been populated by thousands of those, our last resort to test this code first..If it works then we will use the preg_replace.. it will be double processin on the part of your server. However, that is the only way I could think as quick fix right now.

Remember our test code above? Let's use it again . It is a lot easier that way,,

  $url = preg_replace("/^https?:\/\/(.+)$/i","\\1", $row['car']);
  ## we can echo the url to make sure the http// has been removed.
  echo $url."<br/>";

Once again, I want you to post what do you get? You should be getting something like this www.SomeDomainDotCom. without the htpp//.

ADDED LATER: It should be like this, because there is no :

 $url = preg_replace("/^http?\/\/(.+)$/i","\\1", $url);
veedeoo 474 Junior Poster Featured Poster

I just wan't to make sure that we can duplicate the same error on a regular link..Can you please create a new file , paste the code below and save the file as anyname.php , load this file to your server..

  <?php
 $url= "daniweb.com/web-development/php/threads/422216/url-not-working-right";
 $link = "daniweb";
   echo '<td> <a class="mylink" target="_parent" href="http://'.$url.'">'.$link.'<br>';
?>

if you click the link on it, it should take you back on this thread. Please double check that : is not missing on the link.

To make sure that it is not a parsing problem, the code can also be use.. Assuming that php shorthand is enabled on your server.

 $result = mysql_query("SELECT * FROM track ORDER BY rand()");
   while($row = mysql_fetch_array($result)) {

 ?>
    <td> <a  href="http://<?=$row['car']?>" class="mylink" target="_parent"><?=$row['tag']?></td>
<?php
 }

If the link still don't connect to the tartget url when http:// is used, it is the target site that has a DNS problem.

One last note for you to consider, if the row['car'] is printing http:/someDomainDotCom, then the href above should only be like this

   href="'.$row['car'].'"
veedeoo 474 Junior Poster Featured Poster

The reason I made you echo the items coming form your database is to make sure that we are getting something. Now, that we are sure of that. Let's put back the code only with the following correction.

echo '<td> <a href="http://'.$row['car'].'" class="mylink" target="_parent">'.$row['tag'].'</td>';

At first, I did not notice that your href is way outward .. I am not sure if this is what is causing the : to disappear, but I think it is worth trying. On the other hand, I don't think it would be the case though..

veedeoo 474 Junior Poster Featured Poster

hi,

can you change your code above to this..

//echo '<td> <a class="mylink" target="_parent" href="http://'.$row['car'].'">'.$row['tag'].'<br>';

echo $row['car']."<br/>";
echo $row['tag']."<br/>";

Tell us what do see on the screen..

veedeoo 474 Junior Poster Featured Poster

try,

   echo '<td> <a class="mylink" target="_parent" href="http://'.$row['car'].'">'.$row['tag'].'<br>';
veedeoo 474 Junior Poster Featured Poster

try,

$user2 = " this / ?  is ~~ + | $ ##  * 7 ) user  name  <br/>";

    $user2 = preg_replace('/[^a-zA-Z0-9 ]/s', '', $user2);
    $user2 = trim(str_replace(' ','',$user2));

    echo "<br/>".$user2."<br/>";

Let the preg_replace to get process first, and then the trim string replace. They cannot be condensed I think.. I don't have the chance to test it.. Please let me know if the codes above worked..

veedeoo 474 Junior Poster Featured Poster

try..

 $username = " this  is  user  name  ";
   $username = trim(str_replace(' ','',$username));
   echo $username;

for registration, try

  $username = preg_replace('/\s\s+/', '', $username);
veedeoo 474 Junior Poster Featured Poster

You can also do it this way...C++ style... The $z is rolling in its own grease a 100 times ..

  <?php
  call_user_func( $x = function( $yx, $z =1 ) {
echo (string)("Hello World <br/>"), $yx[floor($z/100)]($yx, ++$z);
}, array( $x, function(){} ));

?>
veedeoo 474 Junior Poster Featured Poster

Hi,

Move all these before the while loop..

 <div class="body2">
  <div class="main">
  <section id="content">
  <div class="wrapper">
  <article class="col1">
  <div id="slider">

and then after the closing curly bracket of your while loop, move these.

    </div>
    </article>

By the way, where is the opening tag of article?

veedeoo 474 Junior Poster Featured Poster

Dude,

You need to learn how to relax, and take it easy... panicking will not make you a better coder. Just seat back, relax, look over the window, if you have a cup of starbucks coffee within your reach, take a sip or two, take a few deep breath, exhale , and then slowly.. look back at your monitor.

Once you have done that, look at your database query if it matches your database table columns..better yet, post your insert codes here.

veedeoo 474 Junior Poster Featured Poster

you have too many un-necessary statements and queries. Remember, you are only validating ONE member, one password, one ip, and lastly one id.

Your first query to validate user should be enough,.. Checking the id don't make sense. Especially, if the id is auto incremented on your database. It does not help and will not help at all..

**session_register is long gone and depricated sometime ago.. **

Hold on, let me rewrite your codes..

NEVER MIND you already marked this question as solved...