Jump to content

freakunleash

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Everything posted by freakunleash

  1. @Psycho Thanks I got the result... I used below line to display default image... $img = ($row['pphoto_localurl']!='') ? $row['pphoto_localurl'] : $dft_img; if/else statment in the code is for alternating the row color not to provide default image.
  2. Hi All, Need help. I'm strugling to figure out how to write the code to display default image if no image is available. I'm able to display image if data is available. Not able figure how to echo if/else statment. Below is the code <?php function perDetails($var1, $result, $var2){ $dft_img = 'lib/images/name.png'; echo '<div class="desc">'.$var1.'</div>'; $color="1"; echo '<table align="center" cellpadding="2" cellspacing="1">'; while($row = mysql_fetch_array($result)){ $id = $row['pid']; $name = $row['pname']; $img = $row['pphoto_localurl']; $poster = str_replace("./", "lib/", $img); if($color==1){ echo '<tr bgcolor="#FFC600"><td><img src="'.$poster.'" width="32" height="42" alt="'.$name.'"</td><td><a href="persons.php?det='.$var2.'&perid='.$id.'"> '.$name.'" </a></td></tr>'; $color="2"; } else { echo '<tr bgcolor="#C6FF00"><td><img src="'.$poster.'" width="32" height="42" alt="'.$name.'"</td><td><a href="persons.php?det='.$var2.'&perid='.$id.'"> '.$name.'" </a></td></tr>'; $color="1"; } } echo '</table>'; } ?>
  3. thanks dragon...this is what I was looking for..... I will go through code now & see what I was missing.....
  4. Hi All, not able to understand I'm making miskate in CSS or PHP foreach statement. Need help with proper formating of the below code. I want to format the so that seasons divs will contain all the details about the episodes, title & plot. As of now season div is only wraping around the first episode only & ignoring remaining episodes details. Sorry I'm not able to explain this in words but if you access below code you will be able to understand. <html> <head> <style type="text/css"> .main { width: 750px; margin-right: auto; margin-left: auto; background: #cc1; clear: both; overflow:auto; } .season { margin: 5px; padding: 5px; width: 730px; background: #960; } .details { overflow:hidden; } .ep, .title, .airdate, .plot { margin: 5px; padding: 5px; width: 675px; background: #CCC; } </style> </head> <body> <?php $eps = array( array( 'year' => '2005', 'eptitle' => 'title1', 'airdate' => 'Apr 24 2009', 'epplot' => 'plot of S01E01', 'season' => '1', 'episode' => '1'), array( 'year' => '2005', 'eptitle' => 'title2', 'airdate' => 'May 1 2009', 'epplot' => 'plot of S01E02', 'season' => '1', 'episode' => '2'), array( 'year' => '2005', 'eptitle' => 'title3', 'airdate' => 'May 8 2009', 'epplot' => 'plot of S02E01', 'season' => '2', 'episode' => '1'), array( 'year' => '2005', 'eptitle' => 'title4', 'airdate' => 'May 12 2009', 'epplot' => 'plot of S02E02', 'season' => '2', 'episode' => '2'), array( 'year' => '2005', 'eptitle' => 'title5', 'airdate' => 'May 15 2009', 'epplot' => 'plot of S03E01', 'season' => '3', 'episode' => '1'), array( 'year' => '2005', 'eptitle' => 'title6', 'airdate' => 'May 28 2009', 'epplot' => 'plot of S03E02', 'season' => '3', 'episode' => '2'), ); //var_dump($eps); $season = 0; echo "<div class='main'>"; foreach($eps as $k){ // season check start if($season!=$k['season']) { echo "<div class='season'><b>SEASON : </b>".$k['season']; } //season check finish echo "<div class='details'>"; echo "<div class='ep'><b>EPISODE : </b>".$k['episode']."</div>"; echo "<div class='title'><b>TITLE : </b>".$k['eptitle']."</div>"; echo "<div class='airdate'><b>AIRDATE : </b>".$k['airdate']."</div>"; echo "<div class='plot'><b>PLOT : </b>".$k['epplot']."</div>"; echo "</div>"; // season check start if($season!=$k['season']) { echo "</div>"; $season = $k['season']; } } echo "</div>"; ?> </body> </html>
  5. Thanks guys... actually im not any issue with the code but im having a doubt that im doing somthing wrong.
  6. I have a doubt that I’m doing something wrong in the below code but I’m not able to figure it out. As of now I’m getting the correct result which I’m expecting. Please check below code & let me know if there are any mistakes: <div class='imgs'><a href='movies.php?movieid=<?php echo $id;?>'><img src='<?php if(!empty($poster)){echo $poster;}else{echo $dft_img;}?>' width='214' height='314' alt='<?php echo $title;?>' </a></div> regards Bhaskar
  7. Any idea how to use it. i dont have any clue how to use it.....
  8. Need help in updating the tables I have array of data coming from a form which I'm inserting in my DB. I have 5 tables product filter product_filter heater product_heater Im able to put the data in the "product", "filter" & "heater" tables but i dont know how to put data inside the "product_filter" & "product_heater" table. Any help or direction to any tutorails is appreciated. My Tables structure: product id int(5) product text cost text details text filter id int(5) filter text imgpath text product_filter id int(5) id_product int(5) id_filter int(5) heater id int(5) heater text imgpath text product_heater id int(5) id_product int(5) id_heater int(5) // Product data Update $name = mysql_real_escape_string($_POST['product']); $cost = mysql_real_escape_string($_POST['cost']); $details = mysql_real_escape_string($_POST['details']); $sql_title = "INSERT INTO product ( id , product , cost , details , ) VALUES ( NULL , '$name' , '$cost' , '$details')"; if (!mysql_query($sql_title,$con)) { die('Error: ' . mysql_error()); } echo "records for product added<br />"; // Filter update // This is the array which is coming from the form /* Array ( [0] => ehiem [1] => Hagan [2] => Rena [3] => jobo ) Array ( [0] => img1.jpg [1] => img2.jpg [2] => img3.jpg [3] => img4.jpg ) */ $filtername = mysql_real_escape_string($filtername); $filterimgpath = mysql_real_escape_string($filterimg); $combined_array = array_combine($filtername, $filterimgpath); $values = array(); foreach ($combined_array as $filtername => $filterimgpath) { $values[] = "('$filtername', '$filterimgpath')"; } $sql = "INSERT INTO filter (filter , imgpath) VALUES " . implode(', ', $values); //echo $lastid = mysql_insert_id()."<br />"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "records added<br />"; //Product Filter Update table // This is where Im stuck. Not able to even think of anything.... // heater update // This is the array which is coming from the form /* Array ( [0] => ehiem [1] => Dolphin [2] => Rena [3] => jobo ) Array ( [0] => img1.jpg [1] => img2.jpg [2] => img3.jpg [3] => img4.jpg ) */ $heatername = mysql_real_escape_string($heatername); $heaterimgpath = mysql_real_escape_string($heaterimg); $combined_array = array_combine($heatername, $heaterimgpath); $values = array(); foreach ($combined_array as $heatername => $heaterimgpath) { $values[] = "('$heatername', '$heaterimgpath')"; } $sql = "INSERT INTO heater (heater , imgpath) VALUES " . implode(', ', $values); //echo $lastid = mysql_insert_id()."<br />"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "records added<br />"; //Product heater Update table // This is where Im stuck. Not able to even think of anything....
  9. Hi Guys, I need help for in storing data from PHP from array in mysql. I'm very new to PHP/Mysql and have started learing it just few weeks back. I'm tryting to build a website for myself. I'm having tough time trying to insert the data from Form in mysql. I have a form where user update the company name and insert there product name with there image. I want to rename the image with the corresponding text field value and insert the upload path in the table. my FORM <!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=utf-8" /> <title>Untitled Document</title> <style type="text/css"> body,td,th { color: #000; font-family: Tahoma, Geneva, sans-serif; font-size: 80%; } body { background-color: #9CF; } table { background: #CCF; } th { font: bold normal 16px/normal "Times New Roman", Times, serif; text-transform: capitalize; color: #00F; background: #FFC; } td { font: bold 14px Georgia, "Times New Roman", Times, serif; text-transform: capitalize; color: #3A00FF; background: #FF9; } </style> </head> <body> <form action="upload-file1.php" method="post" enctype="multipart/form-data" name="form"> <strong>Company Name:</strong> <input name="product" type="text" /> <br /> <table> <tr bgcolor="#FF9900"> <th colspan="3" bgcolor="#CCFFFF">filter </th> <th colspan="5" bgcolor="#CCFFFF">heater</th> </tr> <tr><td>filter1</td><td><input name="filter[]" type="text" id="filter"/> <td><input name="img_filter[]" type="file" /></td><td>heater1: </td> <td><input name="heater[]" type="text" id="heater"/></td> <td><input name="img_heater[]" type="file" /></td> </tr> <tr><td>filter2</td><td><input name="filter[]" type="text" id="filter"/> <td><input name="img_filter[]" type="file" /></td><td>heater2: </td> <td><input name="heater[]" type="text" id="heater"/></td> <td><input name="img_heater[]" type="file" /></td> </tr> <tr><td>filter3</td><td><input name="filter[]" type="text" id="filter"/> <td><input name="img_filter[]" type="file" /></td><td>heater3: </td> <td><input name="heater[]" type="text" id="heater"/></td> <td><input name="img_heater[]" type="file" /></td> </tr> <tr><td>filter4</td><td><input name="filter[]" type="text" id="filter"/> <td><input name="img_filter[]" type="file" /></td><td>heater4: </td> <td><input name="heater[]" type="text" id="heater"/></td> <td><input name="img_heater[]" type="file" /></td> </tr> <tr><td>filter5</td><td><input name="filter[]" type="text" id="filter"/> <td><input name="img_filter[]" type="file" /></td><td>heater5: </td> <td><input name="heater[]" type="text" id="heater"/></td> <td><input name="img_heater[]" type="file" /></td> </tr> </table> <br /> <br /> <input name="submit" type="submit" value="submit" /> </form> </body> </html> my PHP Code <?php require("connect.php"); ?> <?php $product = $_POST['product']; echo $product; if(isset($_POST["submit"])){ $sql = "INSERT INTO company (product) VALUES ('$product')"; $query = mysql_query($sql) OR DIE(mysql_error()); $comp_id = mysql_insert_id(); echo $sql; } ?> <?php function filter() { if(isset($_POST['submit'])) { foreach($_POST['filter'] as $key => $val) { if(trim($val) != '') $filter[] = $val; } $total_records_filter = count($filter); for($i = 0; $i < $total_records_filter; $i++) { $prod_val = $filter[$i]; $sql_prod = "INSERT INTO filter(filter_id, filter) VALUES('', '$prod_val')"; echo $sql_prod.'<br>'; mysql_query($sql_prod) OR die(mysql_error()); } } } filter(); function heater() { if(isset($_POST['submit'])) { foreach($_POST['heater'] as $key => $val) { if(trim($val) != '') $heater[] = $val; } $total_records_heater = count($heater); for($i = 0; $i < $total_records_heater; $i++) { $dir_val = $heater[$i]; $sql_dir = "INSERT INTO heater(heater_id, heater) VALUES('', '$dir_val')"; echo $sql_dir.'<br>'; mysql_query($sql_dir) OR die(mysql_error()); } } } heater(); ?> <?php mysql_close($link)?> My Table structure company comp_id int(5) PK product varchar(50) No filter filter_id int(5) PK filter varchar(25) No filter_path varchar(100) No heater heater_id int(5) PK heater varchar(25) No heater_path varchar(100) No company_filter id int(5) PK comp_id int(5) PK FK (From company table) filter_id int(5) PK FK (From filter table) company_heater id int(5) PK comp_id int(5) PK FK (From company table) heater_id int(5) PK FK (From heater table) Regards BW
  10. Really sorry about the post. I have put the wrong code I manage to insert query in Mysql database for a single file. How do I do it if I have to insert the array of names and there pics in database like from the HTML Form from my previous post. <?php require("connect.php"); ?> <?php // Variables $lecturer = $_POST['lecturer']; $name = $_FILES["lect_img"]["name"]; $type = $_FILES["lect_img"]["type"]; $size = $_FILES["lect_img"]["size"]; $tmp_name = $_FILES["lect_img"]["tmp_name"]; $error = $_FILES["lect_img"]["error"]; $filename = $lecturer .".jpeg"; $path = "upload/" . $filename; //echo $type . "<br />"; echo $lecturer . "<br />"; echo $path . "<br />"; if($type == "image/jpeg") { if($error > 0) { echo "Return Code:" . $error; } else { echo "You have successfully uploaded " . $name . " file" . "<br />"; if(file_exists("upload/" . $name)) { echo $name . "File already exists"; } else { move_uploaded_file($tmp_name, "upload/" . $filename); echo "File saved in upload/" . $filename . "<br />"; $qry = "INSERT INTO lecturer VALUES ('', '$lecturer', '$path')"; mysql_query($qry) or die('Error, query failed : ' . mysql_error()); } } } else { echo "Invalid file"; } ?> <?php mysql_close($conn); ?> <!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=utf-8" /> <title>lecturer details</title> <style type="text/css"> body { background-color: #ffc; } </style> </head> <body> <b> <h1>Enter new lecturer details :</h1> <form id="form1" name="form1" method="post" action="submit.php" enctype="multipart/form-data"> <p>Lecturer:<br /> <label for="lecturer"></label> <input name="lecturer" type="text" id="lecturer1" size="15" /> <label for="lect_img1"></label><input id="lect_img1" type="file" name="lect_img"><br /> <br /> <input name="submit" type="submit" id="send" value="submit"> </form> </b> </body> </html>
  11. Hi All, Need help. I have a form which collect the users information including image which are stored in the directory. I want to rename the image file to the name of the user and stores it relative path in SQL table so that when I retrieve user name it also retrieve the image of the user. My Table structure is as follow: id int(5) lecturer_name varchar(10) lecturer_img_path varchar(100) Below is the PHP and HTML code. PHP Code <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'test'; mysql_select_db($dbname)or die ('Error connecting to mysql'); ?> <?php if(isset($_POST['lecturer'])) { $lecturer = $_POST['lecturer']; $n = count($lecturer); $i = 0; echo "Your selected lecturer are \r\n" . "<ol>"; while ($i < $n) { if($lecturer[$i] == ""){ //do nothing $i++; }else{ echo "<li>{$lecturer[$i]}</li> \r\n"; $i++; } } echo "</ol>"; } ?> <?php mysql_close($conn); ?> HTML FORM <!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=utf-8" /> <title>lecturer details</title> <style type="text/css"> body { background-color: #ffc; } </style> </head> <body> <b> <h1>Enter new lecturer details :</h1> <form id="form1" name="form1" method="post" action="submit1.php"> <p>Lecturer:<br /> <label for="lecturer"></label> <input name="lecturer[]" type="text" id="lecturer1" size="15" /> <label for="lect_img1"></label><input id="lect_img1" type="file" name="lect_img[]"><br /> <input name="lecturer[]" type="text" id="lecturer2" size="15" /> <label for="lect_img2"></label><input id="lect_img2" type="file" name="lect_img[]"><br /> <input name="lecturer[]" type="text" id="lecturer3" size="15" /> <label for="lect_img3"></label><input id="lect_img3" type="file" name="lect_img[]"><br /> <input name="lecturer[]" type="text" id="lecturer4" size="15" /> <label for="lect_img4"></label><input id="lect_img4" type="file" name="lect_img[]"><br /> <input name="lecturer[]" type="text" id="lecturer5" size="15" /> <label for="lect_img5"></label><input id="lect_img5" type="file" name="lect_img[]"><br /> <input name="lecturer[]" type="text" id="lecturer6" size="15" /> <label for="lect_img6"></label><input id="lect_img6" type="file" name="lect_img[]"><br /> <br /> <input name="submit" type="submit" id="send" value="submit"> </form> </b> </body> </html>
  12. Hi All, Need help with PHP output from HTML form. I don’t know if I’m doing it correctly or not. I have a form which ask to input data and output values in different page. It has multiple input field for same value and its value is stored in an array. If I submit the form PHP is calculating the empty fields also. I don’t want it to display values if there is no input. Below is the PHP and HTML code of one field. PHP Code <?php if(isset($_POST['product'])) { $product = $_POST['product']; $n = count($product); $i = 0; echo "Your selected Products are \r\n" . "<ol>"; while ($i < $n) { echo "<li>{$product[$i]}</li> \r\n"; $i++; } echo "</ol>"; } ?> HTML FORM <!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=utf-8" /> <title>Product details</title> <style type="text/css"> body { background-color: #C9F; } </style> </head> <body> <b> <h1>Create new Product entry:</h1> <form id="form1" name="form1" method="post" action="submit1.php"> <p>Product:<br /> <label for="product"></label> <input name="product[]" type="text" id="product" size="15" /> <input name="product[]" type="text" id="product" size="15" /> <input name="product[]" type="text" id="product" size="15" /><br /> <input name="product[]" type="text" id="product" size="15" /> <input name="product[]" type="text" id="product" size="15" /> <input name="product[]" type="text" id="product" size="15" /> <br /> <input name="submit" type="submit" id="send" value="submit"> </form> </b> </body> </html>
×
×
  • 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.