Sylva
Members-
Posts
12 -
Joined
-
Last visited
Sylva's Achievements
Newbie (1/14)
0
Reputation
-
Show_Image.php
Sylva replied to tonye's topic in PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
Larry in terms of the getimagesize that is used for image which one can I use to validate other files like pdfs -
hello I m trying to write a script that gets an article from database and shows the article on the homepage and also at the left aside bar show titles of all the articles I have in the database. the scripts work when I separate them but when I include the list_article_imdex.php , I get this error : cannot redeclare error_handler() here's my scripts please help ?php ob_start(); session_start(); if(!isset($page_title)){ $page_title='Rancho-site.com'; } ?> <?php $_SESSION['counter']=0; if(isset($_SESSION['uid'])){ if(@$_SESSION['counter']==0){ $_SESSION['begin']=time(); $_SESSION['counter']=1; }else{ $_SESSION['counter']+=1; } $session_end=60; $session_duration=time()- $_SESSION['begin']; if($session_duration > $session_end){ require_once('includes/config3.inc.php'); $q="UPDATE users SET active = '0' WHERE user_id={$_SESSION['uid']}"; $r=mysqli_query($dbc,$q) or trigger_error("Query:$q</br>Error: ".mysqli_error($dbc)); if($r){ $_SESSION = array(); session_destroy(); setcookie (session_name(), '',time()-300); mysqli_close($dbc); ?> // <meta http-equiv="refresh" content="15;url=index.php" /> <?php } }else{ $_SESSION['begin']=time(); } } ?> <!DOCTYPE html> <html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.0.0.58475 --> <meta charset="utf-8"> <title><?php echo $page_title; ?></title> <meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width"> <!--[if lt IE 9]><script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]--> <link rel="stylesheet" href="style/style.css" media="screen"> <!--[if lte IE 7]><link rel="stylesheet" href="style/style.ie7.css" media="screen" /><![endif]--> <link rel="stylesheet" href="style/style.responsive.css" media="all"> <script src="style/jquery.js"></script> <script src="style/script.js"></script> <script src="style/script.responsive.js"></script> </head> <body> <div id="art-main"> <header class="art-header"> <div class="art-shapes"> </div> <h1 class="art-headline" data-left="2.82%"> <a href="#">Rancho-Solution.com</a> </h1> <h2 class="art-slogan" data-left="31.67%">Enter Site Slogan</h2> <div id="art-flash-area"> <div id="art-flash-container"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="1920" height="544" id="art-flash-object"> <param name="movie" value="style/images/flash.swf"> <param name="quality" value="high"> <param name="scale" value="exactfit"> <param name="wmode" value="transparent"> <param name="flashvars" value="color1=0xFFFFFF&alpha1=.50&framerate1=24&loop=true&wmode=transparent"> <param name="swfliveconnect" value="true"> <!--[if !IE]>--> <object type="application/x-shockwave-flash" data="style/images/flash.swf" width="1920" height="544"> <param name="quality" value="high"> <param name="scale" value="exactfit"> <param name="wmode" value="transparent"> <param name="flashvars" value="color1=0xFFFFFF&alpha1=.50&framerate1=24&loop=true&wmode=transparent"> <param name="swfliveconnect" value="true"> <!--<![endif]--> <div class="art-flash-alt"><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player"></a></div> <!--[if !IE]>--> </object> <!--<![endif]--> </object> </div> </div> </header> <nav class="art-nav"> <div class="art-nav-inner"> <ul class="art-hmenu"> <li><a href="index.php" class="<?php if(isset($page_title) && $page_title=='Rancho-site.com'){echo 'active'; }else{ echo ' ';} ?>">Home</a></li> <li><a href="download.html" class="<?php if(isset($page_title) && $page_title=='Download'){echo 'active'; }else{ echo ' ';} ?>">Download</a> <ul> <li><a href="download/ebooks.html">EBooks</a></li> <li><a href="download/scripts.html">Scripts</a></li> <li><a href="download/videos.html">Videos</a></li> <li><a href="download/applications.html">Applications</a> </li> </ul> </li> <li><a href="forum.html" class="<?php if(isset($page_title) && $page_title=='Rancho| Forum'){echo 'active'; }else{ echo ' ';} ?>">Forum</a></li> <li><a href="about-us.html" class="<?php if(isset($page_title) && $page_title=='About Us'){echo 'active'; }else{ echo ' ';} ?>">About Us</a></li> <li><a href="contact-us.html" class="<?php if(isset($page_title) && $page_title=='Contact us'){echo 'active'; }else{ echo ' ';} ?>">Contact Us</a></li> </ul> </div> </nav> <div class="art-sheet clearfix"> <div class="art-layout-wrapper"> <div class="art-content-layout"> <div class="art-content-layout-row"> <div class="art-layout-cell art-sidebar1"><div class="art-vmenublock clearfix"> <?php if(isset($_SESSION['uid'])){ echo"<p> </p> <p>WELCOME {$_SESSION['uname']}</p>"; } ?> <div class="art-vmenublockheader"> <h3 class="t">Navigation</h3> </div> <div class="art-vmenublockcontent"> <ul class="art-vmenu"> <?php if(isset($_SESSION['uid'])){ ?> <li><a href="logout.php" class="<?php if(isset($page_title) && $page_title=='Log out'){echo 'active'; }else{ echo ' ';} ?>">Logout</a></li> <li><a href="home.html" class="<?php if(isset($page_title) && $page_title=='View'){echo 'active'; }else{ echo ' ';} ?>">View</a></li> <li><a href="cpass.php" class="<?php if(isset($page_title) && $page_title=='Change Password'){echo 'active'; }else{ echo ' ';} ?>">Change Password</a> </li> '; <?php if ($_SESSION['user_level']==1){ ?> <div class="art-vmenublockheader"> <h3 class="t">Administrator Area</h3> </div> <li><a href="#" class="<?php if(isset($page_title) && $page_title=='Approve user'){echo 'active'; }else{ echo ' ';} ?>">approve</a></li> <li><a href="#" class="<?php if(isset($page_title) && $page_title=='List Users'){echo 'active'; }else{ echo ' ';} ?>">List users</a></li> <li><a href="add_article.php" class="<?php if(isset($page_title) && $page_title=='Post Article'){echo 'active'; }else{ echo ' ';} ?>">Post Article</a></li> <li><a href="add_author.php" class="<?php if(isset($page_title) && $page_title=='Add Authors'){echo 'active'; }else{ echo ' ';} ?>">Add Authors</a></li> <li><a href="view_authors.php" class="<?php if(isset($page_title) && $page_title=='View Authors'){echo 'active'; }else{ echo ' ';} ?>">View Authors</a></li> <li><a href="add_book.php" class="<?php if(isset($page_title) && $page_title=='Add Book'){echo 'active'; }else{ echo ' ';} ?>">Add Book</a></li> <?php }else{ ?> <li><a href="#">profile</a></li> <li><a href="#">profile</a></li> <li><a href="#">profile</a></li> <?php } }else{ ?> <li><a href="register.php" class="<?php if(isset($page_title) && $page_title=='Register'){echo 'active'; }else{ echo ' ';} ?>">Register</a></li> <li><a href="login.php" class="<?php if(isset($page_title) && $page_title=='Login'){echo 'active'; }else{ echo ' ';} ?>">Login</a></li> <li><a href="resetpass.php" class="<?php if(isset($page_title) && $page_title=='Forgot Password'){echo 'active'; }else{ echo ' ';} ?>">Forgot password?</a></li>'; <?php } ?> </ul> </div> </div><div class="art-block clearfix"> <div class="art-vmenublockheader"> <h3 class="t">Search</h3> </div> <div class="art-blockcontent"><div> <form action="#" class="art-search" method="get" name="searchform"> <input type="text" value="" name="s" /> <input type="submit" value="Search" name="search" class="art-search-button" /> </form> </div></div> </div><div class="art-block clearfix"> <div class="art-vmenublockheader"> <h3 class="t">Categories</h3> </div> <div class="art-blockcontent"><div> <p>Lorem ipsum dolor sit amet. Nam sit amet sem. Mauris a ante.</p> <ul> <li><a href="#" title="All News">All News</a> (50)</li> <li><a href="#" title="Best of the Year">Best of the Year</a> (4)</li> <li><a href="#" title="Hyperlink">Hyperlink</a> (24)</li> <li><a href="#" title="Visited link" class="visited">Visited link</a> (17)</li> <li><a href="#" title="Hovered link" class="hover">Hovered link</a> (6)</li> </ul> </div></div> </div><div class="art-block clearfix"> <div class="art-vmenublockheader"> <h3 class="t">Blogroll</h3> </div> <div class="art-blockcontent"><div> <ul> <li> <a href="#">My first blog</a> </li> <li> <a href="#">Who will prevail?</a> </li> <li> <a href="#">Stay positive!</a> </li> <li> <a href="#">Oil still going up</a> </li> <li> <a href="#">Gripes and Grins</a> </li> <li> <a href="#">2012 Olympics</a> </li> <li> <a href="#">How to SEO</a> </li> <li> <a href="#">On Global Warming</a> </li> <li> <a href="#">Can you guess?</a> </li> </ul> </div></div> </div><div class="art-block clearfix"> <div class="art-vmenublockheader"> <h3 class="t">Archive</h3> </div> <div class="art-blockcontent"><div> <ul> </ul> </div></div> </div></div> <div class="art-layout-cell art-content"><article class="art-post art-article"> <?php include(‘includes/list_article_index.php’); ?> <div class="art-postcontent art-postcontent-0 clearfix"> The article link <?php include('includes/config2.inc.php'); require_once(MYSQL); $q="SELECT article_id,title FROM article "; $r=mysqli_query($dbc,$q) or trigger_error("Query: $q </br>Error: ".mysqli_error($dbc)); if(mysqli_num_rows($r)>0){ while($row=mysqli_fetch_array($r,MYSQLI_ASSOC)){ echo'<li><a href="'.BASEURL.'show_article.php?aid='.$row['article_id'].'" title="'.$row['title'].'">'.$row['title'].'</a></li>'; } }else{ echo '<p>This article no longer exists</p>'; } mysqli_close($dbc); ?>
-
thanks Hartley for the quick feedback. I was wondering if I could use header function for the download script but instead of downloading the PDF it downloads the whole page. how can I limit it to just the PDF. 2. i was thinking of previewing the front cover of the PDF before download how can I do that? thanks for ur time
-
hello, I've been reading visual pro and have been building on it. I admit learning php with visual pro really helped me grasp most of the basics of php and I m thankful Larry for your efforts . I used the method in uploading files in the book to create a PDF uploading site but I need to add a download back my PDFs and if its possible to store the uploaded PDF to database or is it just the PDF name
-
yeah i ve read the book. and so i thought maybe the error was not with my codes but either my server or database since the yours works for you perfectly so i started afresh deleting the old database, backedup my sites then uninstalled wamp and reinstalled it. Then i recreated the database and tried it this time with that same code and it worked. it was painstaking but it was worth it. Thanks for everything.
-
here it is <?php $page_title='my dbase connect'; define ('DB_HOST','localhost'); define ('DB_USERNAME','root'); define ('DB_PASSWORD',''); define ('DB_NAME','sitename'); ?> <title><?php echo $page_title ;?></title> <?php //conecting to database $dbc=@mysqli_connect(DB_HOST,DB_USERNAME,DB_PASSWORD,DB_NAME) OR die('could not connect to server at this time: '.mysqli_connect_error()); $q='select first_name from user limit 3'; $result=mysqli_query($dbc,$q); echo $result; ?>
-
thanks for replying back at such short notice. here is the code i tried earlier. <?php # Script 8.3 - register.php $page_title = 'Register'; include ('/includes/header.html'); // Check if the form has been submitted: if (isset($_POST['submitted'])) { $errors = array(); // Initialize an error array. // Check for a first name: if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = trim($_POST['first_name']); } // Check for a last name: if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = trim($_POST['last_name']); } // Check for an email address: if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = trim($_POST['email']); } // Check for a password and match against the confirmed password: if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { $p = trim($_POST['pass1']); } } else { $errors[] = 'You forgot to enter your password.'; } if (empty($errors)) { // If everything's OK. // Register the user in the database... require_once('../mysqli_connect.php'); // Connect to the db. // Make the query: $q ="INSERT INTO user (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )" ; $r = @mysqli_query ($dbc, $q); // Run the query. if ($r) { // If it ran OK. // Print a message: echo '<h1>Thank you!</h1> <p>You are now registered. In Chapter 11 you will actually be able to log in!</p><p><br /></p>'; } else { // If it did not run OK. // Public message: echo '<h1>System Error</h1> <p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Debugging message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // End of if ($r) IF. mysqli_close($dbc); // Close the database connection. // Include the footer and quit the script: include ('/includes/footer.html'); exit(); } else { // Report the errors. echo '<h1>Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // End of if (empty($errors)) IF. } // End of the main Submit conditional. ?> <link href="includes/style.css" rel="stylesheet" type="text/css" /> <h1>Register</h1> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="20" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p> <p>Password: <input type="password" name="pass1" size="10" maxlength="20" /></p> <p>Confirm Password: <input type="password" name="pass2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('/includes/footer.html'); ?>
-
Good day, nice book! I ve been getting along fine with it up to chapter 8. At first i wrote the codes then cross checked it with yours and ran it after clicking register on my web browser i get this error: catchable fatal error: object of class mysqli_result could not be converted to string in c:\wamp\www\tutorials\mysqli_connect.php on line 17 i copied your script from the downloads and replaced my script but still same error dont know what to do. I checked my database to see if the name was included but nada. Pls help me. I m using wamp and my mysqli version is 5.5.20