Jump to content

el-sid

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

el-sid's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, I have two tables: category and articles. They have a one-to-many relationship. category: id, name, is_menu[true/false] articles: id, category_id, title, content what i do is i retrieve all items in the category table that have is_menu set to true, to create a menu item. The idea should be that when i click on the menu, the page should show me the latest article from that category. on the sidebar, it should show me links of other article titles within that category. something like this: http://www.uapkenya.com/about-uap/ does anyone know how to go about this? I don't need you to show me code, just some pointers on how to go about it. Thanks in advance
  2. i am redirecting from a link in another page. it redirects from this code in a seperate php file while($row = mysql_fetch_assoc($result)) { // Display the row $id = $row['id']; $caption = $row['caption']; $content = $row['content']; $event_image = $row['event_image']; /** * show each article with edit/delete links */ echo "<div>ID: $id</div>"; echo "<div>Caption: $caption</div>"; echo "<div>Content: $content</div>"; echo "<div>Event Picture: $event_image</div>"; echo "<div><a href=\"editEvent.php?id=$id\">Edit</a> | <a href=\"deleteEvent.php?id=$id\">Delete</a></div>"; echo"<br /><hr />"; }
  3. thanks for the reply riwan, but it didnt work. could it be that all the other $_POST varables are available because they come from a $_POST request while the id is a $_GET in a $_POST form. though i was under the impression that requests in the url are accessible no matter the method in the form
  4. hi, i am unable to retrieve the id from the $_GET variable. I am trying to update a table in a database with a specific id. The thing is, i can see the id on the address bar, but cannot retrieve it via $_GET http://portal:8080/events/admin/editEvent.php?id=14 this is the code <?php require('../config.php'); //require('../NewsScript.php'); include ('../../lib/class.form.php'); include ('../../lib/Events.class.php'); include ('../../lib/class.upload.php'); session_start(); /** * Here we have clicked the button to update our edited article * We need to update it in the database */ if(!empty($_POST['caption'])) { $event = new Events(); $uploadDir = dirname(__FILE__) . "/images/"; $tmpName = $_FILES['event_image']['tmp_name']; $ext = substr(strrchr($tmpName, "."), 1); // make the random file name $randName = md5(rand() * time()); // and now we have the unique file name for the upload file $filePath = $uploadDir . $randName . '.' . $ext; $name = $randName . '.' . $ext; $file = new upload($_FILES['event_image']); $file->file_new_name_body = $name; $file->image_resize = true; $file->image_convert = gif; $file->image_x = 100; $file->image_y = 100; $file->process($uploadDir); $event->updateEvent($_GET['id'], $_POST['caption'], $_POST['content'], $filePath ); if($event->updateEvent($_GET['id'], $_POST['caption'], $_POST['content'], $filePath )) { echo "Update complete!"; echo "<br>"; echo $_GET['id'] . "<br>"; echo $_POST['caption'] . "<br>"; echo $_POST['content'] ."<br>"; echo $filePath; } else { echo "Update Error!"; } exit(); } else // page loads but form not submitted { if(is_numeric($_GET['id'])) { $connection = mysql_connect($db_host, $db_user, $db_password) or die("Unable to connect to MySQL"); mysql_select_db($db_name, $connection) or die("Unable to select DB!"); $id = $_GET['id']; $result = mysql_query("SELECT * FROM event WHERE id = '$id'"); $row = mysql_fetch_assoc($result); $caption = $row['caption']; $content = $row['content']; mysql_close($connection); } else { echo "None numeric Value!"; } } /** * output our content * */ function showContent() { global $content; echo $content; } /** * output the author * */ function showCaption() { global $caption; echo 'value="'. $caption . '"'; } ?> <!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=iso-8859-1" /> <title>Edit News</title> </head> <body> <h1>Edit News</h1> <?php $form = new genForm(); $form->startForm(basename($_SERVER['PHP_SELF'])); $form->startFieldset(''); $form->textareaInput('caption','Caption',false,false,false,$caption, 15,10); $form->closeFieldset(); $form->insertBR(); $form->startFieldset(''); $form->textareaInput('content','Content',false,false,false,$caption, 25,10); $form->closeFieldset(); $form->insertBR(); $form->startFieldset(''); $form->fileInput('event_image','Upload Your Event Picture'); $form->closeFieldset(); $form->insertBR(); $form->newline = false; $form->submitButton(); $form->newline = true; $form->resetButton(); $form->closeForm(); if(!$output = $form->getForm()) { die("error: " . $form->error); } else { echo $output; } ?> </body> </html> any ideas? thanks
  5. thanks for the reply, the error was the white screen - sorry for the confusion. The form is meant to render only when there is no $_POST data
  6. hi, i get the following error when trying to render a form. I think it has to do with html content(header issue) though i'm not sure of how to reposition it <?php include ('../../lib/class.form.php'); include ('../../lib/Events.class.php'); session_start(); if($_POST['submit']) { if(!empty($_POST['caption']) && !empty($_POST['content'])) { $event = new Events(); $event->addEvent($_POST['caption'], $_POST['content'], $_POST['event_image']); } else { ?> <!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> <title>Add Event</title> </head> <body> <h1>Add Event</h1> <?php $form = new genForm(); $form->startForm(basename($_SERVER['PHP_SELF'])); $form->startFieldset(''); $form->textInput('caption','Caption',false,'block required'); $form->insertBR(); $form->startFieldset(''); $form->textareaInput('content','Event Details',false,'block'); $form->insertBR(); $form->startFieldset(''); $form->fileInput('event_image','Upload Your Event Picture'); $form->closeFieldset(); $form->insertBR(); $form->newline = false; $form->submitButton(); $form->newline = true; $form->resetButton(); $form->closeForm(); if(!$output = $form->getForm()) { die("error: " . $form->error); } else { echo $output; } ?> </body> </html> <?php } } ?> anyone knows what i'm missing?
  7. Hi, thanks for the reply. you were right in that i needed to add the vendor directory and your solution worked. My intention was to try and autoload the entire lib directory as some of my classes will be located at the lib root directory. So i gather in order to autoload the entire lib directory i would have to include another path -this time to the lib yes?
  8. Hello all, First, let me say that i know this is a known issue...but even after googling around, am still not able to get past this error. Any help would be REALLY appreciated. What im trying to do is use individual components from zend framework - in this case, the loader class to autoload all by classes in the lib directory. my app structure is as follows: Root application lib vendor Zend Loader(directory with all its components inside) Loader.php web index.php bootstrap.php the code in the bootstrap is as follows set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lib'); require_once dirname(__FILE__) . '/lib/vendor/Zend/Loader/Autoloader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); when i execute this, i get: Warning: require_once(Zend/Loader.php): failed to open stream: No such file or directory in /home/sydney/Projects/Merchant/lib/vendor/Zend/Loader/Autoloader.php on line 24 Fatal error: require_once(): Failed opening required 'Zend/Loader.php' (include_path='.:/usr/share/php:/home/sydney/Projects/Merchant/lib') in /home/sydney/Projects/Merchant/lib/vendor/Zend/Loader/Autoloader.php on line 24 I'm using debian lenny. I know this must be a configuration issue but i just cant get my head around it. Any help is appreciated. Thanks
  9. i get this error when executing the code. still cant figure out what the problem is.any help please You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 <?php ini_set("display_errors","1"); error_reporting("E_ALL"); include 'include.inc'; set_error_handler("errorHandler"); // Initialize a session session_start(); // Clear any errors that might have been // found previously $errors = array(); foreach($_POST as $varname => $value) $formVars[$varname] = trim(clean($value, 50)); $_SESSION["formVars"] = $formVars; // Validate the surname if (empty($formVars["surname"])) // surname cannot be a null string $errors["surname"] = "You must enter your surname."; elseif (strlen($formVars["surname"]) > 50) $errors["surname"] = "The surname cannot be longer than 50 " . "characters"; // Validate the Other names if (empty($formVars["other_names"])) // the user's other name cannot be a null string $errors["other_names"] = "You must enter your other names."; elseif (strlen($formVars["other_names"]) > 50) $errors["other_names"] = "The other names cannot be longer than 50 " . "characters"; // Validate the Address if (empty($formVars["address"])) $errors["address"] = "You must enter your address"; elseif (strlen($formVars["address"]) > 50) $errors["address"] = "The address cannot be longer than 50 " . "characters"; //Validate the phone number if (empty($formVars["phone_no"])) $errors["phone_no"] = "You must enter your phone number"; elseif (strlen($formVars["phone_no"]) > 30) $errors["phone_no"] = "The address cannot be longer than 30 " . "characters"; //Validate the email if (empty($formVars["email"])) $errors["email"] = "You must enter your email address"; // Validate the date of birth if (empty($formVars["dob"])) $errors["dob"] = "You must provide a date of birth."; elseif (!ereg("^([0-9]{4})-([0-9]{2})-([0-9]{2})$", $formVars["dob"], $parts)) // Check the format $errors["dob"] = "The date of birth should be in the" . "format DD/MM/YYYY"; // Validate the gender if (empty($formVars["gender"])) $errors["gender"] = "You must specify your gender"; // Validate the date of employment if (empty($formVars["date_of_emp"])) $errors["date_of_emp"] = "You must enter your employment date"; elseif (!ereg("^([0-9]{4})-([0-9]{2})-([0-9]{2})$", $formVars["date_of_emp"], $parts)) // Check the format $errors["date_of_emp"] = "The date of employment should be in the" . "format DD/MM/YYYY"; if (empty($formVars["level"])) $errors["level"] = "The level field cannot be empty"; // Only validate username if this is an INSERT if (!isset($_SESSION["loginUsername"])) { if (empty($formVars["username"])) $errors["username"] = "You must enter the username"; elseif (strlen($formVars["username"]) > 10) $errors["username"] = "The username can be no longer than 10 " . "characters"; else { // Check if the email address is already in use in // the winestore if (!($connection = @ mysql_pconnect($hostName, $username, $password))) showerror(); if (!mysql_select_db($databaseName, $connection)) showerror(); $query = "SELECT * FROM login WHERE username = '" . $formVars["username"] . "'"; if (!($result = @ mysql_query ($query, $connection))) showerror(); // Is it taken? if (mysql_num_rows($result) == 1) $errors["username"] = "A salesman already exists with this " . "login name."; } } // Only validate password if this is an INSERT // Validate password - between 6 and 8 characters if (!isset($_SESSION["loginUsername"]) && (strlen($formVars["loginPassword"]) < 6 || strlen($formVars["loginPassword"] > )) $errors["loginPassword"] = "The password must be between 6 and 8 " . "characters in length"; // Now the script has finished the validation, // check if there were any errors if (!empty($errors)) { // Store the errors in the session variable $_SESSION["errors"] = $errors; //echo "<script>document.location.href='salesman.register.php'</script>"; header('Location: salesman.register.php'); exit(); } // If we made it here, then the data is valid if (!isset($connection)) { if (!($connection = @ mysql_pconnect($hostName, $username, $password))) showerror(); if (!mysql_select_db($databaseName, $connection)) showerror(); } // Is this an update? if (!isset($_SESSION["loginUsername"])) { $salesman_code = getSalesmanID($_SESSION["loginUsername"], $connection); $query = "UPDATE salesman SET ". "surname = \"" . $formVars["surname"] . "\", " . "other_names = \"" . $formVars["other_names"] . "\", " . "address = \"" . $formVars["address"] . "\", " . "phone_no = \"" . $formVars["phone_no"] . "\", " . "email = \"" . $formVars["email"] . "\", " . "dob = \"" . $formVars["dob"] . "\", " . "gender = \"" . $formVars["gender"] . "\", " . "date_of_emp = \"" . $formVars["date_of_emp"]. "\" " . " WHERE salesman_code =" . $salesman_code; } else $query = "INSERT INTO salesman VALUES (NULL, " . "\"" . $formVars["surname"] . "\", " . "\"" . $formVars["other_names"] . "\", " . "\"" . $formVars["address"] . "\", " . "\"" . $formVars["phone_no"] . "\", " . "\"" . $formVars["email"] . "\", " . "\"" . $formVars["dob"] . "\", " . "\"" . $formVars["gender"] . "\", " . "\"" . $formVars["date_of_emp"] . "\" " . ")"; // Run the query on the customer table if (!(@ mysql_query ($query, $connection))) showerror(); // If this was an INSERT, we need to INSERT // also into the users table if (!isset($_SESSION["loginUsername"])) { // Get the customer id that was created $salesman_code = @ mysql_insert_id($connection); // Use the first two characters of the // username as a salt for the password $salt = substr($formVars["username"], 0, 2); // Create the encrypted password $stored_password = crypt($formVars["loginPassword"],$salt); // Insert a new user into the user table $query = "INSERT INTO login SET salesman_code = $salesman_code, password = '$stored_password', username = '" . $formVars["username"] . "'".","." level = '" . $formVars["level"] . "'"; if (!($result = @ mysql_query ($query, $connection))) showerror(); // Log the user into their new account //session_register("loginUsername"); $_SESSION["loginUsername"] = $formVars["username"]; } // Clear the formVars so a future <form> is blank unset($_SESSION["formVars"]); unset($_SESSION["errors"]); //echo "<script>document.location.href='salesman.mainform.php?salesman_code=$salesman_code'</script>"; header('Location: salesman.mainform.php?salesman_code=$salesman_code'); ?>
  10. it worked after clearing out some session variables and commenting out the error includes and functions. i still dont get quite how that worked but it did. thanks for the help PFMaBiSmAd
  11. sorry..didnt see your edited message there. i just commented out the error.inc file and the set_error_handler function and it gave me the desired output. still not quite sure how that worked out however its redirection leads..again..to a white screen of the same page according to the address bar
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.