PHP - Moved: Need Help With An Easy Fix..
This topic has been moved to Third Party PHP Scripts.
http://www.phpfreaks.com/forums/index.php?topic=319098.0 Similar TutorialsThis topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=313079.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=308475.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=352409.0 ob_start(); include('file.php'); $content = ob_get_clean(); ok so this is the code i found for adding a file to a variable.. now how would i use it in term of this: <?php $id = NULL; if(isset($_GET['id']) && $_GET['id'] == "1"){ $id = 'Marc'; } else if(isset($_GET['id']) && $_GET['id'] == "2"){ $id = 'Glenn'; } else if(isset($_GET['id']) && $_GET['id'] == "3"){ $id = 'Nathan'; } else if(isset($_GET['id']) && $_GET['id'] == "4"){ $id = 'Scott'; } ?> ok so the get variable checks to see whose id youve requested. then when for example id = 4 i want to display an include file somewhere else on the page so i would use.. <?php echo $id; ?> now insted of it being "nathan" i want it to be a file i didnt really understand the first code i found Right now I'm working on a simple register form and I have included the theme. I set up a div and positioned the div below the register form to output any error in red text. If I were to use code like this if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email']) || empty($_POST['Veremail'])){ $required_info = "All three fields are required to continue!"; } It will not work, because I don't have a die(); or end(); function, so it will display: " All three fields are required to continue! and You have been successfully registered! " BUT IT'S IN THE CORRECT PLACE UNDER THE FORM WHERE I PLACED THE DIV. So I made this change if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email']) || empty($_POST['Veremail'])){ $required_info = die("All three fields are required to continue!"); } and it worked fine, but now, the words are not positioned under the form, but at the bottom of the page, I'm wondering how I would end that script, but align the text so it displays underneath the form, and not at the bottom of the page? If you don't understand ask me please. I am trying to send an html file (with .js formatting) to the browser from within a PHP script. The .js formatting is not being interpreted and so the result in the browser is less than impressive. Why can't I make a call, in PHP, to a url and have the results from that call directed to the browser? First of all, the field that holds prefgender does not say "Not added yet". Yet when I do this, it doesn't echo the info: Code: [Select] $prefgender = $req_user_info['prefgender']; if(!$prefgender == "Not added yet"){ ?> <tr> <td>Preferred gender:</td> <td><? echo $req_user_info['prefgender'] ?></td> </tr> <? } Any ideas? <?php query_posts('showposts=10'); ?> <!-- The 10 most recent post, the first one not included --> <h2>Other Recent Articles</h2> <ul> <?php while (have_posts()) : the_post(); ?> <li><span class="title"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></span> <span class="meta"></span></li> <?php endwhile; ?> </ul> <br /> <p class="link"><a href="<?php echo get_option('home'); ?>/archives" title="View Archives">View Archives</a></p> The the first line in the code will display the last 10 posts from all categories. this one: <?php query_posts('showposts=10'); ?> But I want to display the last 10 posts from all categories EXCEPT for the newest post in category 12. so the formula should look something like this... <?php query_posts('showposts=10 BUT DO NOT INCLUDE THE NEWEST POST FROM CAT 12 '); ?> I'm not sure how to do this, can anyone help? I need make error lower then 3 and higher then 15 how should i add higher then 15? Code: [Select] if (strlen($searchTerms) < 3) { $error[] = "Add more then 3 symbols and less then 15!"; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } Easy One - What is the symbol for or? Example: && = and, right? What is 'or'? Hey guys, I'm dealing a url that is similar to hxxp://domain/directory/?#{$id}. What I'm trying to do is extract $id from that. Its not available as a $_GET variable and $_SERVER['REQUEST_URI'] comes up as "/directory/?". Does anyone know how I could retrieve $id ? Thanks I want to know can we do text formatting to a result coming from echo if so then kindly guide how? I'm just learning php and I've created a test shopping website. Everything is working well, but I need help with the following: This is my products table in the database: "CREATE TABLE products ( id int(11) NOT NULL auto_increment, product_name varchar(255) NOT NULL, price varchar(16) NOT NULL, details text NOT NULL, category varchar(16) NOT NULL, subcategory varchar(16) NOT NULL, date_added date NOT NULL, PRIMARY KEY (id), UNIQUE KEY product_name (product_name) ) "; I have 3 subcategories: Hats, Pants and Shirts. On my index page I have links to these three items. This is my products.php code. When run it shows all the items in the 3 subcategories. How do I change the code so that this page display only the Hats when someone clicks on the Hats link? <?php // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $dynamicList = ""; $sql = mysql_query("SELECT * FROM products ORDER BY subcategory DESC"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a></td> <td width="83%" valign="top">' . $product_name . '<br /> $' . $price . '<br /> <a href="product.php?id=' . $id . '">View Product Details</a></td> </tr> </table>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> <!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>Store Home Page</title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("template_header.php");?> <div id="pageContent"> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td width="32%" valign="top"><h3>xxx</h3> <p>xxx</p></td> <td width="35%" valign="top"><h3>Latest Designer Fashions</h3> <p><?php echo $dynamicList; ?><br /> </p> <p><br /> </p></td> <td width="33%" valign="top"><h3>xxx</h3> <p>xxx</p></td> </tr> </table> </div> <?php include_once("template_footer.php");?> </div> </body> </html> If someone can help me I'd be so grateful! Hello! I am trying to make a Guestbook with help from the internet. I have created all sites what i need, but i have some problems with the Input. For example here is the Name inputfrom the "sign.php" <form id="form1" name="form1" method="post" action="addguestbook.php"> <td> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><input name="name" type="text" id="name" size="40" /></td> </tr> And here is the "insert sequence" from the "guestbook.php": $sql="INSERT INTO $tbl_name(name, email, comment, datetime) VALUES('$name', '$email', '$comment', '$datetime')"; $result=mysql_query($sql); If i open the guestbook.php i just can see the datetime. What went wrong? Thanks, Mark p.S.: sorry for my english. Ok so this is what I am looking for and I cannot seem to find any documentation on it! I have some html files which I want to call up by using the following: engine.php?id=? with the questionmark being 1,2,3,4,5,6, etc... where each number is a different HTML page, I just want it to look a little cleaner then if I just have it redirect to each page itself I mean come on what looks better: http://localhost/engine.php?id=1 <------ http://localhost/home.html Any guidance is welcome. Thanks, Drew OK below is my code. the values for $row['state'] are in this format "AL - Alabama" its got the space in it. Code: [Select] while($row = mysql_fetch_array($result)) { echo "<option value=" . $row['state'] . '">' . $row['state']; } ?> When i run the script it outputs HTML as this Code: [Select] <option value="AL" -="" alabama"="">AL - Alabama</option> As you can see at the space it terminates and puts the " in. Im assuming this is a rookie programming mistake. Please help, Justin Is there a simple way of sorting data like this? $string = " 50|1|0|15|1|1~ 13|2|0|15|1|1~ 50|3|0|15|1|0~ 19|1|2|10|0|0~ 19|2|2|10|0|0~ 22|4|2|10|0|0~ 22|3|2|10|0|0~ 19|5|2|10|0|0~ 1|6|2|10|1|0~ 19|6|1|10|1|1 "; I treat this data as a string, and create an array out of it as follows: $individuals = explode("~", $string); Then I can divide up each individual as follows: foreach ($individuals as $individual) { $individual = explode("|", $individual); } How can I write something that sorts this data by $individual[0], $individual[1], and $individual[2], respectively and in that order?? After sorting I should get the following: $string = " 1|2|10|0|0~ 13|2|0|15|1|1~ 19|2|1|10|0|0~ 19|5|2|10|0|0~ 19|6|1|10|1|0~| 19|6|2|10|1|1~ 22|3|2|10|0|0~ 22|4|2|10|0|0~ 50|1|0|15|1|1~ 50|3|0|15|1|0 "; Help? I have no idea how to write such a function. Thank you guys. Hi guys, I have a simple INSERT code. It does not throw any errors and all seems ok but the data is just not appearing in the DB. I've spent ages looking over it but perhaps a 2nd set of eyes could help? Thanks! Code: [Select] $con = mysql_connect("localhost","posturep",""); $tablename = 'product'; if (!$con) { die('Could not connect: ' . mysql_error()); } //Form data sent $product_name = $_POST['product_name']; $product_active = $_POST['product_active']; $product_cat = $_POST['product_cat']; $product_desc = $_POST['product_desc']; $prod_inoutdoor = $_POST['prod_inoutdoor']; $prod_stackable = $_POST['prod_stackable']; $prod_discounted = $_POST['prod_discounted']; echo $product_name; $sql = "INSERT INTO $tablename (name) VALUES ($product_name)"; mysql_query($sql); echo "<p>Product Saved!</p>"; echo $sql; mysql_close($con); So I know next to nothing about PHP so I need some help with something thats probably incredibly easy. I just need a function(hope I'm using that right) that checks if a div with a certain class exists in the same page. then based on whether that's true or not changes the class of an image. This is how I imagine it looks except I don't know what to put in the if brackets to make it find the div and evaluate if its there or not. <img if (){ echo(class=\"visible\"); } else{ echo(class=\"hidden\"); } } src=\"icon.png\" /> Okay, so im making a basic registration forum but keep getting an error on line 29. Here is the code: Code: [Select] <?PHP // register2.php include("dbconnect.php"); $errors = ""; if (!isset($_POST['username'])) $errors .= "Please provide a username. <br/>"; if (!isset($_POST['password'])) $errors .= "Please provide a password. <br/>"; if (!isset($_POST['email'])) $errors .= "Please provide an email address. <br/>"; if (!isset($_POST['first'])) $errors .= "Please provide a First Name. <br/>"; if (!isset($_POST['last'])) $errors .= "Please provide a Last Name. <br/>"; if (!isset($_POST['country'])) $errors .= "Please provide a Country. <br/>"; if (!isset($_POST['state'])) $errors .= "Please provide a State. <br/>"; if (!isset($_POST['street'])) $errors .= "Please provide a Street Address. <br/>"; if (!isset($_POST['city'])) $errors .= "Please provide a City. <br/>"; if (!isset($_POST['zip'])) $errors .= "Please provide a Postal Code. <br/>"; if ($errors == "") { mysql_query("INSERT INTO user_list VALUES( '', '".addslashes($_POST['username'])."', '".md5($_POST['password])."', '".addslashes($_POST['email'])."', '".addslashes($_POST['first'])."', '".addslashes($_POST['last'])."', '".addslashes($_POST['country'])."', '".addslashes($_POST['state'])."', '".addslashes($_POST['street'])."', '".addslashes($_POST['city'])."', '".addslashes($_POST['zip'])."', ") or die(mysql_error()); echo "Registration Successful!"; } else { echo $errors."Please go back and try again."; } ?> |