Jump to content

jeppers

Members
  • Posts

    157
  • Joined

  • Last visited

    Never

Everything posted by jeppers

  1. in a flat text file which i can then pull up the info and use as a voucher code.
  2. hi there i am looking to build a button counter. and i am wondering of you could help. i want the button to +1 every time someone clicks it and also store the value so it can be used as a voucher code. can anyone help thanks
  3. thanks for the help. the problem was the format i had it trying to go in the database like so 2001 20 01 which was wrong when i entered the correct format being 2001-20-01 worked well
  4. please help my head is hurting
  5. <li> <input type="submit" name="submit" value="Send My Posting" /> </li> <?php echo $date; if ($_POST['submit']){ include ('mysql_connect.php'); $sql = "insert into date (dates) values ('$date')"; $result = @mysql_query($sql) or die (mysql_error()); //run query } else { } i am struggling with this error. i have created a dummy database which all i am trying to do is enter the date. which has been selected from pull down menu's i have concatenated them and stored them in a variable call $date. i run the query and i get this as an error message 2010 01 1 Incorrect date value: '2010 01 1' for column 'dates' at row 1 has anyone got any idea on what i am doing wrong. hear is the full code i am using <form action="pulldown.php" method="post"> <label for="date">Date</label> <?php //make the months array $months = array (1 => '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'); //make the days and years array $days = range (1, 31); $years = range (2010, 2012); //make the days pull down menu echo '<select name="days">'; foreach ($days as $key => $value) { echo "<option value=\"$value\">$value</option>\n"; } echo '</select>'; //make that months pull down menus echo '<select name="months">'; foreach ($months as $key => $value) { echo "<option value=\"$value\">$value</option>\n"; } echo '</select>'; //make the year pull down menu echo '<select name="years">'; foreach ($years as $key => $value) { echo "<option value=\"$value\">$value</option>\n"; } echo '</select>'; $days = strtolower($_POST['days']); $months = strtolower($_POST['months']); $years = strtolower($_POST['years']); //create a date variable $date = $years .' '. $months .' '. $days; ?> <li> <input type="submit" name="submit" value="Send My Posting" /> </li> <?php echo $date; if ($_POST['submit']){ include ('mysql_connect.php'); $sql = "insert into date (dates) values ('$date')"; $result = @mysql_query($sql) or die (mysql_error()); //run query } else { } ?>
  6. hi there i would like to ask. does anyone no where i can look for help on extracting the date and time from a pull down menu and adding it to a database. not asking for the answer just a place i could look. hope you can help
  7. well i am working on a photo gallery and it works. pulls info and displays it. thumb nails and main image The problem is when i go on to another page and it displays another 4 images. you click to view these images and instantly the page changes and goes back to the start of the query showing the first images again. what i want to happen is when the image is clicked i want it to stay on that page. i am not sure what to do can you help. please if you need any more info please get in contact. thanks <?php // include MySQL connector function if (! @include('includes/mysql_conn.php')) { echo 'Sorry, page unavailable'; exit; } // define number of columns in table define('COLS', 2); // set maximum number of records per page define('SHOWMAX', 6); // create a connection to MySQL include ('includes/mysql_db.php'); // prepare SQL to get total records $getTotal = 'SELECT COUNT(*) FROM images'; // submit query and store result as $totalPix $total = mysql_query($getTotal); $row = mysql_fetch_row($total); $totalPix = $row[0]; // set the current page $curPage = isset($_GET['curPage']) ? $_GET['curPage'] : 0; // calculate the start row of the subset $startRow = $curPage * SHOWMAX; // prepare SQL to retrieve subset of image details $sql = "SELECT * FROM images LIMIT $startRow,".SHOWMAX; // submit the query (MySQL original) $result = mysql_query($sql) or die(mysql_error()); // extract the first record as an array $row = mysql_fetch_assoc($result); // get the name for the main image if (isset($_GET['image'])) { $mainImage = $_GET['image']; } else { $mainImage = $row['filename']; } // get the dimensions of the main image $imageSize = getimagesize('images/'.$mainImage); ?> <!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>Salsa In Cumbria <?php if (isset($title)) {echo "&#8212;{$title}";} ?> </title> <link href="includes/journey.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="header"> <h1>Salsa Nights</h1> </div> <div id="maincontent"> <h1>Salsa Nights</h1> <div id="wrapper"> <p id="picCount">Displaying <?php echo $startRow+1; if ($startRow+1 < $totalPix) { echo ' to '; if ($startRow+SHOWMAX < $totalPix) { echo $startRow+SHOWMAX; } else { echo $totalPix; } } echo " of $totalPix"; ?></p> <div id="gallery"> <table id="thumbs"> <tr> <!--This row needs to be repeated--> <?php // initialize cell counter outside loop $pos = 0; do { // set caption if thumbnail is same as main image if ($row['filename'] == $mainImage) { $caption = $row['caption']; } ?> <td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?image=<?php echo $row['filename']; ?>"><img src="images/thumbs/<?php echo $row['filename']; ?>" alt="<?php echo $row['caption']; ?>" width="80" height="54" /></a></td> <?php $row = mysql_fetch_assoc($result); // increment counter after next row extracted $pos++; // if at end of row and records remain, insert tags if ($pos%COLS === 0 && is_array($row)) { echo '</tr><tr>'; } } while($row); // end of loop // new loop to fill in final row while ($pos%COLS) { echo '<td> </td>'; $pos++; } ?> </tr> <!-- Navigation link needs to go here --> <tr> <td><?php // create a back link if current page greater than 0 if ($curPage > 0) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'">< Prev</a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> <?php // pad the final row with empty cells if more than 2 columns if (COLS-2 > 0) { for ($i = 0; $i < COLS-2; $i++) { echo '<td> </td>'; } } ?> <td> <?php // create a forwards link if more records exist if ($startRow+SHOWMAX < $totalPix) { echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'">Next ></a>'; } // otherwise leave the cell empty else { echo ' '; } ?> </td> </tr> </table> <div id="main_image"> <p><img src="images/<?php echo $mainImage; ?>" alt="<?php echo $caption; ?>" <?php echo $imageSize[3]; ?> /></p> <p><?php echo $caption; ?></p> </div> </div> </div> </div> </body> </html>
  8. what a fool this is the error $result = @mysql_query ($query) or die(mysql_error()); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK the query is effection 2 rows not one so all done thanks for all your help today
  9. //chck the form has been submitted if (isset($_POST['submitted'])) { if ($_POST['sure'] == 'yes') { //delete them //make the query $query = "DELETE foods, food_associations FROM foods, food_associations WHERE foods.food_id='$id' AND food_associations.food_id ='$id'"; $result = @mysql_query ($query) or die(mysql_error()); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK //print the message echo '<h1 "> Delete a food</h1> <p>The food has been deleted.</p><p><br /><br /></p>'; }else{ //if the query did not run ok echo '<h1 ">Sytem error</h1> <p class="error">The food could not be deleted due to a system error.</p>'; // public message echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; //debugging message. } The code above works and the query is correct. but every time i try to delete it comes up with this message "The food could not be deleted due to a system error" i then check the database and it has been deleted. can u have a look at the code and see if it something very simple thanks
  10. ok ok i was been a fool. thanks for the help
  11. well the script is pulling a $id from another script. // Check for a valid user ID, through GET or POST. if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // Accessed through view_users.php $id = $_GET['id']; } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form has been submitted. $id = $_POST['id']; } else { // No valid ID, kill the script. echo '<h1">Page Error</h1> <p>This page has been accessed in error.</p><p><br /><br /></p>'; exit(); } thanks for spotting the double colon so why do u think there is an empty query
  12. what do u think might be causing my query to be empty. i am not sure what about you. <?php // check the form has been submitted if (isset($_POST['submitted'])) { $errors = array(); // Initialize error array. // Check for a first name. if (empty($_POST['title'])) { $errors[] = 'You forgot to enter the title'; } else { $t =($_POST['title']); } // Check for a last name. if (empty($_POST['description'])) { $errors[] = 'You forgot to enter the description.'; } else { $d =($_POST['description']); } // Check for a last name. if (empty($_POST['price'])) { $errors[] = 'You forgot to enter the price.'; } else { $p =($_POST['price']); } if (empty($errors)) { // If everything's OK. $result = mysql_query($query)or die(mysql_error());; if (mysql_num_rows($result) == 0) { // make query $query = "UPDATE foods SET title='$t', description='$d', price='$p' WHERE food_id=$id"; $result = @mysql_query($query) or die(mysql_error()); if (mysql_affected_rows()==1) {// if ran ok //print message echo '<h1> Edit Food</h1> <p>The food has been updatted</p><p><br /><br /></p>'; } else { //if it did not run ok echo '<h1> System error</h1> <p>Sorry there has been an error and the food could not be updated. sorry</p>'; echo '<p>' . mysql_error() .'<br /><br />Problem:' . $query . '</p>';// debugging message //include ('footer.php') exit(); } }else{ echo '<h1>sorry your food has been updated already</h1>'; } } else { //report the errors echo '<h1>Error!</h1> <p>The follow errors have occurred:<br />'; foreach ($errors as $msg){//print each message echo "-$msg<br />\n"; } echo'</p><p>Please try again.</p><p><br /></p>'; }//end of if }
  13. sorry i am so stuiped i just missed that all out..........
  14. is there any chance you can point me in correct direction, in my code to help me wright that code in so it works.
  15. i am not sure why it won't pick up the id from but it is now starting to get to me so could someone please have a look at this code and maybe tell me where i am going wrong i have 2 pages one where the user can change the oprion in a menu sytem and one where it retives the data using the $id. hear is the code and the user id from the <?php //retrive the users information $query = "SELECT food_id, title, description, price FROM foods WHERE food_id=$id"; $result = @mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) == 1){//valid id show form //get the users information $row = mysql_fetch_array($result, MYSQL_NUM); hear is the id it is ment to pick up http://localhost//edit_food.php?id=43 so what to do can you help
  16. and my mysql server is 5.0 so i am installing the new version which is 5.1.30 i will get back to if no change
  17. just not sure what you mean i am running apachi mysql. i have opened up the command line for mysql entered mysql --version just comes up with and error. how do u access apachi command line if i need to
  18. well i did the phpifo(); and i got 5.0.45 i then tried finding my mysql version but i just could not find it what do u think i should do. reverting back to my code if that's not the issue. i tried the query in command line and it worked if i put the id number in. so i see the problem being because it does not seem to want to pull the info out as a varable. what do u think the issue could be
  19. i am working on a script where a user can edit information on there menu. this is how it works. they log in and are able to view there menu with a edit button next to every item in there menu. they click and it moved to the edit page. hear is my problem i am trying to gather the info mation from the item they have chosen using the $id as a key so the info can be pulled out. this is my problem i can't seem to get the query correct. could you have a look and see if you can spot what i am missing //retrive the users information <?php $query = "SELECT food_id, title, description, price FROM foods WHERE food_id=$id"; $result = @mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) == 1){//valid id show form //get the users information $row = mysql_fetch_array($result, MYSQL_NUM); //create the form echo '<h2> Edit Food. <form action="edit_food.php" method="post"> <p>Title: <input type="text" name="title" size="20" maxlength="20" value="'. $row[0] .'" /></p> <p>Description: <input type="text" name="description" size="15" maxlength="30" value="' . $row[1] . '" /></p> <p>Price: <input type="text" name="price" size="20" maxlength="40" value="' . $row[2] . '" /> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> </form>'; this is the error message i get 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 thanks for any help
  20. i have 2 tables which need to be updated 1 called food and another food_associations. i want to update the fields in both so when the user views the info they will see there update. sorry i am very tired i will show you the whole script <?php require_once ('mysql_connect.php'); //connect to the database // check the form has been submitted if (isset($_POST['submitted'])) { //check for title if (!empty($_POST['title'])) { $t = ($_POST['title']); } else { $t = FALSE; echo '<p><font color="red">Please enter a food name.</font></p>'; } //check for food description if (!empty($_POST['description'])) { $d =($_POST['description']); } else { $d = FALSE; echo '<p><font color="red">Please enter a description of the food.</font></p>'; } //check for food category if (isset($_POST['types']) && (is_array($_POST['types']))) { $type = TRUE; } else { $type = FALSE; echo '<p><font color="red"> Please select one category.</font></p>'; } //check food price if (!empty($_POST['price'])) { $p = ($_POST['price']); } else { $p = FALSE; echo '<p><font color="red">Please enter a price</font></p>'; } $result = mysql_query($query)or die(mysql_error());; if (mysql_num_rows($result) == 0) { // make query $query = "UPDATE menu SET title='$t', description='$t', price='$p' AS f, food_associations AS fa WHERE f.food_id = fa.food_id AND food_cat_id=$id"; $result = @mysql_query($query) or die(mysql_error()); if (mysql_affected_rows()==1) {// if ran ok //print message echo '<h1> Edit Food</h1> <p>The food has been updatted</p><p><br /><br /></p>'; } else { //if it did not run ok echo '<h1> System error</h1> <p>Sorry there has been a system error and the food could not be updated. sorry</p>'; echo '<p>' . mysql_error() .'<br /><br />Problem:' . $query . '</p>';// debugging message //include ('footer.php') exit(); } } else { //report the errors echo '<h1>Error!</h1> <p>The follow errors have occurred:<br />'; foreach ($errors as $msg){//print each message echo "-$msg<br />\n"; } echo'</p><p>Please try again.</p><p><br /></p>'; }//end of if } //always show the form //retrive the users information $query = "SELECT f.food_id, title, description, price FROM foods AS f, food_associations AS fa WHERE f.food_id = fa.food_id AND fa.food_cat_id=$type"; $result = @mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) == 1){//valid id show form //get the users information $row = mysql_fetch_array($result, MYSQL_NUM); //create the form echo '<h2> Edit Food. <form action="edit_food.php" method="post"> <p>Title: <input type="text" name="title" size="20" maxlength="20" value="". $row[0] ."" /></p> <p>Description: <input type="text" name="description" size="15" maxlength="30" value="' . $row[1] . '" /></p> <p>Price: <input type="text" name="price" size="20" maxlength="40" value="' . $row[2] . '" /> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> </form>'; } else { // Not a valid user ID. echo '<h1>Page Error</h1> <p>This page has been accessed in error.</p><p><br /><br /></p>'; } mysql_close(); // Close the database connection. ?> i want it to display the info that they are tring to change and then once its changed to update the database.
  21. i am not sure if the update query i am using is correct as i am not able to find the error any chance you coul have a look $result = mysql_query($query)or die(mysql_error());; if (mysql_num_rows($result) == 0) { // make query $query = "UPDATE menu SET title='$t', description='$t', price='$p' AS f, food_associations AS fa WHERE f.food_id = fa.food_id AND food_cat_id=$id"; $result = @mysql_query($query) or die(mysql_error()); if (mysql_affected_rows()==1) {// if ran ok //print message echo '<h1> Edit Food</h1> <p>The food has been updatted</p><p><br /><br /></p>'; all help welcome
  22. hi again i am working on the same script but trying to update instead of selecting. my problem is that i have 2x sql code and i am not sure if i am hedding down the correct road to victory. the first set of sql code is trying to update and i feel like i am not in corporating the 2 tables need to be updated. and the second is just trying to select the info to show the user. because there is two sets of code i am just not sure where the issues are: // check the form has been submitted if (isset($_POST['submitted'])) { //check for title if (!empty($_POST['title'])) { $t = ($_POST['title']); } else { $t = FALSE; echo '<p><font color="red">Please enter a food name.</font></p>'; } //check for food description if (!empty($_POST['description'])) { $d =($_POST['description']); } else { $d = FALSE; echo '<p><font color="red">Please enter a description of the food.</font></p>'; } //check for food category if (isset($_POST['types']) && (is_array($_POST['types']))) { $type = TRUE; } else { $type = FALSE; echo '<p><font color="red"> Please select one category.</font></p>'; } //check food price if (!empty($_POST['price'])) { $p = ($_POST['price']); } else { $p = FALSE; echo '<p><font color="red">Please enter a price</font></p>'; } $result = mysql_query($query); if (mysql_num_rows($result) == 0) { // make query $query = "UPDATE title='$t', description='$t', price='$p' AS f, food_associations AS fa WHERE f.food_id = fa.food_id AND food_cat_id=$id"; $result = @mysql_query($query) or die(mysql_error()); if (mysql_affected_rows()==1) {// if ran ok //print message echo '<h1> Edit Food</h1> <p>The food has been updatted</p><p><br /><br /></p>'; } else { //if it did not run ok echo '<h1> System error</h1> <p>Sorry there has been a system error and the food could not be updated. sorry</p>'; echo '<p>' . mysql_error() .'<br /><br />Problem:' . $query . '</p>';// debugging message //include ('footer.php') exit(); } } else { //report the errors echo '<h1>Error!</h1> <p>The follow errors have occurred:<br />'; foreach ($errors as $msg){//print each message echo "-$msg<br />\n"; } echo'</p><p>Please try again.</p><p><br /></p>'; }//end of if } //always show the form //retrive the users information $query = "SELECT f.food_id, title, description, price FROM foods AS f, food_associations AS fa WHERE f.food_id = fa.food_id AND fa.food_cat_id=$type"; $result = @mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) == 1){//valid id show form //get the users information $row = mysql_fetch_array($result, MYSQL_NUM); please any advice will help thanks
  23. you have to be kidding, it works thanks for the quick responce.
  24. 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 'WHERE food_id = fa.food_id AND fa.food_cat_id=1, AND fa.approved = 'Y' ORDER B' at line 2 hope that helps
×
×
  • 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.