Jump to content

best I could do - pointer examples of cleaning code please


blui

Recommended Posts

Hi all, I am still getting used to php, but I have managed to create a very basic CMS, the CMS cover 6 pages and each page can have its title, pagetext, image link 1 and 2 altered.

I have doen the best I can but, I imagine that the code I have produced is somewhat ugly and could be clearer and slimlined. I have included the code for both the form page and the post page.

Any pointers, examples of how this code could be made more efficient, would be greatfully appreciated.

Thanks blu

 

postinfo.php:-

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

<?

require_once('connectionlocal.php');

?>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<table width="600" border="0" cellspacing="0" cellpadding="0">

  <form action="../php/postinfo2.php" method="post"><tr>

    <td width="200">Special Offers Title </td>

    <td width="322"><input name="title1" type="text" value="

<?php

// Get a specific result from the "example" table

$result = mysql_query("SELECT * FROM cmscontent WHERE PRIMARYID='1'") or die(mysql_error()); 

$row = mysql_fetch_array( $result );

echo $row['title'];

?>

"/>

</td>

  </tr>

  <tr>

    <td width="200">Special Offers Page Text </td>

    <td><textarea name="pagetext1" cols="50" rows="8"><?php echo $row['pagetext'];?></textarea></td>

  </tr>

  <tr>

    <td width="200">Special Offers Image 1</td>

    <td><select name="imagelist"><option value=<?php echo $row['links1'];?>

></option>

<?

require('directorylistinginc.php');

?>

  </select></td>

  </tr>

  <tr>

    <td width="200">Special Offers Image 2 </td>

    <td><select name="imagelist10"><option value=<?php echo $row['links1'];?>

></option>

<?

require('directorylistinginc.php');

?>

  </select></td>

  </tr>

  <tr>

    <td width="200"> </td>

    <td> </td>

  </tr>

  <tr>

    <td width="200">Leisure Title </td>

    <td><input type="pagetext" name="title2" value="

<?php

// Get a specific result from the "example" table

$result = mysql_query("SELECT * FROM cmscontent WHERE PRIMARYID='2'") or die(mysql_error()); 

$row = mysql_fetch_array( $result );

echo $row['title'];

?>

"/></td>

  </tr>

  <tr>

    <td width="200">Leisure Page Text </td>

    <td><textarea name="pagetext2" cols="50" rows="8"><?php echo $row['pagetext'];?></textarea></td>

  </tr>

  <tr>

    <td width="200">Leisure Image 1 </td>

    <td><select name="imagelist2"><option value=<?php echo $row['links1'];?>

></option>

<?

require('directorylistinginc.php');

?>

  </select></td>

  </tr>

  <tr>

    <td width="200">Leisure Image 2 </td>

    <td><select name="imagelist12"><option value=<?php echo $row['links2'];?>

></option>

<?

require('directorylistinginc.php');

?>

  </select></td>

  </tr>

  <tr>

    <td width="200"> </td>

    <td> </td>

  </tr>

  <tr>

    <td width="200">Golf Title </td>

    <td><input type="text" name="title3" value="

<?php

// Get a specific result from the "example" table

$result = mysql_query("SELECT * FROM cmscontent WHERE PRIMARYID='3'") or die(mysql_error()); 

$row = mysql_fetch_array( $result );

echo $row['title'];

?>

"/></td>

  </tr>

  <tr>

    <td width="200">Golf Page Text </td>

    <td><textarea name="pagetext3" cols="50" rows="8"><?php echo $row['pagetext'];?></textarea></td>

  </tr>

  <tr>

    <td width="200">Golf Image 1 </td>

    <td> <select name="imagelist3"><option value=<?php echo $row['links1'];?>

></option>

<?

require('directorylistinginc.php');

?>

  </select></td>

  </tr>

  <tr>

    <td width="200">Golf Image 2 </td>

    <td><select name="imagelist13"><option value=<?php echo $row['links2'];?>

></option>

<?

require('directorylistinginc.php');

?>

  </select></td>

  </tr>

  <tr>

    <td width="200"> </td>

    <td> </td>

  </tr>

  <tr>

    <td width="200">Christmas Title </td>

    <td><input type="text" name="title4" value="

<?php

// Get a specific result from the "example" table

$result = mysql_query("SELECT * FROM cmscontent WHERE PRIMARYID='4'") or die(mysql_error()); 

$row = mysql_fetch_array( $result );

echo $row['title'];

?>

"/></td>

  </tr>

  <tr>

    <td width="200">Christmas Page Text </td>

    <td><textarea name="pagetext4" cols="50" rows="8"><?php echo $row['pagetext'];?></textarea></td>

  </tr>

  <tr>

    <td width="200">Christmas Image 1 </td>

    <td><select name="imagelist4"><option value=<?php echo $row['links1'];?>

></option>

<?

require('directorylistinginc.php');

?>

  </select></td>

  </tr>

  <tr>

    <td width="200">Christmas Image 2 </td>

    <td><select name="imagelist14"><option value=<?php echo $row['links2'];?>

></option>

<?

require('directorylistinginc.php');

?>

  </select></td>

  </tr>

  <tr>

    <td width="200"> </td>

    <td> </td>

  </tr>

  <tr>

    <td width="200">Conferences Title </td>

    <td><input type="text" name="title5" value="

<?php

// Get a specific result from the "example" table

$result = mysql_query("SELECT * FROM cmscontent WHERE PRIMARYID='5'") or die(mysql_error()); 

$row = mysql_fetch_array( $result );

echo $row['title'];

?>

"/></td>

  </tr>

  <tr>

    <td width="200">Conferences Page Text </td>

    <td><textarea name="pagetext5" cols="50" rows="8"><?php echo $row['pagetext'];?></textarea></td>

  </tr>

  <tr>

    <td width="200">Conferences Image 1 </td>

    <td><select name="imagelist5"><option value=<?php echo $row['links1'];?>

></option>

<?

require('directorylistinginc.php');

?>

  </select></td>

  </tr>

  <tr>

    <td width="200">Conferences Image 2 </td>

    <td><select name="imagelist15"><option value=<?php echo $row['links2'];?>

></option>

<?

require('directorylistinginc.php');

?>

  </select></td>

  </tr>

  <tr>

    <td width="200"> </td>

    <td> </td>

  </tr>

  <tr>

    <td width="200">Sample Menu Title </td>

    <td><input type="text" name="title6" value="

<?php

// Get a specific result from the "example" table

$result = mysql_query("SELECT * FROM cmscontent WHERE PRIMARYID='6'") or die(mysql_error()); 

$row = mysql_fetch_array( $result );

echo $row['title'];

?>

"/></td>

  </tr>

  <tr>

    <td width="200">Sample Menu Page Text </td>

    <td><textarea name="pagetext6" cols="50" rows="8"><?php echo $row['pagetext'];?></textarea></td>

  </tr>

  <tr>

    <td width="200">Sample Menu Image 1 </td>

    <td><select name="imagelist6"><option value=<?php echo $row['links1'];?>

></option>

<?

require('directorylistinginc.php');

?>

  </select></td>

  </tr>

  <tr>

    <td width="200">Sample Menu Image 2 </td>

    <td><select name="imagelist16"><option value=<?php echo $row['links2'];?>

></option>

<?

require('directorylistinginc.php');

?>

  </select></td>

  </tr>

  <tr>

    <td width="200"> </td>

    <td>  <input type="submit" name="submit" value="submit">  </td>

  </tr>

</form></table>

</body>

</html>

 

-----------------------------------------------------

directorylistinginc.php:-

<?

$file_dir="images/thumbs";

$dir=opendir($file_dir);

while ($file=readdir($dir))

{

if ($file != "." && $file != "..")

{

echo "<option value=".$file_dir."/".$file." >".$file."";

echo "</option>";

}

}

?>

 

--------------------------------------------------------------------

postinfo2.php

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

<?

require_once('connectionlocal.php');

?>

<?PHP

 

//inserts title into approprate cell

$sql = "UPDATE `cmscontent` SET `title` = '{$_POST['title1']}' WHERE `PRIMARYID`='1'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `title` = '{$_POST['title2']}' WHERE `PRIMARYID`='2'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `title` = '{$_POST['title3']}' WHERE `PRIMARYID`='3'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `title` = '{$_POST['title4']}' WHERE `PRIMARYID`='4'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `title` = '{$_POST['title5']}' WHERE `PRIMARYID`='5'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `title` = '{$_POST['title6']}' WHERE `PRIMARYID`='6'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

 

//inserts pagetext into approprate cell

$sql = "UPDATE `cmscontent` SET `pagetext` = '{$_POST['pagetext1']}' WHERE `PRIMARYID`='1'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `pagetext` = '{$_POST['pagetext2']}' WHERE `PRIMARYID`='2'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `pagetext` = '{$_POST['pagetext3']}' WHERE `PRIMARYID`='3'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `pagetext` = '{$_POST['pagetext4']}' WHERE `PRIMARYID`='4'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `pagetext` = '{$_POST['pagetext5']}' WHERE `PRIMARYID`='5'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `pagetext` = '{$_POST['pagetext6']}' WHERE `PRIMARYID`='6'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

 

//inserts image link into approprate cell

$sql = "UPDATE `cmscontent` SET `links1` = '{$_POST['imagelist']}' WHERE `PRIMARYID`='1'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `links1` = '{$_POST['imagelist2']}' WHERE `PRIMARYID`='2'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `links1` = '{$_POST['imagelist3']}' WHERE `PRIMARYID`='3'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `links1` = '{$_POST['imagelist4']}' WHERE `PRIMARYID`='4'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `links1` = '{$_POST['imagelist5']}' WHERE `PRIMARYID`='5'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `links1` = '{$_POST['imagelist6']}' WHERE `PRIMARYID`='6'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

 

$sql = "UPDATE `cmscontent` SET `links2` = '{$_POST['imagelist10']}' WHERE `PRIMARYID`='1'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `links2` = '{$_POST['imagelist12']}' WHERE `PRIMARYID`='2'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `links2` = '{$_POST['imagelist13']}' WHERE `PRIMARYID`='3'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `links2` = '{$_POST['imagelist14']}' WHERE `PRIMARYID`='4'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `links2` = '{$_POST['imagelist15']}' WHERE `PRIMARYID`='5'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

$sql = "UPDATE `cmscontent` SET `links2` = '{$_POST['imagelist16']}' WHERE `PRIMARYID`='6'";

mysql_query($sql) || die("An error has happened: " . mysql_error());

 

 

?>

<?php

// Change to the URL you want to redirect to

$URL="http://pauldaleragu/php/postinfo.php";

header ("Location: $URL");

?>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

</body>

</html>

 

Archived

This topic is now archived and is closed to further replies.

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