baccarak Posted November 14, 2010 Share Posted November 14, 2010 I confess I am not a php coder but have managed to build a youtube player which plays from a list which is generated by a flat file data base. http://www.d-sine.com/DEV/CHW/movies/index.php I have also (nearly) built an admin backend where users can edit the database and add, delete and update their movie player list. http://www.d-sine.com/DEV/CHW/movies/admin/ pass = password the problem I have is that when the list is edited it throws in a return (a blank line) into the database resulting in an error when the player is refreshed after the change. When this blank line is taken out all is fine, I have got so close its frustrating arrrgghh Can anyone help??? The code in full is attatched Open Source, so if it is any use to anyone, be my guest ;-) [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 14, 2010 Share Posted November 14, 2010 before inserting/updating your database, trim() the string values. that should remove any line feeds/carriage returns on the end of the string. Quote Link to comment Share on other sites More sharing options...
baccarak Posted November 14, 2010 Author Share Posted November 14, 2010 Thank you for your prompt reply. trim() does look like the answer but I have not got a clue where to add this. This is the code to display the player: <?php $recordset = explode("\n",$recordfile); echo"<br><div id='trailer'><center>"; echo"<div id='nwrap'><div id='trnav'>"; foreach ($recordset as $record){ list( $MDIV, $MYOUTUBE, $MTITLE ) = explode("|", $record); if (!empty($record)){ echo"<li><a href='#' onclick='return playVideo(\"selectDemo$MDIV\",\"videoPlayback\")'>$MTITLE</a></li>"; } } echo" </div><br /><a href='admin/index.php' target='_blank'><img src='ig/admin.png' border='0' /></a></div><div id='videoPlayback' class='vids'></div><div style='clear:both;'></div></center></div>"; foreach ($recordset as $record){ list( $MDIV, $MYOUTUBE, $MTITLE ) = explode("|", $record); if (!empty($record)){ echo "<div id='selectDemo$MDIV'style='display: none'>"; echo "<object width='480' height='385'><param name=movie value='http://www.youtube.com/v/$MYOUTUBE&hl=en_GB&fs=fs=1&color1=0x234900&color2=0x4e9e00'></param><param name=allowFullScreen value=true></param><param name=allowscriptaccess value=always></param><embed src=http://www.youtube.com/v/$MYOUTUBE&hl=en_GB&fs=1& type=application/x-shockwave-flash allowscriptaccess=always allowfullscreen=true width='480' height='385'></embed></object></div>"; echo"\r"; } } ?> Quote Link to comment Share on other sites More sharing options...
baccarak Posted November 14, 2010 Author Share Posted November 14, 2010 added trim() to player does not work ;-( tx anyway list( $MDIV, $MYOUTUBE, $MTITLE ) = explode("|", trim($record)); admin.php <?php require_once('inc/settings.php'); ?> <?php session_start(); define('ADMIN_PASS', $adminpassword ); $admin_password = isset($_COOKIE['admin_password']) ? $_COOKIE['admin_password'] : ''; if (empty($admin_password)) { if (isset($_POST['admin_password'])) { $admin_password = md5($_POST['admin_password']); if ($admin_password == md5(ADMIN_PASS)) { setcookie('admin_password', $admin_password); } } } if (!file_exists($database)) { echo "<html><head><link href=\"css/adm.css\" rel=\"stylesheet\" type=\"text/css\">"; echo "</head><body><center><div class=\"message\">"; echo "<h2>Movie database not found!</h2>"; echo "<br><br><br><br><FORM><INPUT type=image src=\"ig/return.png\" value=\"Back\" onClick=\"history.back();\"></FORM>";echo "</div></center>"; echo "</body></html>"; exit; } $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : ''; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; $divnumbers = array(); $youtubes = array(); $movienames = array(); $count = 0; $userindex = -1; $items = file($database); foreach($items as $line) { list( $divnumber, $youtube, $moviename ) = explode('|', trim($line)); $divnumbers[$count] = $divnumber; $youtubes[$count] = $youtube; $movienames[$count] = $moviename; if ($id == $moviename) { $userindex = $count; } $count++; } if (!empty($action)) { if ($action == 'delete') { if ($userindex == -1) { echo "<html><head><link href=\"css/adm.css\" rel=\"stylesheet\" type=\"text/css\">"; echo "</head><body><center><div class=\"message\">"; echo "<h2>Movie not found!</h2>"; echo "<br><br><br><br><FORM><INPUT type=image src=\"ig/return.png\" value=\"Back\" onClick=\"history.back();\"></FORM>";echo "</div></center>"; echo "</body></html>"; exit; } $file = fopen($database, 'w'); for ($i=0; $i < $count; $i++) { if ($i != $userindex) { fwrite($file, $divnumbers[$i]); fwrite($file, '|'); fwrite($file, $youtubes[$i]); fwrite($file, '|'); fwrite($file, $movienames[$i]); fwrite($file, "\r\n"); } } fclose($file); header('Location: '.basename(__FILE__)); exit; } else if ($action == 'update') { $file = fopen($database, 'w'); for ($i=0; $i < $count; $i++) { if ($i == $userindex) { $divnumbers[$i] = $_POST['divnumber']; $youtubes[$i] = $_POST['youtube']; $movienames[$i] = $_POST['moviename']; } fwrite($file, $divnumbers[$i]); fwrite($file, '|'); fwrite($file, $youtubes[$i]); fwrite($file, '|'); fwrite($file, $movienames[$i]); fwrite($file, "\r\n"); } fclose($file); header('Location: '.basename(__FILE__)); exit; } else if ($action == 'create') { for ($i=0; $i < $count; $i++) { if ($movienames[$i] == $_POST['divnumber']) { echo "<html><head><link href=\"css/adm.css\" rel=\"stylesheet\" type=\"text/css\">"; echo "</head><body><center><div class=\"message\">"; echo "<h2>ID Number already exists!</h2>"; echo "<br><br><br><br><FORM><INPUT type=image src=\"ig/return.png\" value=\"Back\" onClick=\"history.back();\"></FORM>";echo "</div></center>"; echo "</body></html>"; exit; } } $file = fopen($database, 'a'); fwrite($file, $_POST['divnumber']); fwrite($file, '|'); fwrite($file, $_POST['youtube']); fwrite($file, '|'); fwrite($file, $_POST['moviename']); fwrite($file, "\r\n"); fclose($file); header('Location: '.basename(__FILE__)); exit; } else if ($action == 'logout') { session_unset(); session_destroy(); setcookie('admin_password', '', time() - 3600); header('Location: '.basename(__FILE__)); exit; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <link href="css/adm.css" rel="stylesheet" type="text/css"> <title>Movie administrator</title> </head> <body><center> <div id="ctop"></div><div id="cmid"> <?php if ($admin_password != md5(ADMIN_PASS)) { echo "<center><br>\n"; echo "<h2>Movie Administrator Login</h2>\n"; echo "<form method=\"post\" action=\"" .basename(__FILE__) . "\">\n"; echo "Admin Password: <input type=\"text\" name=\"admin_password\" size=\"20\" /><br><br>\n"; echo "<input type=\"image\" src=\"ig/login.png\" value=\"Login\" name=\"submit\" />\n"; echo "</form>\n"; echo "</center>\n"; } else { if (!empty($action)) { if (($action == 'edit') || ($action == 'new')) { $divnumber_value = ($userindex == -1) ? "" : $divnumbers[$userindex]; $youtube_value = ($userindex == -1) ? "" : $youtubes[$userindex]; $moviename_value = ($userindex == -1) ? "" : $movienames[$userindex]; echo "<center><br>\n"; echo "<h2>Add New Movie</h2>\n"; echo"<ul class='info'>"; echo"<li><strong>Div No</strong>: This number must be unique with <strong>no</strong> duplicates </li>"; echo"<li><strong>Youtube No:</strong> (example) http://www.youtube.com/watch?v=<strong>b5tTl9SF4I8 </strong> << this number is needed </li>"; echo"<li><strong>Movie Name:</strong> Enter Description <strong>(maximum of 35 characters)</strong> </li>"; echo"<li><strong>Action:</strong> Add, Edit or Delete Movie Selection </li>"; echo"</ul>"; echo "<form action=\"" . basename(__FILE__) . "\" method=\"post\">\n"; echo "<table cellspacing=\"0\" cellpadding=\"5\" class=\"admin\">\n"; if ($action == 'new') { echo "<input type=\"hidden\" name=\"action\" value=\"create\">\n"; } else { echo "<input type=\"hidden\" name=\"action\" value=\"update\">\n"; } echo "<input type=\"hidden\" name=\"id\" value=\"". $id . "\">\n"; echo "<tr><td class='bo'>Div No:</td>\n"; echo "<td><input type=\"text\" size=\"10\" name=\"divnumber\" value=\"" . $divnumber_value . "\"></td></tr>\n"; echo "<tr><td class='bo'>Youtube No: </td>\n"; echo "<td><input type=\"text\" size=\"30\" name=\"youtube\" value=\"" . $youtube_value . "\"></td></tr>\n"; echo "<tr><td class='bo'>Movie Name: </td>\n"; echo "<td><input type=\"text\" size=\"60\" name=\"moviename\" value=\"" . $moviename_value . "\"></td></tr>\n"; echo "</table>"; echo "<div align=\"center\" class='nav'><input type=\"image\" src=\"ig/save.png\" name=\"cmdSubmit\" value=\"Save\">"; echo " "; echo "<input type=\"image\" src=\"ig/reset.png\" name=\"cmdReset\" value=\"Reset\"> "; echo "<input type=\"image\" name=\"cmdBack\" src=\"ig/back-s.png\" border=\"0\" value=\"Back\"OnClick=\"location.href='" . basename(__FILE__) . "'\"></div>\n"; echo "</form>\n"; echo "<center><br>\n"; } } else { echo "<center><br>\n"; echo "<h2>Movie Administration</h2>\n"; echo"<ul class='info'>"; echo"<li><strong>Div No</strong>: This number must be unique with <strong>no</strong> duplicates </li>"; echo"<li><strong>Youtube No:</strong> (example) http://www.youtube.com/watch?v=<strong>b5tTl9SF4I8 </strong> << this number is needed </li>"; echo"<li><strong>Movie Name:</strong> Enter Description <strong>(maximum of 35 characters)</strong> </li>"; echo"<li><strong>Action:</strong> Add, Edit or Delete Movie Selection </li>"; echo"</ul>"; echo "<table cellspacing=\"0\" cellpadding=\"5\" class=\"admin\">\n"; echo "<th width=100>No</th>\n"; echo "<th width=200>Youtube No</th>\n"; echo "<th>Movie Name</th>\n"; echo "<th width=200>Action</th></tr>\n"; for ($i=0; $i < $count; $i++) { echo "<tr>\n"; echo "<td><center>" . $divnumbers[$i] . "</center></td>\n"; echo "<td>" . $youtubes[$i] . "</td>\n"; echo "<td>" . $movienames[$i] . "</td>\n"; echo "<td>\n"; echo "<center><a href=\"" . basename(__FILE__) . "?action=edit&id=" . $movienames[$i] . "\"><img src='ig/edit-s.png' border=0></a>\n"; echo "<a href=\"" . basename(__FILE__) . "?action=delete&id=" . $movienames[$i] . "\"><img src='ig/delete-s.png' border=0 ></a></center>\n"; echo "</td>\n"; echo "</tr>\n"; } echo "</table>\n"; echo "<div class='nav'><a href=\"" . basename(__FILE__) . "?action=new\"><img src='ig/addmovie.png' border=0></a> <a href=\"http://www.youtube.com\" target='_blank'><img src='ig/youtube.png' alt='youtube' border='0' /></a> <a href=\"" . basename(__FILE__) . "?action=logout\"><img src='ig/logout.png' border=0></a></div>\n"; } } ?><br></div><div id="cbtm"></div></center></body> </body> </html> Quote Link to comment Share on other sites More sharing options...
baccarak Posted November 15, 2010 Author Share Posted November 15, 2010 Fixed - thanks for looking Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.