richardjh Posted October 3, 2008 Share Posted October 3, 2008 Hello Fine people. I have a script that allows users to enter text, preview the text and then submit to a mysql database. The script worked fine on my previous hosts server. But now I have moved hosts and the thing just wont work. what should happen (and indeed did on the old server): User types text and choses options from two dropdowns. They click preview and they see a preview of their text etc. which they can edit and preview again... when happy with the text, the user clicks submit and the submission is added to the database. what happens now: I type text into the text input boxes and choose options from dropdowns. When I click on preview I seem to return to the default function (all text and choices have gone). If I click Submit then the same thing happens - it seems that the $op and switch statements are not working, yet the script did work fine on the old server. I will paste the code below but please understand that I'm not a coder - I tend to hack at scripts I find to make them work the way I want! When they break I get stuck. The code is like dog's vomit - for this I apologise. <?php session_start(); if (!isset($_SESSION['user'])) { die('Please login or register to submit'); } global $tag, $title, $author, $pubname, $cat, $genre, $intro, $maintext, $username; function defaultDisplay() { include("include/cfig.php"); $useremail = $_SESSION['user']; $query = "SELECT * FROM users WHERE user_email='$useremail'"; $result = mysql_query($query) or die(mysql_error()); while($get_row = mysql_fetch_array( $result )) { $id = $get_row['id']; $full_name = $get_row['full_name']; $email = $get_row['user_email']; print "<center><b>Submit Writing</b> $full_name & $id</center></p>"; print "<table border=\"0\" cellpadding=\"3\" cellspacing=\"4\"> <tr><td width=\"706\" valign=\"top\"><p align=\"left\">"; print "<form name='myform' method='POST' action='/members/submit.php'>\n"; print " <input name='id' type='hidden' value='".$id."'>\n"; print " <table border='0' cellspacing='1' cellpadding='1' width='100%'>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'></span></td>\n"; print " <td><input class='mandtext' name='tag' type='hidden' value='".$tag."' bgcolor='yellow' size='15'></td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'></span></td>\n"; print " <td><input class='mandtext' name='email' type='hidden' value='".$email."' size='50'></td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'></span></td>\n"; print " <td><input class='mandtext' name='pubname' type='hidden' value='".$full_name."' size='50'></td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'>Title</span></td>\n"; print " <td><input class='mandtext' name='title' type='text' size='30'></td>\n"; print " </tr>\n"; print " <tr>\n"; // author input print " <td><span class='fieldname'>Author</span></td>\n"; print " <td><input class='mandtext' name='author' type='text' size='30'></td>\n"; print " </tr>\n"; print " <tr>\n"; // end print " <td><span class='fieldname'>Category</span></td>\n"; print " <td>"; include("catdd2.php"); "</td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'>Genre</span></td>\n"; print " <td>"; include("genredd.php"); "</td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'>Blurb (Book Description)</span></td>\n"; $maintext = str_replace("<br>", "\n", $maintext); print " <td><textarea name='maintext' rows='10' cols='30'>".$maintext."</textarea></td>\n"; print " </tr>\n"; print " <tr>\n"; // image URL addition nov 4th 2007 print " <td><span class='fieldname'>Image Link<br>Link to a thumbnail book cover image</span></td>\n"; print " <td><input class='mandtext' name='imgurl' type='text' size='50'><br></td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><img src=\"/images/spacer.gif\" width=\"10\" height=\"10\" border=\"0\"></td>\n"; print " <td></td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'>Direct Link<br> Primary website featuring the book (e.g. Amazon)</span></td>\n"; print " <td><input class='mandtext' name='booklink' type='text' size='50'><br></td>\n"; print " </tr>\n"; print " <tr>\n"; print " \n<p><td colspan='2' align='center'><input type='submit' name ='op'class='button' value='Preview'></td>\n"; print " </tr>\n"; print " \n<p><td colspan='2' align='center'><input type='submit' name ='op' class='button' value='Submit'></td>\n"; print " </tr>\n"; print " </table>\n"; print "</form>\n"; print "</td></tr></table>\n\n\n"; print"<p></td></tr></table>"; } } function Preview($id, $full_name, $email, $title, $author, $cat, $genre, $intro, $maintext, $imgurl, $booklink, $cc_title, $gg_title) { $title = trim($title); $author = trim($author); $title = str_replace("'", "'", $title); $author = str_replace("'", "'", $author); $query = "SELECT * FROM Submit WHERE title='$title' AND author='$author'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) // make sure there are images (you can handle this any way you like) if(mysql_num_rows($result) > 0) { echo '<center><font color="red" size="4"><b>This book is rather similar to a book already listed.</font></b><br> Please <a href="/expand.php?oid='.$row['oid'].'" target="_blank">click and check this title is not the same book</a> (opens a new browser window). <p>If the you still wish to submit this book (assuming the link above is a <font color="red"><b>DIFFERENT</b></font> book) please alter your choice of title and/or author below. Thank you.<p> </center>'; } if ($cat == 0) {echo '<center><font color="red"><b>REMINDER:</font></b> You need to choose a <b>CATEGORY</b> for this book</center><p>';} if ($genre == 0) {echo '<center><font color="red"><b>REMINDER:</font></b> You need to choose a <b>GENRE</b> for this book</center><p>';} function truncate($string, $chars, $append = '...') { $string = substr($string, 0, $chars); $trunc_at = strrpos($string, ' '); if($trunc_at !== FALSE) $string = substr($string, 0, $trunc_at); return $string.$append; } if(empty($imgurl)) { $img = '<img src="images/noimage.gif" align="center" border="0" vspace="4" hspace="4" width="75" height="100" alt="'. $title. ' by '. $author . '" title=" '. $title. ' by '. $author . '">'; }else{ $img = '<img src="'. $imgurl. '" align="center" border="0" vspace="4" hspace="4" width="75" height="100" alt="'. $title. ' by '. $author . '" title=" '. $title. ' by '. $author . ' ">'; } if(empty($imgurl)) { $img2 = '<img src="images/noimage.gif" align="center" border="0" vspace="4" hspace="4" width="123" height="190" alt="'. $title. ' by '. $author . '" title=" '. $title. ' by '. $author . '">'; }else{ $img2 = '<img src="'. $imgurl. '" align="center" border="0" vspace="4" hspace="4" width="123" height="190" alt="'. $title. ' by '. $author . '" title=" '. $title. ' by '. $author . ' ">'; } ################################## preview ##################################### ?> <font color="blue"> Below is how your book will appear on the click-thru page. This page features the details you have supplied and gives readers the chance to add reviews (if you choose) and for you to also add reviews and further details.<p></font> <table border="0" cellpadding="3" cellspacing="4"> <tr> <td width="971"><p> <div class="PortTitleDetails" style="background-image:url('../images/port_title_check.jpg')"><?php echo $title .' by '.$author.''; ?></div> <div class="HPFeatureThumbEx"><?php echo $img2; ?></div> <?php $maintext = str_replace("\n", "<br>", $maintext); ?> <?php echo $maintext; ?> <?php $catjoin = mysql_query("select * from Categories where id=$cat"); while(list($c_id, $c_title) = mysql_fetch_row($catjoin)) { if ($c_id == $cat) { $cc_title = $c_title; } else { $cc_title = "";} } $genjoin = mysql_query("select * from Genres where id=$genre"); while(list($g_id, $g_title) = mysql_fetch_row($genjoin)) { if ($g_id == $genre) { $gg_title = $g_title; } else { $gg_title = "";} } ?> <p> </td></tr> <td width="971"><p> </td> </tr> </table> <table border="0" cellpadding="2"> <tr> <td width="257"><p align="left"> <div class="Appointment"><center><?php echo $cc_title ." | ".$gg_title ?></center></div> </td> <td width="696"><p></td> </tr><tr> <td width="257"><p></td> <td width="696"><p align="center"><?php echo $pubname; ?></td> </tr></table> <center><hr size="1" width="90%"></center> <p> <?php print " <td><img src=\"/images/spacer.gif\" width=\"10\" height=\"20\" border=\"0\"></td>\n"; if ($cat == 0) {echo '<center><font color="red"><b>REMINDER:</font></b> You need to choose a <b>CATEGORY</b> for this book</center><p>';} if ($genre == 0) {echo '<center><font color="red"><b>REMINDER:</font></b> You need to choose a <b>GENRE</b> for this book</center><p>';} // the hidden form variables print "<p><center><b>Submit a book</b></center></p> <table border=\"0\" cellpadding=\"3\" cellspacing=\"4\"> <tr><td width=\"706\" valign=\"top\"><p align=\"left\">"; print "<form name='myform' method='POST' action='/members/submit.php'>\n"; print " <input name='id' type='hidden' value='".$id."'>\n"; print " <table border='0' cellspacing='1' cellpadding='1' width='100%'>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'></span></td>\n"; print " <td><input class='mandtext' name='tag' type='hidden' value='".$tag."' bgcolor='yellow' size='15'></td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'></span></td>\n"; print " <td><input class='mandtext' name='email' type='hidden' value='".$email."' size='50'></td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'>Title</span></td>\n"; print " <td><input class='mandtext' name='title' type='text' value='".$title."' size='30'></td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'>Author</span></td>\n"; print " <td><input class='mandtext' name='author' type='text' value='".$author."' size='30'></td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'>Category</span></td>\n"; print " <td>"; include("catdd2.php"); "</td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'>Genre</span></td>\n"; print " <td>"; include("genredd.php"); "</td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'>Blurb (Book Description)</span></td>\n"; $maintext = str_replace("<br>", "\n", $maintext); print " <td><textarea name='maintext' rows='10' cols='30'>".$maintext."</textarea></td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'>Image Link<br>Link to a thumbnail book cover image</span></td>\n"; print " <td><input class='mandtext' name='imgurl' type='text' value='".$imgurl."'size='50'><br></td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><img src=\"/images/spacer.gif\" width=\"10\" height=\"10\" border=\"0\"></td>\n"; print " <td></td>\n"; print " </tr>\n"; print " <tr>\n"; print " <td><span class='fieldname'>Direct Link<br> Primary website featuring the book (e.g. Amazon)</span></td>\n"; print " <td><input class='mandtext' name='booklink' type='text' value='".$booklink."'size='50'><br></td>\n"; print " </tr>\n"; print " <tr>\n"; print " \n<p><td colspan='2' align='center'><input type='submit' name='op'class='button' value='Preview'></td>\n"; print " </tr>\n"; print " \n<p><td colspan='2' align='center'><input type='submit' name='op' class='button' value='Submit'></td>\n"; print " </tr>\n"; print " </table>\n"; print "</form>\n"; print "</td></tr></table>\n\n\n"; print"<p> </td> </tr></table>"; } function Submit($id, $full_name, $email, $title, $author, $cat, $genre, $intro, $maintext, $imgurl, $booklink, $cc_title, $gg_title) { include("../cfig.php"); if ($cat == 0) {$cat = 1;} if ($genre == 0) {$genre = 14;} $title = str_replace("'", "\'", $title); $author = str_replace("'", "\'", $author); $maintext = str_replace("'", "\'", $maintext); $query = "SELECT * FROM Submit WHERE title='$title' AND author='$author'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) // make sure there are images (you can handle this any way you like) if(mysql_num_rows($result) > 0) { die ('<center><font color="red" size="4"><b>This book is rather similar to a book already listed.</font></b><br> Please <a href="/expand.php?oid='.$row['oid'].'" target="_blank">click and check this title is not the same book</a> (opens a new browser window). <p>If the you still wish to submit this book (assuming the link above is a <font color="red"><b>DIFFERENT</b></font> book) please alter your choice of title and/or author below. Thank you.<p> <a href="javascript:history.go(-1)"><img src="images/back.gif" border="0" align="center" valign="bottom" alt="Go Back" title="Go Back"></a></center>'); } $catjoin = mysql_query("select * from Categories where id=$cat"); while(list($c_id, $c_title) = mysql_fetch_row($catjoin)) { if ($c_id == $cat) { $cc_title = $c_title; } else { $cc_title = "";} } $genjoin = mysql_query("select * from Genres where id=$genre"); while(list($g_id, $g_title) = mysql_fetch_row($genjoin)) { if ($g_id == $genre) { $gg_title = $g_title; } else { $gg_title = "";} } $result = mysql_query("insert into Submit values ('', '$username', '$tag', '$email', '$title', '$author', '$cat', '$genre', '$intro', '$maintext', '$imgurl','$booklink')", $db); if(!$result) { echo "Opps! Error<br>"; } else { echo "<p><center><b>Thank You.</b><br>The title has been entered into the database and is available to view <a href=\"/genre.php?cat=$cat&genre=$genre\">HERE</a><p> You can now go to your cPanel and add extras like paylinks and media review links.<p>"; } } switch($op) { case "Preview": Preview($id, $full_pubname, $email, $title, $author, $cat, $genre, $intro, $maintext, $imgurl, $booklink, $cc_title, $gg_title); break; case "Submit": Submit($id, $full_name, $email, $title, $author, $cat, $genre, $intro, $maintext, $imgurl, $booklink, $cc_title, $gg_title); break; default: defaultDisplay(); break; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/126946-solved-submit-amp-preview-form-not-working/ Share on other sites More sharing options...
thecard Posted October 3, 2008 Share Posted October 3, 2008 Blimey, that is a mess! Just please make sure you copied the WHOLE document from the old server. I'll try to have a look through it in the mean time. Quote Link to comment https://forums.phpfreaks.com/topic/126946-solved-submit-amp-preview-form-not-working/#findComment-656666 Share on other sites More sharing options...
richardjh Posted October 3, 2008 Author Share Posted October 3, 2008 @thecard I know, I'm dreadfully embarrassed to post the code here but I really have no clue what to do (as you can see from my coding attempts!) The code I posted above is the whole code which is contained in a file called submit.php. The original idea was to contain the three functions (default, preview & submit) into one page and use switch statements. It did work (promise) even though it is hard to image code this poor actually functioning. thanks in advance for any help you provide. Quote Link to comment https://forums.phpfreaks.com/topic/126946-solved-submit-amp-preview-form-not-working/#findComment-656676 Share on other sites More sharing options...
PFMaBiSmAd Posted October 4, 2008 Share Posted October 4, 2008 The posted code is dependent on register_globals, for at least the $op variable that controls the switch/case statement. Add the following line of code near the start of your code - $op = isset($_POST['op']) ? $_POST['op'] : "" ; To find this problem and any other similar problems, add the following two lines immedately after the first <?php tag - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/126946-solved-submit-amp-preview-form-not-working/#findComment-656760 Share on other sites More sharing options...
richardjh Posted October 5, 2008 Author Share Posted October 5, 2008 @PFMaBiSmAd Thanks for that advice. I have got the form to work now by listing the form post variables at the top thus: $op = isset($_POST['op']) ? $_POST['op'] : "" ; $username = isset($_POST['username']) ? $_POST['username'] : "" ; $email = isset($_POST['email']) ? $_POST['email'] : "" ; etc... many thanks for your advice. R Quote Link to comment https://forums.phpfreaks.com/topic/126946-solved-submit-amp-preview-form-not-working/#findComment-657481 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.