Jump to content

marksie1988

Members
  • Posts

    225
  • Joined

  • Last visited

Everything posted by marksie1988

  1. ok i have a form which when fields on it are eidted it should update a mysql talbe the code is below all i can think is that my part in adminprocess.tcos that has the update mysql in it is incorrect. please advice MySQL Table TABLE `songs` ( `id` int(10) unsigned NOT NULL auto_increment, `postdate` int(11) default NULL, `title` varchar(50) NOT NULL, `length` time NOT NULL default '00:00:00', `link` varchar(200) NOT NULL, `lyrics` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; there is a form which the user selects the song name to go to the edit page. that form works ok. Form (song_edit.tcos) <? /** * Admin.tcos */ include("include/session.tcos"); /** * User not an administrator, redirect to main page * automatically. */ if(!$session->isAdmin()){ header("Location: index.tcos"); } else{ /** * Administrator is viewing page, so display all * forms. */ ?> <html> <body> <h1>Song Actions please do not use yet!!</h1> <font size="5" color="#ff0000"> <b>::::::::::::::::::::::::::::::::::::::::::::</b></font> <font size="4">Logged in as <b><? echo $session->username; ?></b></font><br><br> Back to [<a href="index.tcos">Main Page</a>]<br><br> <? if($form->num_errors > 0){ echo "<font size=\"4\" color=\"#ff0000\">" ."!*** Error with request, please fix</font><br><br>"; } ?> <table align="left" border="0" cellspacing="5" cellpadding="5"> <?php if(ctype_digit($_GET['id'])) $song_id = $_GET['id']; else $article_id = 0; $query = "SELECT * FROM `songs` WHERE `id` = '" . $song_id . "' LIMIT 1;"; $result = mysql_query($query); if(mysql_num_rows($result) == 0) { echo "<h5 class=\"style2\">There are no songs with this id</h5>"; } else{ while ($row = mysql_fetch_assoc ($result)) { ?> <h3>Edit Song</h3> <? echo $form->error("editsong"); ?> <form action="adminprocess.tcos" method="POST"> Title:<br> <input type="text" name="title" maxlength="50" value="<?php echo "$row[title]";?>"><br> Length:<br> <input type="text" name="length" maxlength="50" value="<?php echo "$row[length]";?>"><br> Song Link (http://songlocation):<br> <input type="text" name="link" value="<?php echo "$row[link]";?>"><br> Lyrics:<br> <textarea rows="20" cols="90" name="lyrics"><?php echo "$row[lyrics]";?></textarea><br> <input type="hidden" name="subeditsong" value="1"> <input type="submit" value="Edit Song!"> </form> <?php } } ?> </table> </body> </html> <? } ?> process (adminprocess.tcos) this is where the form is directed to update. <? /** * AdminProcess.php * * The AdminProcess class is meant to simplify the task of processing * admin submitted forms from the admin center, these deal with * member system adjustments. * * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC) * Last Updated: August 15, 2004 */ include("include/session.tcos"); class AdminProcess { /* Class constructor */ function AdminProcess(){ global $session; /* Make sure administrator is accessing page */ if(!$session->isAdmin()){ header("Location: ../main.php"); return; } /* Admin submitted delete user form */ else if(isset($_POST['subdeluser'])){ $this->procDeleteUser(); } /* Admin submitted add news form */ else if(isset($_POST['subaddnews'])){ $this->procaddnews(); } /* Admin submitted delete news form */ else if(isset($_POST['subdelnews'])){ $this->procDeletenews(); } /* Admin submitted add song form */ else if(isset($_POST['subaddsong'])){ $this->procaddsong(); } /* Admin submitted edit song form */ else if(isset($_POST['subeditsong'])){ $this->proceditsong(); } /* Admin submitted change welcome form */ else if(isset($_POST['subwelcome'])){ $this->procwelcome(); } /* Should not get here, redirect to home page */ else{ header("Location: ../main.php"); } } /** * procDeleteUser - If the submitted username is correct, * the user is deleted from the database. */ function procDeleteUser(){ global $session, $database, $form; /* Username error checking */ $subuser = $this->checkUsername("deluser"); /* Errors exist, have user correct them */ if($form->num_errors > 0){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } /* Delete user from database */ else{ $q = "DELETE FROM ".TBL_USERS." WHERE username = '$subuser'"; $database->query($q); header("Location: ".$session->referrer); } } /** * procaddnews */ function procaddnews(){ global $session, $database, $form; /* Errors exist, have user correct them */ if($form->num_errors > 0){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } else{ $q = "INSERT INTO ".TBL_NEWS." (id, postdate, title, newstext) VALUES ('null', UNIX_TIMESTAMP() , '$_POST[title]', '$_POST[newstext]')"; $database->query($q); header("Location: ".$session->referrer); } } /** * procaddsong */ function procaddsong(){ global $session, $database, $form; /* Errors exist, have user correct them */ if($form->num_errors > 0){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } else{ $q = "INSERT INTO ".TBL_SONGS." (id, postdate, title, length, link, lyrics) VALUES ('null', UNIX_TIMESTAMP() , '$_POST[title]', '$_POST[length]', '$_POST[link]', '$_POST[lyrics]')"; $database->query($q); header("Location: ".$session->referrer); } } /** * proceditsong */ function proceditsong(){ $this->time = time(); global $session, $database, $form; if($form->num_errors > 0){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } else{if(ctype_digit($_GET['id'])) $article_id = $_GET['id']; else $article_id = 0;$query = "SELECT * FROM `songs` WHERE `id` = '" . $article_id . "' LIMIT 1;"; $result = mysql_query($query); if(mysql_num_rows($result) == 0) { echo "<h5 class=\"style2\">There is no news with this article id</h5>"; } else{ while ($row = mysql_fetch_assoc ($result)) { mysql_query("UPDATE songs SET title = '$_POST[title]' WHERE id = '" . $article_id . "' "); mysql_query("UPDATE songs SET length = '$_POST[length]' WHERE id = '" . $article_id . "' "); header("Location: ".$session->referrer); } } } /** * procwelcome */ function procwelcome(){ $this->time = time(); global $session, $database, $form; if($form->num_errors > 0){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } else{ mysql_query("UPDATE welcome SET welcome = '$_POST[welcome]' WHERE title = 'welcome'"); mysql_query("UPDATE welcome SET timestamp = UNIX_TIMESTAMP() WHERE title = 'welcome'"); header("Location: ".$session->referrer); } } /** * procDeletenews - If the submitted username is correct, * the user is deleted from the database. */ function procDeletenews(){ global $session, $database, $form; if($form->num_errors > 0){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } else{ mysql_query("DELETE FROM news WHERE title = '$_POST[delnews]'"); header("Location: ".$session->referrer); } } /** * checkUsername - Helper function for the above processing, * it makes sure the submitted username is valid, if not, * it adds the appropritate error to the form. */ function checkUsername($uname, $ban=false){ global $database, $form; /* Username error checking */ $subuser = $_POST[$uname]; $field = $uname; //Use field name for username if(!$subuser || strlen($subuser = trim($subuser)) == 0){ $form->setError($field, "* Username not entered<br>"); } else{ /* Make sure username is in database */ $subuser = stripslashes($subuser); if(strlen($subuser) < 5 || strlen($subuser) > 30 || !eregi("^([0-9a-z])+$", $subuser) || (!$ban && !$database->usernameTaken($subuser))){ $form->setError($field, "* Username does not exist<br>"); } } return $subuser; } }; /* Initialize process */ $adminprocess = new AdminProcess; ?> this is the code i think is giving me the problem i think ive made a total mess of it. /** * proceditsong */ function proceditsong(){ $this->time = time(); global $session, $database, $form; if($form->num_errors > 0){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } else{if(ctype_digit($_GET['id'])) $article_id = $_GET['id']; else $article_id = 0;$query = "SELECT * FROM `songs` WHERE `id` = '" . $article_id . "' LIMIT 1;"; $result = mysql_query($query); if(mysql_num_rows($result) == 0) { echo "<h5 class=\"style2\">There is no news with this article id</h5>"; } else{ while ($row = mysql_fetch_assoc ($result)) { mysql_query("UPDATE songs SET title = '$_POST[title]' WHERE id = '" . $article_id . "' "); mysql_query("UPDATE songs SET length = '$_POST[length]' WHERE id = '" . $article_id . "' "); header("Location: ".$session->referrer); } } } please help me out as this is one of the last things i need to do for the website to function fully Thanks Steve
  2. would it be possible to select the song title from the dropdown and then on select get the id and go to an edit page edit_song.php?id=23 then when the fields are changed and submit is selected it will update the row with id 23 i think this should be possible but i dont know much about dropdown menu's so i wouldnt know how to tell it to get the id and then go to the edit page please help i really need this now
  3. ok but how would i do this ? any example code?
  4. does nobody know how i can do this i cannot find anything about this on the net please help me or tell me if it isnt possible
  5. if you do it like that you may run the risk of one month noone donates and then your out of pocket your probably better off taking donations all the time and then have it saved up for the server and just dont spend it
  6. ok i got the dropdown working by using the following code <?php $res = mysql_query("SELECT * FROM songs ORDER BY title") or die("Invalid query: " . mysql_query()); echo '<label>Select value:</label>'; echo '<select id="song" name="song">'; echo '<option value="">Select</option>'; while ($row = mysql_fetch_assoc($res)) { $va = $row['title']; echo "<option value='$va'>$va</option>"; } echo '</select>'; ?> but how could i use this so that when an admin selects a song title they can view lyrics to edit them ? (lyrics column is called lyrics)
  7. is it possible to show a column from mysql in a dropdown and then when that row is selected to display the information in an editable form ?? if you dont understand i can try explain in more detail
  8. does no body know how i can do this?? please help me out here? Thanks
  9. ok i have a script which shows news on my webpage when a user clicks a link from my rss feed. but if the news has any links within it it will not link them why is this? i think i need to change this row $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>')); but i dont know what to... here is the full php so you can understand the script. <?php if(ctype_digit($_GET['id'])) $article_id = $_GET['id']; else $article_id = 0; $query = "SELECT * FROM `news` WHERE `id` = '" . $article_id . "' LIMIT 1;"; $result = mysql_query($query); if(mysql_num_rows($result) == 0) { echo "<h5 class=\"style2\">There is no news with this article id</h5>"; } else{ while ($row = mysql_fetch_assoc ($result)) { /* place table row data in * easier to use variables. * Here we also make sure no * HTML tags, other than the * ones we want are displayed */ $date = date("D d M Y h:i:s e", $row['postdate']); $title = htmlentities ($row['title']); $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>')); /* display the data */ $td = "<td align=\"left\" >"; $ttl = "align=\"center\" style=\"font-size:13px; color:#ffffff; font-family:tahoma\""; $dte = "align=\"center\" style=\"font-size:10px; color:#CA3C30; font-family:tahoma\""; $nws = "align=\"center\" style=\"font-size:12px; color:#999999; font-family:tahoma\""; echo "<strong $ttl> \n $title </strong>\n <br>\n"; echo "<strong $dte> \n $date </strong>\n <br><br>\n"; echo "<strong $nws> \n $news </strong>\n <br><br>\n"; } } ?> help would be appreciated
  10. OMG i cant belive i didnt notice that sometimes i wonder what my mind is doing to me i totaly disreguarded the isset command Cheers
  11. Hi, i have written some code that i want to display an image but only if a field in my sql has information in it i currently have: if($req_user_info['Skype'] > 0){ /* Skype */ echo "<a href='callto://".$req_user_info['Skype'] ."'><img src='../images/icons/skype.gif' border='0'/></a>"; } elseif($req_user_info['myspace'] > 0){ /* myspace */ echo "<a href='http://".$req_user_info['myspace'] ."'><img src='../images/icons/myspace.gif' border='0'/></a>";} else{echo "No Extras";} i think that the problem is if($req_user_info['myspace'] > 0){ ^^^ should i be saying is greater than 0 or not? im new to this so please help.
  12. i have done all of the above and when i run php.exe it shows no errors but then when i look at phpinfo no mysql showing up the dll is there and i have told the php ini to load php_mysql.dll what do you mean by do you mean add the windows path for iis into the php.ini file if so i have done this if not what do you mean?
  13. im setting up a webserver at work on IIS 5.1 using php and mysql i got php working but when i use the mysql extension php shows no errors on loading but phpmyadmin says phpMyAdmin - Error Cannot load mysql extension. Please check your PHP configuration. - Documentation but the extension is deffinatly there. (i can run phpinfo but no mysql info is shown)
  14. can this also be done for different servers that arent running on php? all i could think of is that it would need to ping the pc and record it say every 5 minutes and then use those recordings to work out a percentage for a certain ammount of time
  15. hey, is there a way that i can monitor the uptime with a percentage of servers? i basically am setting up an intranet and would like people to know what the uptime of the server is i know that there are products out there that do this but they all monitor web services and linux machines, but i need it to monitor multiple windows servers and turn it into a percentage can use php and mysql or mssql if required if anyone knows of a FREE script that does this or could let me know how i could do this that would be great as i dont have a clue Cheers
  16. oops sorry they are declaired further up in the script but i have had to remove this feature as i need the script to work now but i am going to setup a test bed and try it again another time
  17. Hi, i have created a registration script for my website and i have added a new featurer that makes you enter your email address twice and then it is supposed to check if they are the same and then if they are submit the form but if not show an error but even if the email addresses are the same it still shows the error below is the code for the email checking /* Email error checking */ $field = "email"; //Use field name for email $field2 = "email2";// Second field for email if(!$subemail || strlen($subemail = trim($subemail)) == 0){ $form->setError($field, "* Email not entered"); elseif(!$subemail2 || strlen($subemail2 = trim($subemail2)) == 0){ $form->setError($field, "* Confirm Email not entered"); } else{ /* Check if valid email address */ $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$subemail)){ $form->setError($field, "* Email invalid"); } else if ($subemail !== $subemail2){ $form->setError($field2, "* Emails does not match"); } $subemail = stripslashes($subemail); } Cheers
  18. well good i didnt know how to do that thankyou for teaching me that im learning so much from this site its great
  19. i get nothing no errors or anything and how do i echo the querys :S sorry ive just never done that
  20. Could someone tell me how i get a column from a row and if that column has yes to show it but if not then dont show it? basically if(['sold'] == yes){ show any rows with yes in the sold column } else{ show nothing } i basically want to show sold items and then have another script the other way around which shows available ones so ones with no in the sold column please help with me starting it off all i need is the first bit then ill figure it out Thanks Steve
  21. using php and mysql how can i tell the my website to move any entry older than 30 days to a different table and then delete it below i have some script i did try but this doesnt work (im using unix timestamp incase that changes anything) mysql_query(" INSERT INTO newsarchive (id, postdate, title, newstext) SELECT id, postdate, title, newstext FROM news WHERE postdate < DATE_SUB(curdate(), INTERVAL 30 DAY)"); mysql_query("DELETE FROM news WHERE postdate < DATE_SUB(curdate(), INTERVAL 30 DAY)"); mysql_close($link); //clean up
  22. ok i have an access database that uses tables from a mysql database to update information on my website. but i use the unixtimestamp to show the time and date this was implemented, how do i tell my access forms to put in the current unix timestamp when i update something?
  23. ok tried <form method=post action="<?php echo "$_SERVER['PHP_SELF']"; ?>"> didnt work so i tried <form method=post action="<?php echo $_SERVER['PHP_SELF']; ?>"> that worked but when i insert test order number and test postcode it doesnt return anything test order number is: 123456789 test postcode is: ls8 1bu i get the following error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/marksie/public_html/blacklime/track/check.php on line 11 There are no repaits in the database for that postcode and order number.SELECT * FROM repair ORDER BY status postdate DESC WHERE on ='123456789' postcode ='ls8 1bu' and the php is now <?php $db =mysql_connect ("localhost","dbuser","dbpass"); mysql_select_db("dbname",$db); $on = $_POST['on']; $post = $_POST['postcode']; if($on && $post) { // query DB $sql = "SELECT * FROM repair ORDER BY status postdate DESC WHERE on ='$on' postcode ='$post'"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0){ while($row=mysql_fetch_array($result)){ echo "Date Submitted: $row[postdate]<br>"; echo "Order Number: $row[on]<br>"; echo "Postcode: $row[postcode]<br><br>"; echo "Status: $row[status]<br><br>"; echo "Comments: $row[comments]<br><br>"; echo "Technician: $row[technician]<br><br>"; echo "Due By: $row[dueby]<br><br>"; } }else{ echo "There are no repaits in the database for that postcode and order number."; } //display data }else{ //display form ?> <form method=post action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p> Order number: <input type="text" name="on"> </p> <p>Postcode: <input type="text" name="postcode"> </p> <p> <input type="submit"> </p> </form> <?php } echo $sql ?>
  24. ok so i have looked around and i got how to do the if statement u use && instead of + but my form still returns nothing here is the code <?php $db =mysql_connect ("localhost","dbuser","dbpass"); mysql_select_db("db to use",$db); if($on && $post) { // query DB $sql = "SELECT * FROM repair ORDER BY status postdate DESC WHERE on ='$on' post ='$post'"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0){ while($row=mysql_fetch_array($result)){ echo "Date Submitted: $row[postdate]<br>"; echo "Order Number: $row[on]<br>"; echo "Postcode: $row[postcode]<br><br>"; echo "Status: $row[status]<br><br>"; echo "Comments: $row[comments]<br><br>"; echo "Technician: $row[technician]<br><br>"; echo "Due By: $row[dueby]<br><br>"; } }else{ echo "There are no repaits in the database for that postcode and order number."; } //display data }else{ //display form ?> <form method=post action="<?php echo $PHP_SELF?>"> <p> Order number: <input type="text" name="order number"> </p> <p>Postcode: <input type="text" name="postcode"> </p> <p> <input type="submit"> </p> </form> <?php } echo $sql ?> i have the code uploaded here http://blacklimecomputers.co.uk/track/check.php when i look at the source it seems that the form doesnt know to action to itself any ideas what i can do???
×
×
  • 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.