PHP - Display Imagejpeg() In Middle Of Page
I'm calling the image page via ajax. Depending on what date is selected will be written to the image. However I'm getting header error on my main page. What would be the proper way to display the generated image to the user? Can I do it without saving it? // FETCH IMAGE & WRITE TEXT $img = imagecreatefromjpeg('balloon.jpg'); $white = imagecolorallocate($img, 255, 255, 255); $txt = "Hello World"; $font = "C:\Windows\Fonts\arial.ttf"; imagettftext($img, 24, 0, 5, 24, $white, $font, $txt); // OUTPUT IMAGE header('Content-type: image/jpeg'); imagejpeg($img); imagedestroy($jpg_image); // OR SAVE TO A FILE // THE LAST PARAMETER IS THE QUALITY FROM 0 to 100 // imagejpeg($img, "test.jpg", 100);
Similar TutorialsIs it possible to feed the browser a default save as name for the image when outputting to the browser, instead of it defaulting to the .php file name? So, instead of myimage.php I could use imagename.jpg or whatever I want. Hey, I'm having problems displaying data from a mysql database properly. Problem page: here It's a bit like a cms, a user fills out a form asking for a page title and the page content, thats then stored in the database and the finished result should be the page title added to the navigation and when clicked displaying the relevant page. I don't know if its possible but I'd like it to be done all on the one page. As you can see on the link I provided, when you click more than one link it displays it on the same page, rather than replacing itself. Can you help with this? Code: <html> <head> <script> function show_content(id){ document.getElementById(id).style.display='block'; } </script> </head> <body> <font face=verdana size=1> <?php include 'dbwire.php'; $query = mysql_query('SELECT * FROM content'); while($results = mysql_fetch_array($query,MYSQL_ASSOC)){ $title = $results['title']; $id = $results['id']; $content = $results['content']; echo "| <a href=\"javascript:void(0);\" onclick=\"show_content($id)\">$title</a> "; echo "<div id=\"$id\" style=\"display:none\">$content</div>"; } ?> <hr> </body> </html> Also, any idea how I should do the navigation? As you can see the more pages added the longer the navigation will get...eventually extending beyond the page width and creating problems. I understand I have problems explaining, if you need more just let me know! Thanks, Drew. it cant display the page i cant find the page i tryed to see whats wrong but it thing all brace and semicolos are were there suppose to be at it gives me a Server error Code: [Select] <?php if(isset($_POST['submitbtn'])){ //will open up the db connection include "../includes/connect.php"; $errors = ""; $welcometitle = mysql_real_escape_string($_POST['welcometitle']); $welcomesection = mysql_real_escape_string($_POST['welcomesection']); $infotitle = mysql_real_escape_string($_POST['infotitle']); $infosection = mysql_real_escape_string($_POST['infosection']); $videotitle = mysql_real_escape_string($_POST['videotitle']); $videosection = mysql_real_escape_string($_POST['videosection']); if(isset($welcometitle && $welcomesection)) && !empty($welcometitle && $welcomesection)){ if(isset($infotitle && $infosection)) && !empty($infotitle && $infosection)){ if(isset($videotitle && $videosection)) && !empty($videotitle && $videosection)){ //adding them to the db $query = mysql_query("UPDATE home SET `welcometitle`=`$welcometitle`,`welcomesection`=`$welcomesection`,`infotitle`=`$infotitle`, `infosection`=`$infosection`,`videotitle`=`$videosection`"); header("location: http://www.website.org/control/edithome"); }else{ $errors = "Please fill in the Video Section"; } }else{ $errors = "Please fill in the Info Section"; } }else{ $errors = "Please fill in the Welcome Section"; } mysql_close();//will close the inlcude db connection } ?> Hi, So I am currently making a real estate site for my class at school but I am having a tiny issue with the listing display page. So what I want to do is show a bunch of listing that the agent owns on their dashboard which I have already done. Now I have two links one to update the listing and one to view the listing. Now what I am trying to do is when the view listing link is clicked it will take the user to the listing-display page and then I want it to display all the information for the listing that the link was clicked under. But i cannot for the life of me figure out how to do that!
This is currently the code for the dashboard where you only view the listing headline <?php // If the session was never set with a user id $output = ''; $conn = db_connect(); if($_SESSION['userType'] != AGENT) { $_SESSION['RedirectError'] = "You were not logged in as an Agent<br/>"; header("Location:login.php"); } if (isset($_GET["page"])) { $page = $_GET["page"]; $index = ($page -1) * IMAGE_LIMIT; } else { $page=1; $index = 0; } ?> <!-- start of main page content --> <div class="container" style="margin-top: 2em;"> <h2>Dashboard</h2> <p>Welcome back <?php echo $_SESSION['userId']; ?> you last logged in on <?php echo $_SESSION['last_access']; ?></p> <h4>Your Listings</h4> <?php $sql = "SELECT listing_id FROM listings WHERE user_id = '".$_SESSION['userId']."' AND status = 'o' ORDER BY listing_id"; $result = pg_query($conn, $sql); $listings = pg_fetch_all($result); for($index; $index < pg_num_rows($result); $index++) { $sql = "SELECT * FROM listings WHERE listing_id = '".$listings[$index]['listing_id']."'"; $listing_result = pg_query($conn, $sql); $arrayRow = pg_fetch_assoc($listing_result); echo (build_listing_card($arrayRow)); if($index !=0 && ($index +1) % IMAGE_LIMIT ==0){ break; } } ?> </div> <br/> <?php $total_pages = ceil(count($listings) / IMAGE_LIMIT); $pageLink = "<div class='pagination'>"; for ($i=1; $i<=$total_pages; $i++) { if($i == $page) { $pageLink .= "<a class='active' href='dashboard.php?page=".$i."'>".$i."</a>"; } else { $pageLink .= "<a href='dashboard.php?page=".$i."'>".$i."</a>"; } }; ?> </div> <br/>
and this is the code for the listing-display page where I want all the listing information to be displayed <?php if (isset($_GET['listing_id'])) { $_SESSION['listing_id'] = $_GET['listing_id']; } else { $_SESSION['listing_id'] = 0; echo "ERROR: listing information was not find"; } $sql = 'SELECT * FROM listings WHERE listing_id = ' . $_SESSION['listing_id']; echo "<BR>".$sql; $result = pg_query(db_connect(), $sql); $records = pg_num_rows($result); echo "<BR>".pg_fetch_result($result, 0, "listing_id"); echo "<BR>".pg_fetch_result($result, 0, "user_id"); echo "<BR>".pg_fetch_result($result, 0, "status"); echo "<BR>".pg_fetch_result($result, 0, "price"); echo "<BR>".pg_fetch_result($result, 0, "headline"); echo "<BR>".pg_fetch_result($result, 0, "description"); echo "<BR>".pg_fetch_result($result, 0, "postal_code"); echo "<BR>".pg_fetch_result($result, 0, "images"); echo "<BR>".pg_fetch_result($result, 0, "city"); echo "<BR>".pg_fetch_result($result, 0, "property_options"); echo "<BR>".pg_fetch_result($result, 0, "bedrooms"); echo "<BR>".pg_fetch_result($result, 0, "bathrooms"); echo "<BR>".pg_fetch_result($result, 0, "garage"); echo "<BR>".pg_fetch_result($result, 0, "purchase_type"); echo "<BR>".pg_fetch_result($result, 0, "property_type"); echo "<BR>".pg_fetch_result($result, 0, "finished_basement"); echo "<BR>".pg_fetch_result($result, 0, "open_house"); echo "<BR>".pg_fetch_result($result, 0, "schools"); ?> <h1> Listing Display </h1> <hr/> <table style="width:50%" border="1px solid black"> <tr> <th>Listing Image</th> <th>Listing Description</th> </tr> <tr> <th rowspan="2"> <img src="" alt="Oshawa House" width="300px" height="200px"/> </th> <td align="left" valign="top"> <h3><?php echo pg_fetch_result($result, 0, "headline") ?></h3> <ul> <li>Open house?: <?php echo get_property('open_house', pg_fetch_result($result, 0, "open_house"))?> </li> <li>Finished Basement?: <?php echo get_property('finished_basement', pg_fetch_result($result, 0, "finished_basement"))?></li> <li><?php echo get_property('purchase_type', pg_fetch_result($result, 0, "purchase_type"))?></li> <li>Garage Type: <?php echo get_property('garage_type', pg_fetch_result($result, 0, "garage"))?></li> <li>Near school?: <?php echo get_property('schools', pg_fetch_result($result, 0, "schools"))?></li> <li>Status: <?php echo get_property('listing_status', strtolower(pg_fetch_result($result, 0, "status"))) ?></li> <li>Washrooms: <?php echo get_property('washrooms',pg_fetch_result($result, 0, "bathrooms")) ?></li> <li>Bedrooms: <?php echo get_property('bedrooms',pg_fetch_result($result, 0, "bedrooms")) ?></li> <li>Description: <?php echo pg_fetch_result($result, 0, "description") ?></li> </ul> </td> </tr> <tr> <td align="left" valign="top"><ul> <li>Location: <?php echo get_property('cities',pg_fetch_result($result, 0, "city")) ?></li> <li>Postal Code: <?php echo pg_fetch_result($result, 0, "postal_code") ?></li> <li>Price: <?php echo pg_fetch_result($result, 0, "price") ?></li> </ul> </td> </tr> </table> <form action="listing-matches.php"> <p> <input type="submit" name="submit" value="Back"/></p> </form>
Hi, I have a website which displays products on product display pages and static pages such as 'contact us'. I am now looking to add a search function which directs to the display page so the products are neatly presented. However, all the tutorials I can find are based on displaying the echo on same page as the search and directing the search to another page. Does anyone know how to do this? Most of the websites I have built have not been large and not dynamic in nature, but I need to make one now with a boatload of content on it. and I’m needing a little resource help where I can research something. I’m sure all developers do this, and I know I need a massive database or 2 and the PHP knowledge I already have, but I’m just looking for a little guidance about how to do this the easiest way. It may actually sound like a stupid question and I might be over-thinking a bit. So… Lets say I have 500 articles that I want to make available to a site visitor and give them the option to choose what they want to look at through nav menus and submenus. I want the same page to display to the user, regardless of what article is chosen. how does PHP play a part in that? Would I be right by saying the following? If the home page had this content on it: This website is a course in PHP coding. <a href="courseTemplate.php" target="_blank">Click here</a> to view course #1. and I wanted all the course content to be displayed through the use of the “courseTemplate.php” file, how simple is that? I would assume that these types of things would be the results and the techniques to accomplish the goal, right? => a resulting URL that looks like this: www.site.com/courseTemplate.php?id=1 => storing all the text of the course material in one single field of a DB record. NOT storing the layout-oriented code (HTML, etc.) and echoing it out with the rest of the text. => making use of the GET() function somehow to pull the course’s text content out of the database. Can someone show me a website that demonstrates this? I don’t think this is very difficult, and I’m sure there are web resources available that show how this is done. I’m almost sure that most news agency websites do this, and I know for a fact that most forum software has this template technique written into it, regardless if SEO is included or not. Sorry for the basic nature of this question. I know some of my previous posts have been such where I’ve asked much more difficult questions than this. I have seen youtube tutorials on issues similar to this, but nothing pulled up by google really shows this in a very simplistic nature. thanks. Hi, Wonder if someone could help with the problem below. Got a main page that includes a header, footer and a link to a database. I can get the two Includes to work but can't seem to display the database fields in the body of the page. What has me baffled is that it appears to be connecting to the database, (Opening the connection to the database server The connection worked. The link is: Resource id #3) but no text (see below for database text) is appearing on the screen. Yet I'm not getting a "page_not_found" message. I can go to the database in MYSQL console and query it successfully. Read and (hopefully) applied the section Debugging: A Beginner's Guide, but still can't see the problem. Any help greatly appreciated. Bren --------------------CODE FOR MAIN PAGE START------------------- <?php $page_name = $_REQUEST['name']; /*http://localhost/exemples/page.php?name=about_us*/ // Get the body of the page mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $sql = "SELECT * from pages WHERE name='$page_name'"; print "Opening the connection to the database server<br>"; $link = mysql_connect("localhost","root", ""); print "The connection worked. The link is: $link <br>"; /* --------------What is being selected from the database-------------- +----------+------------------------------------------------------------------------+ | name | body | +----------+------------------------------------------------------------------------+ | about_us | <h1>About Us</h1> ACME Toys has been established in 1850 to provide toys | to children all over the world +----------+------------------------------------------------------------------------+ 1 row in set (0.00 sec) ---------------------------------------------------------------------- */ $result = mysql_query($sql) or die(mysql_error() ); // If the page is not found, redirect to a static page if(mysql_num_rows($result) == 0 ) { header("Location: page_not_found.html"); } $row = mysql_fetch_assoc( $result ); $body = stripslashes( $row["body"] ); // Include the header include("c:/wamp/www/exemples/header.php"); // Print the body of the page echo $body; // Include the footer include("c:/wamp/www/exemples/footer.php"); ?> --------------------CODE FOR MAIN PAGE END------------------- I have been playing around with this. Thought I had it nailed, and then found that It was fubar when I started to add more entries to the database. I basically want to display 2 tables from my database on the page. One is called "players" the other is called "editlog". The output with my current script came out as this: and here is the dreaded code: <html> <body> <u><h3>Performance Point Monitor (PPM): Knights of Shadow WoW Officers.</h3></u> <?php include('/home/a3269923/public_html/ppm/admin/config.php'); include('/home/a3269923/public_html/ppm/admin/dbopen.php'); $query="SELECT * FROM players"; $result=mysql_query($query); $num=mysql_numrows($result); ?> <table border="1" style="position:absolute;width:500;height:10;left:0;top:70"> <tr> <th><font face="Arial, Helvetica, sans-serif">PLAYER</font></th> <th><font face="Arial, Helvetica, sans-serif">POINTS</font></th> <th><font face="Arial, Helvetica, sans-serif">DATE</font></th> </tr> <?php $i=0; while ($i < $num) { $f2=mysql_result($result,$i,"PLAYER_NAME"); $f3=mysql_result($result,$i,"ND_POINTS"); $f4=mysql_result($result,$i,"DATE ADDED"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td> </tr> </table> <?php $i++; } ?> <?php include('/home/a3269923/public_html/ppm/admin/config.php'); include('/home/a3269923/public_html/ppm/admin/dbopen.php'); //USER LOG $query="SELECT * FROM editlog"; $result=mysql_query($query); $num=mysql_numrows($result); ?> <table border="1" style="position:absolute;width:600;height:10;left:510;top:70"> <tr> <th><font face="Arial, Helvetica, sans-serif">USER</font></th> <th><font face="Arial, Helvetica, sans-serif">TYPE</font></th> <th><font face="Arial, Helvetica, sans-serif">POINTS</font></th> <th><font face="Arial, Helvetica, sans-serif">NOTES</font></th> <th><font face="Arial, Helvetica, sans-serif">DATE</font></th> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"USER"); $f2=mysql_result($result,$i,"TYPE"); $f3=mysql_result($result,$i,"POINTS"); $f4=mysql_result($result,$i,"NOTE"); $f5=mysql_result($result,$i,"TIMESTAMP"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td> </tr> </table> <?php $i++; } ?> What am I doing wrong? Halp! Hi, i have a folder with thumbnails and original big pictures of the thumbnails, i wanna make it so that the max amount of thumbs that can be displayed on one page would be 3 Code: [Select] <body> <div id=head></div> <div id=main> <?php include("loadimages.php") ?> //<- here i take all the thumbnails that are in my thumb folder </div> <div id=foot></div> </body> i have 5 thumbnails, it displays all of them in the "main" div, i wanna add an "Next" and "Previous" buttons, i mean, i want it to show only 3 thumbs at one time, once u click "next" it would remove the first 3 thumbs and load the other 2 thumbnails.. heres a pic maybe it will explain better of what im trying to do.. Hi, I am a newbie to this forum and php as well. I have a script which inserts data and image file into mysql database. Now I want to display this image on web page but unable to do it. I tried a lot but couldn't find out any solution. I would appreciate your help. <?php $con = mysql_connect("localhost", "root", "xx"); if(!$con) { die('Could not connect:' .mysql_error()); } mysql_select_db("yyy",$con); $memberid = '$_POST[memberid]'; $fname = '$_POST[fname]'; $lname = '$_POST[lname]'; $gender= '$_POST[gender]'; $add1 = '$_POST[add1]'; $add2 = '$_POST[add2]'; $city = '$_POST[city]'; $state = '$_POST[state]'; $zip = '$_POST[zip]'; $country = '$_POST[country]'; $photo1 = '$_FILES[image][name]'; echo "$photo1"; //if ($memberid= $_GET['memberid']){ $query="select memberid,fname,lname,gender,add1,add2,city,state,zip,country,photo1 from vadhuvar_member where memberid =(select max(memberid)from vadhuvar_member)"; $result=mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $memberid = $row['memberid']; $fname = $row['fname']; $lname = $row['lname']; $gender = $row['gender']; $add1 = $row['add1']; $add2 = $row['add2']; $city = $row['city']; $state = $row['state']; $zip = $row['zip']; $country = $row['country']; //$photo1=chunk_split(base64_encode($photo1)); $photo1 = $row['photo1']; //echo base64_encode($photo1); echo "Name:$fname $lname<br>"; //echo "Name:$_POST[fname]$_POST[lname]<br>"; echo "Gender:$gender<br>"; echo "Address:$add1 $add2<br>"; echo "$city $state $zip<br>"; echo "$country<br>"; //echo "<img src=".upload/$photo1 ." alt="" width="200" height="300" /><br />"; } //} ?> <!--img src="<?php echo '.upload/$_FILES[image][name]?memberid=$row[memberid]'?>"alt="" width="200" height="300"/-->; <?php echo "<img src=". upload/$row[photo1]" alt="" width="200" height="300">";?> <!--img src="<?php echo ".\upload\$photo1" ?>" alt="" width="200" height="300"/-->; <? set_magic_quotes_runtime(1); // turn back on ?> Thanks Smita Hi All,
So phpMyAdmin can generate quite nice graphs, and I was wondering if it is possible to have these graphs pull through into a PHP page?
Hi,
I'm trying to display a message first before redirect to other page, but my code just directly redirect the page without display the message.please help me.
if($num_rows == 0) { echo '<script type="text/javascript">alert("Please Enter Correct Details!");</script>'; header ('Location :login.php'); } Ok when I run this code is displays nothing but a white page.. No error or anything. I have commented the first two segments of code the rest should be self explainable. Ok my beauty of a script: Any help to improve and or modify would be great as well as helping with the problem at hand. Code: [Select] <?php include("secure/database.php"); // Include Database Connection File... $q = "SELECT * FROM `accountinfo_org` ORDER BY `strikeaction` ASC";//Select all from account table order by strike action ascending . $res = mysql_query($q) or die(mysql_error()); // Query $count = mysql_num_rows($res); // Count for($i=1;$i>=$count;$i++){// For loop while($player=mysql_fetch_array($res)){ // While Loop $id = securevar($player['id']); // ID $user = securevar($player['username']); // Username $q = "UPDATE `accountinfo_org` SET `strikerank` = '$i' WHERE `id` = '$id'"; // Update account set strike action equals $i where account is account. $res = mysql_query($q) or die(mysql_error()); // Get Query if(isset($res)){ // if isset result from query. echo "Strike Rank set to $user as ".number_format($i)."!"; // Echo This. } } } $q = "SELECT * FROM `accountinfo_org` ORDER BY `defenceaction` ASC"; // Select all from table order by defenceaction ascending. $res = mysql_query($q) or die(mysql_error()); $count = mysql_num_rows($res); for($i=1;$i>=$count;$i++){ while($player=mysql_fetch_array($res)){ $id = securevar($player['id']); $user = securevar($player['username']); $q = "UPDATE `accountinfo_db` SET `defencerank` = '$i' WHERE `id` = '$id'"; $res = mysql_query($q) or die(mysql_error()); if(isset($res)){ echo "Defence Rank set to $user as ".number_format($i)."!"; } } } $q = "SELECT * FROM `accountinfo_org` ORDER BY `covertaction` AND `anticovertaction` ASC"; $res = mysql_query($q) or die(mysql_error()); $count = mysql_num_rows($res); for($i=1;$i>=$count;$i++){ while($player=mysql_fetch_array($res)){ $id = securevar($player['id']); $user = securevar($player['username']); $q = "UPDATE `accountinfo_db` SET `covertrank` = '$i' WHERE `id` = '$id'"; $res = mysql_query($q) or die(mysql_error()); if(isset($res)){ echo "Covert & Anti Covert Rank set to $user as ".number_format($i)."!"; } } } $q = "SELECT * FROM `accountinfo_org` ORDER BY `msaction` ASC"; $res = mysql_query($q) or die(mysql_error()); $count = mysql_num_rows($res); for($i=1;$i>=$count;$i++){ while($player=mysql_fetch_array($res)){ $id = securevar($player['id']); $user = securevar($player['username']); $q = "UPDATE `accountinfo_db` SET `msrank` = '$i' WHERE `id` = '$id'"; $res = mysql_query($q) or die(mysql_error()); if(isset($res)){ echo "Mothership Rank set to $user as ".number_format($i)."!"; } } } $q = "SELECT * FROM `accountinfo_org` ORDER BY `msaction` AND `strikeaction` AND `defenceaction` AND `covertaction` AND `anticovertaction` AND `msaction` ASC"; $res = mysql_query($q) or die(mysql_error()); $count = mysql_num_rows($res); for($i=1;$i>=$count;$i++){ while($player=mysql_fetch_array($res)){ $id = securevar($player['id']); $user = securevar($player['username']); $time = time(); $q = "UPDATE `accountinfo_db` SET `rank` = '$i', `lastTurnTime` = '$time' WHERE `id` = '$id'"; $res = mysql_query($q) or die(mysql_error()); if(isset($res)){ echo "Overall Rank set to $user as ".number_format($i)."!"; } } } ?> Brian Hello all. I am using an API from jambase.com to display events on a php page. Everything works great, the xml file is read and the data is displayed on the page as it should. My only problem is that when the data is displayed there is always a blank area where the first record of data should go. Any ideas how to get rid of this? http://www.wddclients.com/mag33/events_search.php (artist search field not enabled yet) Hopefully this is something pretty minor but if anyone wants to see specific code I can supply that. Thanks so much for all help! is it possible to disable warnings on a specific page? php.ini set to show warnings Hello every one I need Ur Help... In mY site i have one page which name is invoice.php,but when i click a link in invoice.php,one page is generated which name is make invoice.php, but i want makeinvoice.php page should display as pdf..... Please Help me..... Thanks In Advance Hello all. I'm using this code to go through the database and output certain user-defined numbers Code: [Select] <?php mysql_connect ("pdb1.awardspace.com", "anastasov_db","moscow1945") or die (mysql_error()); mysql_select_db ("anastasov_db"); $term = $_POST['term']; $sql = mysql_query("select * FROM countries WHERE cocode = '$term'"); while ($row = mysql_fetch_array($sql)){ echo '<br/> Code: '.$row['cocode']; echo '<br/> Country: '.$row['coname']; echo '<br/><br/>'; } ?> Now how would I go about making a page that appears if the script can't find any results in the database? Thank you in advance |