Jump to content

PHP4 script to PHP5 HELP!


mediasix

Recommended Posts

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>";

  }

?>

Link to comment
Share on other sites

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");

?>

Link to comment
Share on other sites

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++;

}

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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  :)

 

 

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.