mediasix Posted November 20, 2007 Share Posted November 20, 2007 i currently have this script in place, but i need to make it compatible with php5. please can you help me convert it?!? thanks in advance mediasix <?php if ($HTTP_POST_VARS['submit']) { mysql_connect("xxxxxx","xxxxxx","xxxxxx"); mysql_select_db("xxxxxx"); $title=$HTTP_POST_VARS['title']; $text=$HTTP_POST_VARS['text']; $query ="INSERT INTO weblog (title,content)"; $query.=" VALUES ('$title','$content')"; $result=mysql_query($query); if ($result) echo "<b>Successfully Posted!</b>"; else echo "<b>ERROR: unable to post.</b>"; } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 20, 2007 Share Posted November 20, 2007 Change $HTTP_POST_VARS to $_POST Quote Link to comment Share on other sites More sharing options...
mediasix Posted November 20, 2007 Author Share Posted November 20, 2007 thanks that worked a treat, do you think you could help on this piece of code too? thanks again mediasix <? mysql_connect("xxxxxx","xxxxxx","xxxxxx"); mysql_select_db("xxxxxx"); $query="SELECT * FROM weblog WHERE title='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $date=mysql_result($result,$i,"date"); $title=mysql_result($result,$i,"title"); $content=mysql_result($result,$i,"content"); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 20, 2007 Share Posted November 20, 2007 I don't see any PHP problems with that code myself. Maybe a missing $i++ Quote Link to comment Share on other sites More sharing options...
mediasix Posted November 20, 2007 Author Share Posted November 20, 2007 OK, probably would have been better giving you the full code, here it is. when i navigate to the page providing the correct variable the page is blank. Thank you very much mediasix <? mysql_connect("xxxxxx","xxxxxx","xxxxxx"); mysql_select_db("xxxxxx"); $query="SELECT * FROM weblog WHERE title='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $date=mysql_result($result,$i,"date"); $title=mysql_result($result,$i,"title"); $content=mysql_result($result,$i,"content"); ?> <!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=utf-8" /> <title>mediasix blog - <? echo "$title"?></title> <link href="../css/mediasix.css" rel="stylesheet" type="text/css" /> <link href="../css/mediasix-print.css" rel="stylesheet" type="text/css" media="print" /> <script type="text/javascript" src="../scripts/equalcolumns.js"></script> </head> <body> <div id="header"><img src="../images/mediasix-web-logo.gif" alt="logo" width="600" height="100" /></div> <div id="holder"> <div id="contentholder"> <div class="nav" align="center" id="nav"><?php include("../includes/menu.php");?></div> <div id="content"> <h1><? echo "$title"?></h1><h2><? echo "$date"?></h2> <p><? echo "$content"?></P></div> <div id="othercontent"><?php include ("../includes/othercontent.php");?></div> <div id="footer"><?php include("../includes/footer.php");?></div> </div> </div> </body> </html> <? $i++; } ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 20, 2007 Share Posted November 20, 2007 Change all the short open tags <? to full open tags <?php Quote Link to comment Share on other sites More sharing options...
mediasix Posted November 20, 2007 Author Share Posted November 20, 2007 i have done that, but i still get a blank page when i turn on php4.4.7 it works fine, but as soon as i turn on php5.2.3 is breaks! im baffled ??? please please help! (oh and it can be found at www.mediasix.co.uk click on the test blog entry on the right panel) Quote Link to comment Share on other sites More sharing options...
revraz Posted November 20, 2007 Share Posted November 20, 2007 Your entire display relies on $i < $num echo $num to check it's value This line may be returning unexpected results $query="SELECT * FROM weblog WHERE title='$id'"; Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 20, 2007 Share Posted November 20, 2007 Blank pages are usually caused by fatal php parse errors. Check your web server log for errors. Quote Link to comment Share on other sites More sharing options...
mediasix Posted November 21, 2007 Author Share Posted November 21, 2007 OK, is it possable to remove the $i < $num and it still function? whe i do i get the errors: Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 2 in /home/.putz/mutual_mediasix/mediasix.co.uk/weblog/weblogentry.php on line 9 Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 2 in /home/.putz/mutual_mediasix/mediasix.co.uk/weblog/weblogentry.php on line 10 Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 2 in /home/.putz/mutual_mediasix/mediasix.co.uk/weblog/weblogentry.php on line 11 being a n00b sucks, please help ??? thanks mediasix Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 21, 2007 Share Posted November 21, 2007 Try this <?php mysql_connect("localhost","root",''); mysql_select_db("******"); $query="SELECT * FROM weblog"; $result=mysql_query($query); ?> <!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=utf-8" /> <title>mediasix blog - <? echo "$title"?></title> <link href="../css/mediasix.css" rel="stylesheet" type="text/css" /> <link href="../css/mediasix-print.css" rel="stylesheet" type="text/css" media="print" /> <script type="text/javascript" src="../scripts/equalcolumns.js"></script> </head> <body> <div id="header"><img src="../images/mediasix-web-logo.gif" alt="logo" width="600" height="100" /></div> <div id="holder"> <div id="contentholder"> <div class="nav" align="center" id="nav"><?php include("../includes/menu.php");?></div> <?php $i=0; while ($row = mysql_fetch_array($result)) { $date=mysql_result($result,$i,"date"); $title=mysql_result($result,$i,"title"); $content=mysql_result($result,$i,"content"); ?> <div id="content"> <h1><? echo "$title"?></h1><h2><? echo "$date"?></h2> <p><? echo "$content"?></P></div> <? $i++; } ?> <div id="othercontent"><?php include ("../includes/othercontent.php");?></div> <div id="footer"><?php include("../includes/footer.php");?></div> </div> </div> </body> </html> Tested on PHP version : 5.2.4 Quote Link to comment Share on other sites More sharing options...
sharifbaba Posted November 21, 2007 Share Posted November 21, 2007 Change $HTTP_POST_VARS to $_POST Quote Link to comment Share on other sites More sharing options...
mediasix Posted November 21, 2007 Author Share Posted November 21, 2007 OK i had to change the layout of the the code slightly, as i need the title of the html page to be dynamicaly created too. the code now works on php5, but not exactly how i want it. it now displays all the entries in form 'weblog' but i need it to take a specific vairiable from the url using GET, in my last piece of code i had $query="SELECT * FROM weblog WHERE title='$id'"; but when i put that back into the code below it breaks! thanks again mediasix <?php mysql_connect("xxxxxx","xxxxxx","xxxxxx"); mysql_select_db("xxxxxx"); $query="SELECT * FROM weblog"; $result=mysql_query($query); ?> <?php $i=0; while ($row = mysql_fetch_array($result)) { $date=mysql_result($result,$i,"date"); $title=mysql_result($result,$i,"title"); $content=mysql_result($result,$i,"content"); ?> <!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=utf-8" /> <title>mediasix blog - <?php echo "$title"?></title> <link href="../css/mediasix.css" rel="stylesheet" type="text/css" /> <link href="../css/mediasix-print.css" rel="stylesheet" type="text/css" media="print" /> <script type="text/javascript" src="../scripts/equalcolumns.js"></script> </head> <body> <div id="header"><img src="../images/mediasix-web-logo.gif" alt="logo" width="600" height="100" /></div> <div id="holder"> <div id="contentholder"> <div class="nav" align="center" id="nav"><?php include("../includes/menu.php");?></div> <div id="content"> <h1><?php echo "$title"?></h1><h2><? echo "$date"?></h2> <p><?php echo "$content"?></P></div> <? $i++; } ?> <div id="othercontent"><?php include ("../includes/othercontent.php");?></div> <div id="footer"><?php include("../includes/footer.php");?></div> </div> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 21, 2007 Share Posted November 21, 2007 Try this, you are using WHILE loop above other html tags, your LOGO and other stuff will repeat below the WHILE loop <?php mysql_connect("localhost","root",''); mysql_select_db("********"); $query="SELECT * FROM weblog WHERE title='$id'"; $result=mysql_query($query); // you are using WHILE loop here and it ends below, so the code below this line will repeat // are you expecting like this all your LOGO stuff and other THINGS will repeat while ($row = mysql_fetch_array($result)) { $date=$row['date']; // change here with your table field name $title=$row['title']; $content=$row['content']; // till here ?> <!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=utf-8" /> <title>mediasix blog - <?php echo "$title"?></title> <link href="../css/mediasix.css" rel="stylesheet" type="text/css" /> <link href="../css/mediasix-print.css" rel="stylesheet" type="text/css" media="print" /> <script type="text/javascript" src="../scripts/equalcolumns.js"></script> </head> <body> <div id="header"><img src="../images/mediasix-web-logo.gif" alt="logo" width="600" height="100" /></div> <div id="holder"> <div id="contentholder"> <div class="nav" align="center" id="nav"><?php include("../includes/menu.php");?></div> <div id="content"> <h1><?php echo "$title"?></h1><h2><? echo "$date"?></h2> <p><?php echo "$content"?></P></div> <? } ?> <div id="othercontent"><?php include ("../includes/othercontent.php");?></div> <div id="footer"><?php include("../includes/footer.php");?></div> </div> Quote Link to comment Share on other sites More sharing options...
mediasix Posted November 21, 2007 Author Share Posted November 21, 2007 i am now rather confused, and i am unsure if i need a loop at all now. all i want is the page to take the variable 'id' from the url which will look like this: http://mediasix.co.uk/weblog/weblogentry.php?id=this%20is%20a%20test%20entry then query the sql database in table 'weblog' and return the entry that matches the 'id' variable with the 'title' coloumn in the table, i dont need this repeated or anything like that. all this needs to be before my html so that i can insert the returned values into the header and then into the body. this worked fine in php4, i need it to work in php5 desperatley many thanks in advance mediasix Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 21, 2007 Share Posted November 21, 2007 Have you tried in Version 5.x.x $query="SELECT * FROM weblog WHERE title='$id'"; Your query will return all the data from the table which matches title=id, if there is 1 you will get 1, if there are many you will get all. So, how many rows you want to display. And for running in version 5+ i checked this code, i got 5.2.4 and it is running fine. Quote Link to comment Share on other sites More sharing options...
mediasix Posted November 21, 2007 Author Share Posted November 21, 2007 i tried that but i get nothing displayed, my page is there with the structure and css but no dynamic data! here is the code currently being used: thanks as always mediasix **edit** there should only be on record that can be returned, as all entries will have a different title. but for arguments sake, only one row <?php mysql_connect("xxxxxx","xxxxxx","xxxxxx"); mysql_select_db("xxxxxx"); $query="SELECT * FROM weblog WHERE title='$id'"; $result=mysql_query($query); $row = mysql_fetch_array($result); $date=$row['date']; $title=$row['title']; $content=$row['content']; ?> <!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=utf-8" /> <title>mediasix blog - <?php echo "$title"?></title> <link href="../css/mediasix.css" rel="stylesheet" type="text/css" /> <link href="../css/mediasix-print.css" rel="stylesheet" type="text/css" media="print" /> <script type="text/javascript" src="../scripts/equalcolumns.js"></script> </head> <body> <div id="header"><img src="../images/mediasix-web-logo.gif" alt="logo" width="600" height="100" /></div> <div id="holder"> <div id="contentholder"> <div class="nav" align="center" id="nav"><?php include("../includes/menu.php");?></div> <div id="content"> <h1><?php echo "$title"?></h1><h2><? echo "$date"?></h2> <p><?php echo "$content"?></P></div> <div id="othercontent"><?php include ("../includes/othercontent.php");?></div> <div id="footer"><?php include("../includes/footer.php");?></div> </div> Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 21, 2007 Share Posted November 21, 2007 Where are you getting this '$id' from, try using 1,2... which is in your table, and keep error_reporting(E_ALL); this in your php file at the top Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 21, 2007 Share Posted November 21, 2007 There was just a recent thread with similar problems - http://www.phpfreaks.com/forums/index.php/topic,168465.0.html Your code is dependent on register globals being on (variables magically appear from post/get/files/session/cookie data). This is not an issue with the PHP version but of php settings. Register globals are apparently off (as the should be) in the PHP5 settings. What is sad about this is that register globals were turned off by default in php 4.2 in the year 2002. No new code, tutorials, books... should have been written after that point in time that relied on register globals being on. That was 5 years ago. Everyone on the planet should have gotten the message by now to not continue writing code this way. Register globals have been completely removed in PHP6, so everyone will need to fix any code that is dependent on register globals by the time PHP6 is released. Edit: The posted code has no error checking, error reporting, or error recovery on the mysql function calls and will result in a blank page any time the mysql server cannot be connected to (which happens more than you would think.) Quote Link to comment Share on other sites More sharing options...
mediasix Posted November 21, 2007 Author Share Posted November 21, 2007 OK , ive added: error_reporting(E_ALL); to the top of my code and also i changed '$id' to '$1' - same as before, nothing! the code and link is below - thanks people http://mediasix.co.uk/weblog/weblogentry.php?1=this%20is%20a%20test%20entry <?php error_reporting(E_ALL); mysql_connect("xxxxxx","xxxxxx","xxxxxx"); mysql_select_db("xxxxxx"); $query="SELECT * FROM weblog WHERE title='$1'"; $result=mysql_query($query); $row = mysql_fetch_array($result); $date=$row['date']; $title=$row['title']; $content=$row['content']; ?> <!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=utf-8" /> <title>mediasix blog - <?php echo "$title"?></title> <link href="../css/mediasix.css" rel="stylesheet" type="text/css" /> <link href="../css/mediasix-print.css" rel="stylesheet" type="text/css" media="print" /> <script type="text/javascript" src="../scripts/equalcolumns.js"></script> </head> <body> <div id="header"><img src="../images/mediasix-web-logo.gif" alt="logo" width="600" height="100" /></div> <div id="holder"> <div id="contentholder"> <div class="nav" align="center" id="nav"><?php include("../includes/menu.php");?></div> <div id="content"> <h1><?php echo "$title"?></h1><h2><?php echo "$date"?></h2> <p><?php echo "$content"?></P></div> <div id="othercontent"><?php include ("../includes/othercontent.php");?></div> <div id="footer"><?php include("../includes/footer.php");?></div> </div> Quote Link to comment Share on other sites More sharing options...
mediasix Posted November 21, 2007 Author Share Posted November 21, 2007 if anyone could tell me why error_reporting(E_ALL); isnt working then i will try and debug myself, but even that wont work! please help ??? Quote Link to comment Share on other sites More sharing options...
mediasix Posted November 21, 2007 Author Share Posted November 21, 2007 please anyone!?!?! Quote Link to comment Share on other sites More sharing options...
revraz Posted November 21, 2007 Share Posted November 21, 2007 Is error reporting on in your php.ini? Quote Link to comment Share on other sites More sharing options...
mediasix Posted November 21, 2007 Author Share Posted November 21, 2007 yeah its on, i have tried on my host 'dreamhost' and on my local install, both times nothing! i'm really stuck, any more advise welcomed with open arms thanks mediasix 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.