1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Generating a new list item.

Discussion in 'PHP' started by zXen, Apr 19, 2007.

  1. #1
    Hi,

    I am quite new to PHP, so it might sound quite simple what I am trying to do.

    I have a list of images that are within an <li> tag. I have made an upload tool, which uploads an image to my image folder, which works ;) and while they are selecting to upload an image they have to enter a link into the text box. So when they click that image it will take them to that destination.

    Basically what I am trying to do is find a way to get those images and weblinks added to a newly created list item. I know how to add them to the existing list items, i'm just struggling on how to get it so i can hit a submit button and adds that image and weblink to a newly generated list item.

    The code I have at the moment ( This is the php file that contains the list items) is:

    
    
    <?
    
    $dbcnx = @mysql_connect('localhost:3306', 'root', 'me334');
    mysql_select_db('main');
    
      
        // Request the text of all the contact information in the database
        $result = mysql_query(
                  "SELECT ID, Name, Type,Size, Link FROM images");
        			
    	  if (!$result) {
          echo("<P>Error performing query: " .
               mysql_error() . "</P>");
    	  }
    		   
    	while ( $row = mysql_fetch_array($result)) {
    		$ID=$row['ID'];
    		$Name=$row['Name'];
    		$Type=$row['Type'];
    		$Size=$row['Size'];
    		$Link=$row['Link'];
    }
    
    ?>
    
    <li><a href="http://www.<?=$Link?>.com" title="">
    	<img src="images/<?=$Name?>" title="" /></a></li>
    <li><a href="http://www.<?=$Link?>.com" title="">
    	<img src="images/<?=$Name?>" title="" /></a></li>
    
    
    Code (markup):
    The Upload file code is (I know the submit button doesnt really do anything ATM):

    
    <?
    	if($_FILES['generic']['name'] . $_POST['link']== NULL){
    ?>
    		<form action="<?=$_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data">
    			<p>File to upload:</p>
    			<p><input type="file" name="generic" /></p>
    			<p>Link to <input type="text" name="link" value=""/></p>
    			<p><input type="submit" value="Upload File!" /></p>
    		</form>
    <?
    	} else {
    	
    		$uploaddir = 'C:/Program Files/Apache Group/Apache2/htdocs/MAIN/uploads/';
    		$uploadfile = $uploaddir . $_FILES['generic']['name'];
    		$filename = $_FILES['generic']['name'];
    		$link = $_POST['link'];
    		
    		if (move_uploaded_file($_FILES['generic']['tmp_name'], $uploadfile)) {
    			?>
    				<p><b>Upload Successful!</b></p>
    			<?
    		} else {
    			?>
    				<p><b>Upload Failed!</b></p>
    			<?
    		}
    		
    ?>
    
    <?
    
    $dbcnx = @mysql_connect('localhost:3306', 'root', 'me334');
    mysql_select_db('bateszi');
    
    	$name = $_FILES['generic']['name'];
    	$type = $_FILES['generic']['type'];
    	$size1 = $_FILES['generic']['size'];
    	$link = $_POST['link'];
    	$sql = "INSERT INTO Images SET
    		Name='$name',
    		Type='$type',
    		Size='$size1',
    		Link='$link'";
    	if (@mysql_query($sql)) {
    		echo('<p>New Image Added</p>');
    	}	
    	    else {
    		echo('<p>Error adding new Image: ' . 
    		mysql_error() . '</p>');
    		}
    ?>
    
    
    
    		<p>Filename is: <?=$_FILES['generic']['name']?></p>
    		<p>File type is: <?=$_FILES['generic']['type']?></p>
    		<p>File size is: <?=$_FILES['generic']['size']?></p>
    		<p>The image will be linked to: <?=$_POST['link']?></p>
    		<p><img src="/MAIN/uploads/<?=$_FILES['generic']['name']?>" /></p>
    		
    	<p>Add imsage to thumb list?</p>
      <input type="submit" name="submit" value="SUBMIT" />
      </form>
    
    		
    <?
    	}
    ?>
    
    
    Code (markup):
    The php file where their outputted to is:

    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    
    <head>
    
    	
    	<style type="text/css" media="all">@import "css/master.css";</style>
    	<?php include("main_col.php"); ?>
    </head>
    
    <body>
    
    	<div id="sidebar-a">
    		<div class="padding">
    			<h2>Thumbnails</h2>
    				<ul id="navlist">
    					<?php include("output.php"); ?>
         			</ul>
    				
    			<h2>About</h2>
    			<p>
    			Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam gravida enim ut risus. 
    			Praesent sapien purus, ultrices a, varius ac, suscipit ut, enim. Maecenas in lectus. 
    			Donec in sapien in nibh rutrum gravida. Sed ut mauris. Fusce malesuada enim vitae lacus 
    			</p>
    
    		</div>
    	</div>
    	
    	<div id="content">
    		<div class="padding">
    			<h2>Upload a Thumb</h2>
    			<br />
    				<?php include("file_upload.php"); ?>
    		</div>
    	</div>
    
    </div>
    </body>
    </html>
    
    
    Code (markup):
    Hope this helps, thanks for responses.
     
    zXen, Apr 19, 2007 IP