PHP - Link Within Document Causing Top Of The Page To Disappear
Ok, I've spent a good part of the day trying to figure out what is going wrong with a client site. I introduced a link within document to send readers from the blogs home page to the comments section of individual posts. It's straight forward right? HTML1, been doing these kind of links for more than ten years.
#respond at the end of the normal URL in a normal anchor tag should bring the browser to id="respond" or name="respond" within the document. Right? But, a.) it doesn't. And b.) once it makes a jump everything above that point disappears. Space fills out to the same page height as if it existed but you can't scroll up. You can see it in action at http://www.thebouncingbead.com/blog/ by clicking "Add Your Comment (0)" under the title of any post. Can anyone see what might be causing this problem or experienced something similar before? Similar TutorialsHere is a link to screenshots of what is happening, because I'm crappy at describing things: http://imgur.com/a/ahvPA Of course I've messed the code up somewhere, but I can't for the life of me figure out where. I have a simple page for someone to enter text in a textbox to save in a database to display on another page. There are 10 textboxes on the page. I can enter text into any and all textboxes and it'll save the data in the database, EXCEPT if I enter text into the 2nd textbox. If there's anything in the 2nd textbox after I click submit, it will delete whatever was in the 2nd textbox and move all data in each textbox (except textbox 1, which stays in the same place) down one element. And it pushes the data in the final textbox off the page (presumably because there's no other textbox to accept its data). Here is the code to the two pages affected. Any help would be appreciated! Code: [Select] <?php // start the session session_start(); if (!session_is_registered($_SESSION['myusername'])) { header ('location:./login.php'); } $i=1; require_once('./dbconnect.php'); $sql="SELECT `event` FROM `events`"; $result=mysql_query($sql); mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Admin Portal</title> </head> <body> <form name="events" method="post" action="eventlogging.php"> <table width="800" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td> <table width="100%" border="0" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td colspan="3" bgcolor="#CCCCCC"> <strong><p><strong>Admin Portal</strong></p><p align="right"><small><a href="./logout.php">Logout</a></small> </td> </tr> <?php while ($i<11) { echo ' <tr align="center"> <td align="right" width="100">Event ' . $i . ' </td> <td width="800"> <textarea name=event' . $i . ' cols=40 rows=5>'; $row = mysql_fetch_array($result); if ($row) { $msg=$row[0]; echo $msg; }; $i++; echo '</textarea> </td> </tr> '; } ?> <tr> <td colspan="2"> <center><input type="submit" name="Submit" value="Submit" /></center> <input type="hidden" name="submitted" value="true" /> </td> </tr> </td> </tr> </table> </td> </tr> </table> </form> </body> </html> <?php $position = 1; $dbControl = 9; $event = array(); if (!empty($_POST['event1'])) { $event[] = $_POST['event1']; } if (!empty($_POST['event2'])) { $event[] = $_POST['event']; } if (!empty($_POST['event2'])) { $event[] = $_POST['event']; } if (!empty($_POST['event3'])) { $event[] = $_POST['event3']; } if (!empty($_POST['event4'])) { $event[] = $_POST['event4']; } if (!empty($_POST['event5'])) { $event[] = $_POST['event5']; } if (!empty($_POST['event6'])) { $event[] = $_POST['event6']; } if (!empty($_POST['event7'])) { $event[] = $_POST['event7']; } if (!empty($_POST['event8'])) { $event[] = $_POST['event8']; } if (!empty($_POST['event9'])) { $event[] = $_POST['event9']; } if (!empty($_POST['event10'])) { $event[] = $_POST['event10']; } include ('./dbconnect.php'); mysql_query("DELETE FROM `events`"); foreach ($event as $msg) { mysql_query("INSERT INTO `events` (`position`, `event`, `date`) VALUES ('$position', '$msg', curdate() )") or die(mysql_error()); $position++; } mysql_close(); $position=1; /* foreach ($event as $msg) { echo $position . '. ' . $msg . '<br />'; $position++; } */ header("location:./admin.php"); ?> Hello folks, well what I mean by temporary variables are variables like error messages or success messages that appear after a form has been submitted. I want to be able to kill these variables when the page is refreshed and return the page to its defualt state. For example, I'm making this simple page which is basically a form that ask users for some information, then upon submit, stores the in a database and prints a success message. If the form is filled out incorrectly or some form fields are left blank, then error messages are printed. What I really want is for these messages to disappear when the page is refreshed. My current model uses a second page to handle the form, and then upon succes or upon encountering an error, redirects to the form page, passing the error or success variables via the url to the form page where they are printed out. What can I do differently to achieve what I want (ie kill variables upon page refresh)? Below are the form page, and the page that handles the form respectively. Code: [Select] <form method="post" action="send_email.php"> <div id="contact_form"> <div align="left" class="green18">Contact Us</div> <br/> <br/> <label>Your Name:</label> <input class="texta" name ="name" size="20" maxlength="49"/> <br/> <br/> <div class ="error" style="position:relative;bottom:40px;left:128px" > <?php //Retrieve the encoded errors string from send_email.php page $errors_string=$_GET['errors_string']; //Explode the decoded errors string back to an array. $errors = explode(",", $errors_string); echo $errors[0];?> </div> <label>Your Company Name:</label> <input class="texta" name ="company" size="30" maxlength="66"/> <br/> <br/> <div class ="error" style="position:relative;bottom:40px;left:128px" > <?php //Retrieve the encoded errors string from send_email.php page $errors_string=$_GET['errors_string']; //Explode the decoded errors string back to an array. $errors = explode(",", $errors_string); echo $errors[1];?> </div> <label>Subject(Optional):</label> <input class="texta" name ="subject" size="20" maxlength="49"/> <br/> <br/> <label>Email:</label> <input class="texta" name ="email" size="20" maxlength="49"/> <br/> <br/> <div class ="error" style="position:relative;bottom:40px;left:128px" > <?php //Retrieve the encoded errors string from send_email.php page $errors_string=$_GET['errors_string']; //Explode the decoded errors string back to an array. $errors = explode(",", $errors_string); echo $errors[2];?> </div> <label>Message:</label> <textarea style="float:left" class="" name ="message" cols="40" rows="3"> </textarea> <br/> <br/> <div class ="error" style="position:relative;bottom:-19px;left:-260px" > <?php //Retrieve the encoded errors string from send_email.php page $errors_string=$_GET['errors_string']; //Explode the decoded errors string back to an array. $errors = explode(",", $errors_string); echo $errors[3];?> </div> <button class="button" type ="submit" name ="submit">Submit</button> <br/> <div id ="sent" > <?php //Retrieve the user id from send_email.php page $sent=$_GET['sent']; $send_msg = urldecode($sent); echo $send_msg; ?> </div> <!--closes sent--> </div> </form> Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); if (isset($_POST['submit'])) { $errors = array(); // Connect to the database. require('config/config.php'); //Check for errors. //Check to make sure they entered their name and it's of the right format. if (eregi ("^([[:alpha:]]|-|')+$", $_POST['name'])) { $a = TRUE; } else { $a = FALSE; $errors[0] = '*Please enter a valid name.'; } //Check to make sure they entered their company name. if (!empty ( $_POST['company'])) { $b = TRUE; } else { $b = FALSE; $errors[1] = '*Please enter company name.'; } //Check to make sure email is valid. if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) { $c = TRUE; }else { $c = FALSE; $errors[2] = '*Please enter a valid email address.'; } //Check to make sure they entered their message. if (!empty ( $_POST['message'])) { $d = TRUE; } else { $d = FALSE; $errors[3] = '*Please enter your message.'; } //If no errors if (empty($errors)) { //Create variables for all the post values. $name = $_POST['name']; $company = $_POST['company']; $email = $_POST['email']; $message = $_POST['message']; $ip = $_SERVER[REMOTE_ADDR]; $date = (date("Y/m/d:G:i:s")); $timestamp = ( mktime(date(H), date(i), date(s), date(m) , date(d) , date(Y))); //Formulate the insert query. $query = "INSERT INTO emails ( email_id, name, company, email, message, ip, date,timestamp) VALUES ( 0, '$name','$company','email', '$message', '$ip' , '$date', '$timestamp' )"; $result = mysql_query($query) or die("Data could not be inserted into table because: " .mysql_error()); if (mysql_affected_rows() == 1) { // Display success message $sent_msg = "Your email has been sent. We will get back to you shortly."; $sent = urlencode($sent_msg); // Display contact page header("Location: contact_page.php?sent=$sent"); exit(); }else{die("There was a problem: " . mysql_error());} //Display error messages. } else {// if errors array is not empty //Confer the errors array into a string $errors_string = implode(",", $errors); //Encode the imploded string. $error_message = urlencode($errors_string); // Display page header("Location: contact_page.php?errors_string=$errors_string"); exit(); }//End of if there are errors. }//End of if submit. ?> Also, another problem I just noticed is that, the errors[3] variable isn't getting passed back to the form page. I don't know if it's because the url can only pass so much info to a second page. The page in question can be located he http://creativewizz.com/contact_page.php Hello.
I have a bit of a problem. When I fetch the link field from the database.i don't see an actual link on the page.
One more thing, what type of field should I use to store the link in the database? Probably there is where I went wrong.
All help is
Hi guys, I have created a php script (with alot of help from others) that allows me to have a login area on my website. When the user logs onto their page - they obviously cannot see the others profile. My next task is to be able to upload PDF documents to appear on their profiles. The PDF's will be specific to them. The main problems I have a 1/ They cannot be able to view any PDF but their own. 2/ How do I create a form that knows where to send and display the link? I guess it is using the user id & name etc? I will not actually be the one uploading the files else I would just sit and tediously link each form to each profile. This must be done by my secretary via a file upload form that I will password protect. I basically want her to be able to log in and be presented with a document upload form. The form will have a dropdown list of the clients name and a document upload part. From uploading it will then appear on the users page. If anyone could help it would be amazing! I am fairly new to PHP although am getting better with my understanding. Hopefully I will become as good as you lot one day! Cheers in advance Hi, Is it possible to build a PHP Template page that selects and publishes a row of data from a MySQL Database when a linked is clicked? I would design: Template.php Text links (perhaps on homepage of navigation bar): ProductA, ProductB and ProductC If you click link ProductA Template.php would display data for ProductA and likewise for ProductB and ProductC. I would also like search engines for find ProductA, ProductB and ProductC PHP pages. (Not just my single Template.php) Any ideas as to how this could be done without designing individual PHP pages for each product? Kind regards, Matthew. With some great forum help my nav menu shows nav options in the main menu, and when the user logs-in, it lines up additional menu choices all on a horizontal line. The issue I'd like to fix is to make the "log-in" menu choice disappear when the user is logged-in. If you can overlook all the font tags, in the code below, I'd greatly appreciate any help. Code: [Select] <!--Begin Sub-Navigation. This only appears when a user is logged in.--> <div class="sub-nav"> <img src="themes/default/images/arrow-red.gif"> <a href="members/[var.user_name]"><font color="#333333" face="verdana">my account</font></a> <img src="themes/default/images/arrow-red.gif"> <a href="credits.php"><font color="#333333" face="verdana">[var.lang_my_credits]: [var.member_credits]</font></a> <img src="themes/default/images/arrow-red.gif"> <a href="logout.php"><font color="#000000" face="verdana">log out</font></a> <!--[onload;block=div;when [var.loggedin]=1;comm]--> </div> <!--Begin Sub-Navigation. This only appears when a user is logged in.--> <div class="sub-nav1"> <p class="account"> <span id="welc"><span style="color:#333333; font-size: 12px; font-face=verdana;"> Welcome! You Are Now Logged In.</span></p> <!--[onload;block=div;when [var.loggedin]=1;comm]--> </div> <div class="menu1"> <a href="[var.base_url]"> <font color="#333333" font face="verdana">home</font></a> <a href="page.php?page=16"><font color="#333333" face="verdana">faq</font></a> <a href="[var.base_url]/join.php"><font color="#333333" face="verdana">register</font></a> <a href="[var.login_out_link]"><font color="#333333" face="verdana">log in</font></a> <a href="page.php?page=9"><font color="#333333" face="verdana">search</font></a> <a href="page.php?page=6"><font color="#333333" face="verdana">upload</font></a> </div> Code: [Select] .menu1 { font-size: 11px; font-family: verdana; text-align: right; float: right; color: #333333; margin: 0px 5px 0px 0px; padding: 0px 0px 0px 0px; } .sub-nav { font-size: 11px; font-family: verdana; text-align: right; color: #333333; margin: 0px 22px 0px 0px; padding: 0px 0px 0px 0px; } .sub-nav-links { color: #; font-size: 14px; margin: 0px 0px -20px 0px; } .sub-nav1 { font-size: 11px; font-family: verdana; text-align: right; float: left; color: #333333; margin: 0px 22px 0px 0px; padding: 0px 0px 0px 0px; } .sub-nav {float:right} .sub-nav1 p { margin:0 font-size: 11px; font-family: verdana; color: #333333; } #welc{ float left; } .account font-size: 11px; font-family: arial; color: #333333; } This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=358408.0 Hi all, I have a problem I am not sure how to sort, hopefully someone here can help. I have a sliding login panel on a website that I am making. Its quite discreet. I have a stripped down version here that you can see: http://mgdesign.hostultra.com/login_test/login_test.php On the page I am making, users with a log in enter their details and will be taken to the restricted page. I would like this sliding panel to be on every page when the user is not logged in. Once they log in from the sliding panel they can still surf around all the main site pages. When they log out the session dies and it reverts to the home page. However, when they are logged in I would like the sliding login panel to disappear from the top of each page. Is there any way I can do this simply? Any help or advice would be greatly appreciated. When I asked how to make this Log In Form disappear once it performs it's function:
<form action="../login.php" method="post" accept-charset="UTF-8" class="middletext" onsubmit="javascript:this.style.display='none';"> <p> <input type="text" size="20" name="user_name_login" id="user_name_login" value="ENTER USERNAME" style="color:#D9D9D9" style="vertical-align:middle"; onfocus="if (this.value=='ENTER USERNAME') {this.value=''; this.style.color='#696969';}" > <input type="text" size="20" name="password_login" id="password_login" value="ENTER PASSWORD" style="color:#D9D9D9" style="vertical-align:middle"; onfocus="if (this.value=='ENTER PASSWORD') {this.value=''; this.style.color='#696969';}" > <input type="hidden" name="cookie_time" value="10080" /> <img src="../themes/default/images/arrow-red.png" alt="" /><input type="submit" style="outline:grey" font-size="5px" value="[var.lang_login_now]" class="button-form2" /> <input type="hidden" name="submitted" value="yes" /> <input type="hidden" name="remember_me" value="remember_me" /> </p> </form> </div> <!--Begin Sub-Navigation. This only appears when a user is logged in.--> <div class="container1"> <div class="menu1"> <div class="sub-nav"><a href="../index.php"></a> <img src="../themes/default/images/arrow-red.jpg" style="vertical-align:middle" alt="" /><a href="../members/[var.user_name]"> my account</a><img src="../themes/default/images/arrow- red.jpg" style="vertical-align:middle" alt="" /> <a href="../credits.php">[var.lang_my_credits]: [var.member_credits]</font></a><img src="../themes/default/images/arrow-red.jpg" style="vertical-align:middle"><a href="../logout.php">[var.login_out]</a> <!--[onload;block=div;when [var.loggedin]=1;comm]--> </div>I was given this line of code: if($_SESSION['loggedin'] == true){ //dont show form } else { //show form }But I don't know how/where to integrate it into the Form. Any help will be appreciated. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=343671.0 I'm just learning about PHP and I'm diving in head first by attempting to modify our web site's contact form. I'm wishing to stop the form from erasing previously entered values upon "failed" data validation. It's of course going to be annoying to our visitors if their hardworked entries disappear just because they left out a name or entered an illegal email address. I regret that some potential solutions found on this forum and other locations on Google didn't seem to help on my page. As you can see, the validation is done with PHP's version of if-elseif-else. Later I'll be adding a reCAPTCHA and I hope that whatever I learn here might be useful for the potentially same problem when I am adding the CAPTCHA. The actual contact form is at http://www.woofwoofwoof.org/contact/index.php. Thank you in advance for your taking the time to help me what originally appeared to be a simple problem. I have read the rules and I hope I've followed the rules -- please let me know if I committed any sins of omission or commission. Now, for your Sunday reading pleasure, here's the code: CODE STARTS HERE ==================================== <?php include("../common/docType.php"); ?> <?php include("../common/htmlOpen.php"); ?> <head> <title><?php include("../common/titleBar.php"); ?> - Contact us!</title> <meta name="description" content="Call or email us with questions or orders."> <meta name="keywords" content="Barking Dog Chocolatiers, Charlotte NC, chocolate, contact us, telephone, email, e-mail"> <meta name="geo.placename" content="Charlotte, North Carolina"> <meta name="geo.region" content="US-NC"> <meta name="author" content="Joal Fischer"> <meta name="verify-v1" content="1aqZs7xrrfI3lp1RaWDkHHjY9UQZIbq2z/mIVdFeXiI=" /> <?php include("../common/headInclude.php"); ?> <script src="../common/common.js" type="text/javascript"></script> <link rel="Stylesheet" href="../css/contact.css" /> </head> <?php // Success/Fail message $msg = ""; $brisket = ""; // Target Email $targetEmail = "barkingdog@bellsouth.net"; // Process Submissions if(isset($_POST['submitted'])) { if($_POST['submitted']) { // process form. $guestName = $_POST['guestName']; $cityState = $_POST['cityState']; $emailAddress = $_POST['emailAddress']; $phone = $_POST['phone']; $msgSubject = "Barking Dog Chocolatiers Inquiry"; $msgContent = "FROM: $guestName\n"; $msgContent .= "City/State: $cityState\n"; $msgContent .= "Phone & time to call: $phone\n"; $msgContent .= "\nInquiry:\n"; $msgContent .= stripslashes($_POST['msgContent']); // Trial if then else reversed from Dan's original allowing maybe multiple tests in sequence -- in action if($guestName == "") { $keepvar = "1"; $msg = "<p style='color: red; font-weight: bold; font-size: 14px; margin: 12px 0px 0px 0px;'>Please enter a name!</p>"; } elseif($emailAddress == "") { $msg = "<p style='color: red; font-weight: bold; font-size: 14px; margin: 12px 0px 0px 0px;'>Please enter a valid email address!</p>"; } else { mail($targetEmail, $msgSubject, $msgContent, "From: $guestName <$emailAddress>\nX-Mailer:PHP/" . phpversion()); $msg = "<p style='color: darkgreen; font-weight: bold; font-size: 14px; margin: 12px 0px 0px 0px;'>Thank you! Your message has been sent.</p>"; $brisket = "<img src='../images/Brisket180x180web.jpg' width='180px' height='180px' alt='Brisket Says Hi' />"; } // Original if then else all commented out // if($emailAddress != "") { // mail($targetEmail, $msgSubject, $msgContent, "From: $guestName <$emailAddress>\nX-Mailer:PHP/" . phpversion()); // $msg = "<p style='color: darkgreen; font-weight: bold; font-size: 14px; margin: 12px 0px 0px 0px;'>Thank you! Your message has been sent.</p>"; // $brisket = "<img src='../images/Brisket180x180web.jpg' width='180px' height='180px' alt='Brisket Says Hi' />"; // } else { // $msg = "<p style='color: red; font-weight: bold; font-size: 14px; margin: 12px 0px 0px 0px;'>Please enter a valid email address!</p>"; // } } } ?> <body onload="loadMe('contact')"> <div id="container"> <div id="header"> <a href="../home/index.php" style="border:none"><div id="logo"></div></a> <div id="navBG"><?php include("../common/mainNav.php"); ?></div> </div><!--End Header--> <div id="contentArea"> <br /><img class="sideBox" src="../images/sideBox.jpg" width="12px" height="12px"><p class="sideItemSelected">contact us</p><br style="clear:both" /> <p class="sideItem"><a class="sideLink" href="./shipping.php">useful q & a</a></p> <div id="mainContent"> <h1>contact us</h1><br /> <h2>Have questions? Ready to order?<br /> <span style="color:#b5a072">Call 704.333.1595 Mon-Fri 9am - 5pm EST</span></h2> <p id="contactText" class="text">It's not business, it's personal! For instant answers to many questions about ordering, shipping, and other good stuff, please check the <a href="shipping.php">useful q&a</a> page. Nonetheless, we'll always be happy to answer your questions by phone or through the form below. We look forward to hearing from you.</p><br /> <div id="contactFormContainer"> <form method="post" id="contactForm" action="<?php echo($_SERVER['PHP_SELF']); ?>" > <div id="formContainer"> <input type="hidden" name="submitted" value="true" /> <input type="hidden" name="formname" value="contact" /> <div class="formRow"> <div class="itemSet"> <p class="itemLabel">Name</p> <input tabindex="1" class="itemContent" type="text" name="guestName" value='<?php echo $_POST[Name]; ?>' /> </div> <div class="itemSet"> <p class="itemLabel">City & state</p> <input tabindex="2" class="itemContent" type="text" name="cityState" /> </div> <br class="clearMe" /> </div> <div class="formRow"> <div class="itemSet"> <p class="itemLabel">Email Address</p> <input tabindex="3" class="itemContent" type="text" name="emailAddress" /> </div> <div class="itemSet"> <p class="itemLabel">Phone & best local time to call</p> <input tabindex="4" class="itemContent" type="text" name="phone" /> </div> </div> <div class="formRow"> <div> <p class="itemLabel">Your question</p> <textarea tabindex="5" id="msgContent" type="text" name="msgContent">Please telephone us to submit an order</textarea> </div> </div> <div class="formRow"> <div style="position: relative;"> <div style="float: left; margin-right: 40px;"> <input tabindex="6" id="submitButton" type="submit" name="submit" value="Submit" /> </div> <div style="float: left; margin-top: -10px;"> <?php //echo($msg); ?> </div> <br style="clear: both;" /> <div style="clear: both; position: absolute; top: -350px; left: -217px; width: 180px;"> <?php echo($msg); echo($brisket); ?> </div> <br style="clear: both;" /> </div> </div> </div> <!-- End Form Container --> </form> </div> <!-- End Contact Form --> </div> </div><!-- End Content Area--> <div id="bottomBar"></div> <?php include("../common/footer.php"); ?> </div><!-- End Container --> </body> </html> CODE STOPS HERE===================================== Can someone help me debug this code...this is a search page where it searches the keyword typed in the mysql db and it limits 10 results per page...and at the bottom if there are more than 10 results it says next 10 and its a link but when it is clicked it goes to the code and says please type a search, here is the code can someone please help me with this I would really appreciate it. Code: [Select] <?php $page = $PHP_SELF; // Get the search variable from URL $var = @$_GET['search'] ; $searchtype = @$_GET['searchtype']; $isbn = "ISBN"; $school = "School"; $title = "Title"; $subject = "Subject"; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database $connect = mysql_connect("","]",]") or die("Not connected"); //specify database mysql_select_db("collegebooxboox") or die("could not log in"); if ($searchtype == ($title)) { // Build SQL Query $query = "select * from boox where name like \"%$trimmed%\" order by name"; // EDIT HERE and specify your table and field names for the SQL query } elseif ($searchtype == ($school)) { // Build SQL Query $query = "select * from boox where school like \"%$trimmed%\" order by school"; // EDIT HERE and specify your table and field names for the SQL query } elseif ($searchtype == ($isbn)) { // Build SQL Query $query = "select * from boox where isbn like \"%$trimmed%\" order by isbn"; // EDIT HERE and specify your table and field names for the SQL query echo "isbn"; } elseif ($searchtype == ($subject)) { // Build SQL Query $query = "select * from boox where subject like \"%$trimmed%\" order by subject"; // EDIT HERE and specify your table and field names for the SQL query } $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\" target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here</a> to try the search on google</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . "" in "" . $searchtype ."" </p>"; // begin to show results set echo "Results "; $count = 1 + $s ; if ($searchtype = $title) { // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["name"]; echo "$count. $title   </br><table width='297' border='1' align='center'> <tr> <td width='152'>Book Title:</td> <td width='129'>$row[name]</td> </tr> <tr> <td>Author:</td> <td>$row[author]</td> </tr> <tr> <td>ISBN#</td> <td>$row[isbn]</td> </tr> <tr> <td>Date Posted:</td> <td>$row[date]</td> </tr> <tr> <td>Posted By:</td> <td><a href='backpack.php' onclick='document['packback'].submit()'>$row[username]</a></td> </tr> <tr> <td>School:</td> <td>$row[school]</td> </tr> </table></br>"; $count++ ; } } elseif ($searchtype = $school) { // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["school"]; echo "$count. $title" ; $count++ ; } } elseif ($searchtype = $subject) { // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["subject"]; echo "$count. $title" ; $count++ ; } } elseif ($searchtype = $isbn) { // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["isbn"]; echo "$count. $title" ; $count++ ; } } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> ok so now all my logo link goes to the same page..i dont know how to fix it.i want all of them connect to a link(each of the company has their own company_link id) which i named company_link which is already in the database..so i need to call it.there are about 20 total logos.. except for the $company id=33..just remain that one.. Code: [Select] <? if(isset($_GET[ttid])) { $ttid = $_GET[ttid]; } $connection=mysql_connect("$server", "$username", "$password") or die("Could not establish connection"); mysql_select_db($database_name, $connection) or die ("Could not select database"); $query = "select master_event.* , (DATE_FORMAT(event_datefrom, '%d %M %Y')) as datefrom, (DATE_FORMAT(event_dateto, '%d %M %Y')) as dateto, ucase(event_name) as eventname from master_event where master_event.event_id = '$ttid '"; $result=mysql_query($query); while($row = mysql_fetch_array($result)){ $eventname = $row['eventname']; $eventdesc = $row['event_desc']; $companydescription = $row['company_description']; $eventvenue = $row['event_venue']; $eventfee = $row['event_fee']; $datefrom = $row['datefrom']; $dateto = $row['dateto']; echo "<font color='#000000' face='arial' ><b> $eventname </b> </font> <br>"; echo "<font color='#000000' face='arial' ><i>Date</i> : $datefrom - $dateto <br>"; echo "<i>Venue</i> : $eventvenue <br>"; $querypstype = "SELECT DISTINCT master_pstype.pstype_id, pstype_desc FROM master_pstype INNER JOIN master_psevent ON master_psevent.pstype_id= master_pstype.pstype_id where master_psevent.event_id = '$ttid' ORDER BY pstype_id"; $resultpstype=mysql_query($querypstype); while($rowpstype = mysql_fetch_array($resultpstype)){ $pstypeid = $rowpstype['pstype_id']; $pstypedesc = $rowpstype['pstype_desc']; echo "<br><font color='#8B3A3A' size='1' face='georgia' ><b><i>$pstypedesc</i></b></font> <br>"; $queryps = "SELECT master_psevent.*, pstype_desc, company_name, company_link, company_description, logo_filename FROM master_psevent LEFT JOIN master_pstype ON master_psevent.pstype_id = master_pstype.pstype_id LEFT JOIN master_ps ON master_ps.ps_id = master_psevent.ps_id WHERE master_psevent.event_id = '$ttid' and master_pstype.pstype_id= '$pstypeid' ORDER BY pstype_desc,company_name "; $resultps=mysql_query($queryps); while($rowps = mysql_fetch_array($resultps)){ $companyname = $rowps['company_name']; $companyid = $rowps['ps_id']; $companylinkori = $rowps['company_link']; $companydescription = $rowps['company_description']; if ($companyid==33){ $companylink = "http://(confidential)/index.php?view=describe"; } else { if ($companylinkori <> "") { //$companylink = "http://".$rowps['company_link']; $companylink = "http://(confidential)/index.php?view=".$companyid; } else { $companylink = ""; } } $logopath = $rowps['logo_filename']; if ($companylink <> ""){ echo "<font color='#4A708B' face='arial' ><a href=$companylink style=\"color:white;text-decoration: none; \" target='new'><img src=".$logo_dir."/".$logopath." width=\"15%\"></img></a>  </font>"; } else { echo "<font color='#4A708B' face='arial' ><img src=".$logo_dir."/".$logopath." width=\"15%\"></img>  </font>"; } ?> <br> <? } echo "<br>"; } } ?> It's been a while since I've needed to whip anything substantial up from scratch, so my scripting is a little (lot) fast and loose (weird/inefficient) here. I'm trying to mock up a script that's essentially a quiz/survey. There are a handful of topics, each with a few screens of yes/no questions. At the end, it returns a list of recommendations based on the answers gathered. The script is posting back to itself. Using print_r ($_SESSION), it seems like all of the post values for the first screen of questions are being assigned to the session array as expected. When the second screen of questions is answered, their values are assigned as well, but the values for the first set go away completely. This continues through subsequent screens, with the values from the previous screen present and all others before missing. I'd really appreciate a look at my code to see if you tell me the cause or error(s). Thanks! <?php session_start; include('_config.php'); // database connect $dbc = mysqli_connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname); // set to section 1, page 1 if no values are in _POST array if (($_SERVER['REQUEST_METHOD'] == 'GET') || (!isset($_POST['section']))) { $section = 1; $page = 1; } else { // something was posted, so...set those values in session variable foreach($_POST as $key => $data) { $_SESSION[$key] = $data; } // debug: display contents of the session array print_r ($_SESSION); // which section and page? $section = (int) $_POST['section']; $page = (int) $_POST['next']; } // check if last topic $query = "SELECT * FROM hw_topics"; $data = mysqli_query($dbc, $query); if ($section == mysqli_num_rows($data)) { $last_section = true; } else { $last_section = false; } // get current topic name and info $query = "SELECT topic, display_name, pages_in_topic FROM hw_topics WHERE topic_id = '$section'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { $row = mysqli_fetch_array($data); $topic_display_name = $row['display_name']; $pages_in_topic = $row['pages_in_topic']; } // test if last page in topic $topic_pages = $row['pages_in_topic']; if ($page == $topic_pages) { $last_page_in_section = true; } else { $last_page_in_section = false; } // set form action (set to this script or to recommendations when last section is complete if (($last_section == true) && ($last_page_in_section == true)) { $form_action = $CFG->reccomend; } else { $form_action = $_SERVER['PHP_SELF']; } // get current page headline $query = "SELECT page_headline FROM hw_pages WHERE topic_id = '$section' AND page_number = '$page'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The headline row was found so display the headline $row = mysqli_fetch_array($data); $page_headline = '<h2>' . $row['page_headline'] . '</h2>'; } // Grab the question data from the database to generate the list and form fields $query = "SELECT question_id, question_number, question_text FROM hw_questions WHERE topic_id = '$section' AND page_id = '$page' ORDER BY question_number"; $data = mysqli_query($dbc, $query); $questions = array(); while ($row = mysqli_fetch_array($data)) { array_push($questions, $row); } include($CFG->includesdir.'/header.php'); ?> <div id="head"> <h1>Assessment<?php if (isset($topic_display_name)) { echo ': <em>' . $topic_display_name . '</em>'; } ?></h1> <p class="paging">Page <?php echo $page; ?> of <?php echo $pages_in_topic; ?></p> </div><!-- #head --> <div id="content"> <p class="instr">Please complete this survey. We'll generate a list of recommendations and resources for your organization.</p> <div id="questions"> <?php echo $page_headline; ?> <form method="post" action="<?php echo $form_action; ?>"> <table border="0" cellpadding="0" cellspacing="0"> <thead> <tr> <td></td> <td class="qtext"></td> <td class="qanswer">yes</td> <td class="qanswer">no</td> <td class="pad"></td> </tr> </thead> <?php if ($questions) { // display question rows foreach ($questions as $question) { echo '<tr>'; echo '<td class="qnumber">' . $question['question_number'] . '.</td>'; echo '<td class="qtext"><p>...' . $question['question_text'] . '</p></td>'; echo '<td class="qanswer"><div class="radio" id="box-yes"><input type="radio" value="yes" name="qid_' . $question['question_id'] . '" id="qid_' . $question['question_id'] . '" class="radio" /></div></td>'; echo '<td class="qanswer"><div class="radio" id="box-no"><input type="radio" value="no" name="qid_' . $question['question_id'] . '" id="qid_' . $question['question_id'] . '" class="radio"'; $field_name = 'qid_' . $question['question_id']; if (isset($_SESSION[$field_name])) { echo ' checked="checked"'; } echo ' /></div></td>'; echo '<td class="pad"></td>'; echo '</tr>'; } } else { echo '<tr>'; echo '<td colspan="3" class="qtext"><p>No questions found in the database for this page.</p></td>'; echo '<td class="pad"></td>'; echo '</tr>'; } ?> </table> <ul id="controls"> <?php if ($last_page_in_section == true) { $section++; $page = 1; } else { $page++; } echo '<input type="hidden" value="' . $section . '" name="section" />'; echo '<input type="hidden" value="' . ($page) . '" name="next" />'; if (($last_section == true) && ($last_page_in_section == true)) { echo '<li><input type="submit" value="Submit Answers and Get Recommendations" name="submit" id="submit" /></li>'; } else { echo '<li><input type="submit" value="Next Page" name="submit" id="next" /></li>'; } ?> </ul><!-- #controls --> </form> </div><!-- #questions --> <?php mysqli_close($dbc); include($CFG->includesdir.'/footer.php'); ?> Hello. Say i want to view another user profile. I click on user name and i see the profile page. So how can i link user name to his profile? I have tried linking it to $id (this is where user id is stored in the database), but no luck. Thank you. Hello all, I am working on a webpage which needs to be finished Friday so I am a bit stressing out, hence this post. I have made the following script: // Uitkomst van POST waardes echo"<pre>"; print_r($_POST); echo"</pre>"; // LET OP: De tabel "test_optie" is niet compleet gevuld en daarom werkt het script alleen als je start bij categorie 1. // Het is dus GEEN fout in de script, alleen de database is niet helemaal gevuld kostte me teveel tijd! echo" <html> <head> <style> select {float:left;width:250px;margin:0 5px 0 0;} </style> </head> <body> <form name='form' action='chainselect.php' method='post' /> <select name='veld1' onChange='document.form.submit()'> "; // Data opvragen $sql_categorie = mysql_query("SELECT * FROM plaatsnaam ORDER BY id") or die (mysql_error()); // Counter $a = 0; // Standaard geselecteerd echo"<option value='0' selected>Selecteer een plaats</option>"; while($row_categorie = mysql_fetch_array($sql_categorie)){ $a++; echo"<option value='$row_categorie[id]' ";if($_POST[veld1] == "$a"){echo"selected";}echo">$row_categorie[naam]</option>"; } echo" </select> <select name='veld2' onChange='document.form.submit()'> "; // Data opvragen $sql_rubriek = mysql_query("SELECT * FROM branche WHERE catid = '$_POST[veld1]'") or die (mysql_error()); $ant_rubriek = mysql_num_rows($sql_rubriek); // Huidige id veld2 om zodoende huidig veld te selecteren indien gewijzigd if(isset($_POST[veld2])){ $b = "$_POST[veld2]"; } // Als er geen data gevonden is dan de onderstaande option laten tonen. if($ant_rubriek <= 0){ echo"<option value='0'>-</option>"; } else{ // Standaard geselecteerd echo"<option value='0' selected>Selecteer een branche</option>"; while($row_rubriek = mysql_fetch_array($sql_rubriek)){ echo"<option value='$row_rubriek[id]' ";if($_POST[veld2] == "$row_rubriek[id]"){echo"selected";}echo">$row_rubriek[naam]</option>"; } } echo" </select> <select name='veld3' onChange='document.form.submit()'> "; // Data opvragen $sql_optie = mysql_query("SELECT * FROM filiaal WHERE catid = '$_POST[veld1]' AND rubid = '$_POST[veld2]'") or die (mysql_error()); $ant_optie = mysql_num_rows($sql_optie); // Huidige id veld3 om zodoende huidig veld te selecteren indien gewijzigd if(isset($_POST[veld3])){ $c = "$_POST[veld3]"; } // Als er geen data gevonden is dan de onderstaande option laten tonen. if($ant_optie <= 0){ echo"<option value='0'>-</option>"; } else{ // Standaard geselecteerd echo"<option value='0' selected>Selecteer een filiaal</option>"; while($row_optie = mysql_fetch_array($sql_optie)){ echo"<option value='$row_optie[id]' ";if($_POST[veld3] == "$row_optie[id]"){echo"selected";}echo">$row_optie[naam]</option>"; } } echo" </select> </form> </body> </html> "; ?> What I need now is the results shown linked to a page. U can see the dropdowns in action he www.inventar.nl/chainselect.php For example: In the first dropdown I select Groningen, in the 2nd drop I select Groningen, Restaurant and in the 3rd Groningen, Restaurant, Ni Hao Wok. This gives me the following: Quote Array ( [veld1] => 1 [veld2] => 2 [veld3] => 3 ) Now I have a page named nihao.php, this page needs to be linked to this array result. So if I do the above dropdowns it needs to open nihao.php Can anyone help me with this problem? I am really confused! Thanks in advance! Wheelie I have a site, and there is an image with a link to another page, how can I make it so this is the only way to get to that page is by clicking on that image, and not by typing www.mywebsite.com/page.php into the address bar in a browser? hi there alll newbie here lol just needed help with the code for the next page of results ? IE i have say 30 results returned from a sql query but only want to show ten at a time i no how to limit the result with the LIMIT 10 but how do i get it to put link show the other ten and so on. the code i have is here at the bottom of page http://www.phpfreaks.com/forums/index.php/topic,307971.0.html thanks in advance for any help kaine Every other time a user/users click on a link I want the link to change to a different url the next time a user clicks onto that link.
For example two links
url1.html
url2.html
url1.html shows up when a user clicks that link the link auto changes to then when a new user clicks the linke url2.html then back to url1.html and so on?
Don't know where to start on how I would do this let alone have the server remember to keep which ever link to be held for the next user?
I have an 'I agree' button on this page https://www.setstuffrentals.com/credit-card-authorization/
I basically need the button to redirect to another web page after a customer hits 'I agree'. I don't know PHP much. Can someone help step by step, please? |