SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with my PHP - mySql to PostgreSql

    I'm trying to covert the following code to use a postgreSql database rather than a mySql databse that I has initially used in it's design.

    So far I have part of the code changed and working. Yet a large portion of my code is not working at all. Perhaps someone could tell me where I have gone wrong and how to correct this problem?

    PHP Code:
    <?php
    $input 
    $_GET['input'];
    $SUBMIT $_GET['SUBMIT'];
    switch (
    $input) {
        case 
    :

    echo(
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
    <html>
    <head>
    <title>Submit Case Studies &amp; Floor Plans</title>
    </head>
    <body>
    <form action=\"index.php\" method=\"post\">
    <table summary=\"Form Table\">
    <tr>
    <td colspan=\"2\"><b>If you enter a 1 in both boxes this will publish out as both a Case Study and a Floor Plan.</b><br><hr></td>
    </tr>
    <tr>
    <td align=\"right\">Type 1 in the box if entering a Case Study:</td>
    <td><INPUT TYPE=\"text\" NAME=\"study\"></td>
    </tr>
    <tr>
    <td align=\"right\">Type 1 in the box if entering a Floor Plan:</td>
    <td><INPUT TYPE=\"text\" NAME=\"plan\"></td>
    </tr>
    <tr>
    <td align=\"right\">Model Name and/or Number: </td>
    <td><INPUT TYPE=\"text\" NAME=\"model\"></td>
    </tr>
    <tr>
    <td align=\"right\">Modular Building Category:</td>
    <td><INPUT TYPE=\"text\" NAME=\"cat\"></td>
    </tr>
    <tr>
    <td align=\"right\">Building Type: </td>
    <td><INPUT TYPE=\"text\" NAME=\"title\"></td>
    </tr>
    <tr>
    <td align=\"right\">Square Footage: </td>
    <td><INPUT TYPE=\"text\" NAME=\"sqft\"></td>
    </tr>
    <tr>
    <td align=\"right\">Company or Name:</td>
    <td><INPUT TYPE=\"text\" NAME=\"name\"></td>
    </tr>
    <tr>
    <td align=\"right\">Location:</td>
    <td><INPUT TYPE=\"text\" NAME=\"location\"></td>
    </tr>
    <tr>
    <td align=\"right\">Large Outside:</td>
    <td><INPUT TYPE=\"text\" NAME=\"lgpic\"></td>
    </tr>
    <tr>
    <td align=\"right\">Small Outside :</td>
    <td><INPUT TYPE=\"text\" NAME=\"smpic\"></td>
    </tr>
    <tr>
    <td align=\"right\">Interior 1:</td>
    <td><INPUT TYPE=\"text\" NAME=\"inside\"></td>
    </tr>
    <tr>
    <td align=\"right\">Interior 2:</td>
    <td><INPUT TYPE=\"text\" NAME=\"inside1\"></td>
    </tr>
    <tr>
    <td align=\"right\">Interior 3:</td>
    <td><INPUT TYPE=\"text\" NAME=\"inside2\"></td>
    </tr>
    <tr>
    <td align=\"right\">Large 2d:</td>
    <td><INPUT TYPE=\"text\" NAME=\"lg2d\"></td>
    </tr>
    <tr>
    <td align=\"right\">Small 2d:</td>
    <td><INPUT TYPE=\"text\" NAME=\"sm2d\"></td>
    </tr>
    <tr>
    <td align=\"right\">Large 3d:</td>
    <td><INPUT TYPE=\"text\" NAME=\"lg3d\"></td>
    </tr>
    <tr>
    <td align=\"right\">Small 3d:</td>
    <td><INPUT TYPE=\"text\" NAME=\"sm3d\"></td>
    </tr>
    <tr>
    <td align=\"right\">PDF:</td>
    <td><INPUT TYPE=\"text\" NAME=\"pdf\"></td>
    </tr>
    <tr>
    <td align=\"right\">About:</td>
    <td><textarea name=\"about\" rows=\"10\" cols=\"40\"></textarea></td>
    </tr>
    <tr>
    <td align=\"right\">Need:</td>
    <td><textarea name=\"need\" rows=\"10\" cols=\"40\"></textarea></td>
    </tr>
    <tr>
    <td align=\"right\">Solution:</td>
    <td><textarea name=\"solution\" rows=\"10\" cols=\"40\"></textarea></td>
    </tr>
    <tr>
    <td><input type=\"submit\" name=\"submittitle\" value=\"SUBMIT\"/></td></tr></table>
    </form></body></html>"
    );

            break;
        case 
    :
            include (
    'db.inc');
            
    $query "SELECT * FROM case_plans WERE id = $id";
            
    $result pg_query($query) or die('Error, query failed');
            while (
    $row pg_fetch_array($result)) {
                
    $id $row["id"];
                
    $plan $row["plan"];
                
    $study $row["study"];
                
    $model $row["model"];
                
    $cat $row["cat"];
                
    $sqft $row["sqft"];
                
    $title $row["title"];
                
    $name $row["name"];
                
    $location $row["location"];
                
    $about $row["about"];
                
    $need $row["need"];
                
    $solution $row["solution"];
                
    $pdf $row["pdf"];
                
    $lgpic $row["lgpic"];
                
    $smpic $row["smpic"];
                
    $lg2d $row["lg2d"];
                
    $sm2d $row["sm2d"];
                
    $lg3d $row["lg3d"];
                
    $sm3d $row["sm3d"];
                print 
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"."<html>"."<head>"."<title>Edit Case Studies &amp; Floor Plans</title>"."</head>"."<body>"."<form action=\"index.php\" method=\"post\">"."<table summary=\"Form Table\">"."<tr>"."<td>Model Name and/or Number: </td>"."<td><INPUT TYPE=\"text\" NAME=\"model\" value=\"$model\"></td>"."</tr>"."<tr>"."<td>Modular Building Category:</td>"."<td><INPUT TYPE=\"text\" NAME=\"cat\" value=\"$cat\"></td>"."</tr>"."<tr>"."<td>Building Type: </td>"."<td><INPUT TYPE=\"text\" NAME=\"title\" value=\"$title\"></td>"."</tr>"."<tr>"."<td>Square Footage: </td>"."<td><INPUT TYPE=\"text\" NAME=\"sqft\" value=\"$sqft\"></td>"."</tr>"."<tr>"."<td>Company or Name:</td>"."<td><INPUT TYPE=\"text\" NAME=\"name\" value=\"$name\"></td>"."</tr>"."<tr>"."<td>Location:</td>"."<td><INPUT TYPE=\"text\" NAME=\"location\" value=\"$location\"></td>"."</tr>"."<tr>"."<td>Large Outside:</td>"."<td><INPUT TYPE=\"text\" NAME=\"lgpic\" value=\"$lgpic\"></td>"."</tr>"."<tr>"."<td>Small Outside :</td>"."<td><INPUT TYPE=\"text\" NAME=\"smpic\" value=\"$smpic\"></td>"."</tr>"."<tr>"."<td>Interior 1:</td>"."<td><INPUT TYPE=\"text\" NAME=\"inside\" value=\"$inside\"></td>"."</tr>"."<tr>"."<td>Interior 2:</td>"."<td><INPUT TYPE=\"text\" NAME=\"inside1\" value=\"$inside1\"></td>"."</tr>"."<tr>"."<td>Interior 3:</td>"."<td><INPUT TYPE=\"text\" NAME=\"inside2\" value=\"$inside2\"></td>"."</tr>"."<tr>"."<td>Large 2d:</td>"."<td><INPUT TYPE=\"text\" NAME=\"lg2d\" value=\"$lg2d\"></td>"."</tr>"."<tr>"."<td>Small 2d:</td>"."<td><INPUT TYPE=\"text\" NAME=\"sm2d\" value=\"$sm2d\"></td>"."</tr>"."<tr>"."<td>Large 3d:</td>"."<td><INPUT TYPE=\"text\" NAME=\"lg3d\" value=\"$lg3d\"></td>"."</tr>"."<tr>"."<td>Small 3d:</td>"."<td><INPUT TYPE=\"text\" NAME=\"sm3d\" value=\"$sm3d\"></td>"."</tr>"."<tr>"."<td>PDF:</td>"."<td><INPUT TYPE=\"text\" NAME=\"pdf\" value=\"$pdf\"></td>"."</tr>"."<tr>"."<td>About:</td>"."<td><textarea name=\"about\" rows=\"10\" cols=\"40\">$about</textarea></td>"."</tr>"."<tr>"."<td>Need:</td>"."<td><textarea name=\"need\" rows=\"10\" cols=\"40\">$need</textarea></td>"."</tr>"."<tr>"."<td>Solution:</td>"."<td><textarea name=\"solution\" rows=\"10\" cols=\"40\">$solution</textarea></td>"."</tr>"."<tr>"."<td><input type=\"submit\" name=\"edittitle\" value=\"SUBMIT\"/></td></tr></table>"."</form>"."</body>"."</html>";
            }
            break;
        default;
            echo (
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"."<html>"."<head>"."<title>View Case Studies &amp; Floor Plans</title>"."<link rel=\"stylesheet\" type=\"text/css\" href=\"stylemaster.css\">"."</head>"."<body>"."<table class=\"page\" cellpadding=\"0\" cellspacing=\"0\" summary=\"layout\">"."<tr>"."<td>"."<table class=\"mainspecial\" cellpadding=\"0\" cellspacing=\"0\" summary=\"layout\">"."<tr>"."<td>"."<a href=\"/\">"."<img alt=\"Whitley Manufacturing\" src=\"/images/mast_2.jpg\" border=\"0\" width=\"750\" height=\"88\"></a>"."</td>"."</tr>"."</table>"."</td>"."</tr>"."<tr valign=\"top\">"."<td>"."<table class=\"content\" cellpadding=\"0\" cellspacing=\"0\" summary=\"layout\">"."<tr>"."<td valign=\"top\" width=\"150\">"."[+ inc('.mnu') +]"."</td>"."<td valign=\"top\" width=\"600\" align=\"center\">");
            echo (
    "<br><p align=\"center\"><a href='$PHP_SELF?input=1'>Add a title!</a></p><p align=\"center\">Here are all the titles in our database: </p><hr>");
                        include (
    'db.inc');
            if (
    "SUBMIT" == $edittitle) {
                
    $sql "UPDATE case_plans SET study='$study', plan='$plan', model='$model', cat='$cat', sqft='$sqft', title='$title', name='$name', location='$location', lgpic='$lgpic', smpic='$smpic', inside='$inside', inside1='$inside1', inside2='$inside2', lg2d='$lg2d', sm2d='$sm2d', lg3d='$lg3d', sm3d='$sm3d', pdf='$pdf', about='$about', need='$need', solution='$solution' WHERE id='$id'";
                if (
    pg_update($sql)) {
                    echo (
    "<P>Your title has been updated.</P>");
                } else {
                    echo (
    "<P>Error updating title: ".pg_last_error()."</P>");
                }
            }
            
    // If a title has been submitted,
            // add it to the database.
            
    if ("SUBMIT" == $submittitle) {
                
    $sql "INSERT INTO case_plans SET study='$study', plan='$plan', model='$model', cat='$cat', sqft='$sqft', title='$title', name='$name', location='$location', lgpic='$lgpic', smpic='$smpic', inside='$inside', inside1='$inside1', inside2='$inside2', lg2d='$lg2d', sm2d='$sm2d', lg3d='$lg3d', sm3d='$sm3d', pdf='$pdf', about='$about', need='$need', solution='$solution'";
                if (
    pg_insert($sql)) {
                    echo (
    "<P>Your title has been added.</P>");
                } else {
                    echo (
    "<P>Error adding submitted title: ".pg_last_error()."</P>");
                }
            }
            
    // If a title has been deleted,
            // remove it from the database.
            
    if (isset ($deletetitle)) {
                
    $sql "DELETE FROM case_plans WHERE id=$deletetitle";
                if (
    pg_query($sql)) {
                    echo (
    "<p>The title has been deleted.</p>");
                } else {
                    echo (
    "<p>Error deleting title: ".pg_last_error()."</p>");
                }
            }
            
    // Request the ID and text of all the titles
            
    $result pg_query("SELECT * FROM case_plans");
            if (!
    $result) {
                echo (
    "<p>Error performing query: ".pg_last_error()."</p>");
                exit ();
            }
            
    // Display the text of each title in a paragraph
            // with a "Delete this title" link next to each.
            
    while ($row pg_fetch_array($result)) {
                
    $id $row["id"];
                
    $plan $row["plan"];
                
    $study $row["study"];
                
    $model $row["model"];
                
    $cat $row["cat"];
                
    $sqft $row["sqft"];
                
    $title $row["title"];
                
    $name $row["name"];
                
    $location $row["location"];
                
    $lgpic $row["lgpic"];
                
    $smpic $row["smpic"];
                
    $inside $row["inside"];
                
    $inside1 $row["inside1"];
                
    $inside2 $row["inside2"];
                
    $lg2d $row["lg2d"];
                
    $sm2d $row["sm2d"];
                
    $lg3d $row["lg3d"];
                
    $sm3d $row["sm3d"];
                
    $pdf $row["pdf"];
                
    $about $row["about"];
                
    $need $row["need"];
                
    $solution $row["solution"];
                echo (
    "<BR><TABLE class=\"main\" summary=\"Modular Case Study - "."$name"." \">"."<TBODY>"."<TR>"."<TD valign=\"top\">"."<TABLE border=\"0\" width=\"100%\" cellpadding=\"2\" cellspacing=\"1\" summary=\"layout\">"."<TBODY>"."<TR>"."<TD colspan=\"2\">"."<P class=\"bannerhead\">"."$title"." - "."$location"."</P>"."</TD>"."</TR>"."<TR bgcolor=\"#ffffff\">"."<TD align=\"center\" width=\"200\">"."<P>"."<A onclick=\"MM_openBrWindow('"."$lgpic"."','','scrollbars=yes,width=535,height=400')\" href=\"javascript:;\">"."<IMG src=\""."$smpic"."\" alt=\""."$name"." - "."$location"."\" style=\"border: 0px\"></A>"."</P>"."</TD>"."<TD valign=\"top\">"."<p class=\"about\">About "."$name"."</p>"."<p>"."$about"."</P>"."</TD>"."</TR>"."<TR valign=\"top\">"."<TD colspan=\"2\" rowspan=\"1\" class=\"footer\">");
                if (
    $study == '1') {
                    echo (
    " <A href=\"case_study.html?"."$category"."&amp;"."$id"."\">Case Study</A> |");
                } else {
                    echo (
    "");
                }
                if (
    $plan == '1') {
                    echo (
    " <A href=\"floor_plans.html?"."$category"."&amp;"."$id"."\">Floor Plan</A> |");
                } else {
                    echo (
    "");
                }
                echo (
    " <A href=\""."$pdf"."\">PDF Brochure</A>"."<BR>"."<a href=\"$PHP_SELF?deletetitle=1&amp;id=$id\">"."Delete this title</a> "."| <a href=\"$PHP_SELF?input=2&amp;id=$id\">Edit this title</a>"."</TD>"."</TR>"."</TBODY>"."</TABLE>"."</TD>"."</TR>"."</TBODY>"."</TABLE>");
            }
            echo (
    "<br><table class=\"footer\" summary=\"layout\" cellpadding=\"0\" cellspacing=\"0\">"."<tbody><tr valign=\"top\">"."<td height=\"2\"></td>"."</tr>"."</tbody></table></tr></table><br>"."</td></tr></table></body>"."</html>");
            break;
    }
    ?>
    Last edited by ShadowTR; Jan 4, 2006 at 08:11.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The Case (switch) seems to work but addition do not get stored and the edit section errors:

    Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "id" at character 31 in /web/html/mysite.com/test/index.php on line 110

    PHP Code:
            $query "SELECT * FROM case_plans WERE id = $id"
    Last edited by ShadowTR; Jan 4, 2006 at 08:13.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it helps this is, the original, working code for mySql:

    PHP Code:
    <?php


    //if (isset($addtitle)): // If the user wants to add a title
    switch ($input) {
        case 
    :
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Submit Case Studies &amp; Floor Plans</title>
    </head>
    <body>
    <form action="<?php echo ($PHP_SELF?>" method="post">
    <table summary="Form Table">
    <tr>
    <td colspan="2"><b>If you enter a 1 in both boxes this will publish out as both a Case Study and a Floor Plan.</b><br><hr></td>
    </tr>
    <tr>
    <td align="right">Type 1 in the box if entering a Case Study:</td>
    <td><INPUT TYPE="text" NAME="study"></td>
    </tr>
    <tr>
    <td align="right">Type 1 in the box if entering a Floor Plan:</td>
    <td><INPUT TYPE="text" NAME="plan"></td>
    </tr>
    <tr>
    <td align="right">Model Name and/or Number: </td>
    <td><INPUT TYPE="text" NAME="model"></td>
    </tr>
    <tr>
    <td align="right">Modular Building Category:</td>
    <td><INPUT TYPE="text" NAME="cat"></td>
    </tr>
    <tr>
    <td align="right">Building Type: </td>
    <td><INPUT TYPE="text" NAME="title"></td>
    </tr>
    <tr>
    <td align="right">Square Footage: </td>
    <td><INPUT TYPE="text" NAME="sqft"></td>
    </tr>
    <tr>
    <td align="right">Company or Name:</td>
    <td><INPUT TYPE="text" NAME="name"></td>
    </tr>
    <tr>
    <td align="right">Location:</td>
    <td><INPUT TYPE="text" NAME="location"></td>
    </tr>
    <tr>
    <td align="right">Large Outside:</td>
    <td><INPUT TYPE="text" NAME="lgpic"></td>
    </tr>
    <tr>
    <td align="right">Small Outside :</td>
    <td><INPUT TYPE="text" NAME="smpic"></td>
    </tr>
    <tr>
    <td align="right">Interior 1:</td>
    <td><INPUT TYPE="text" NAME="inside"></td>
    </tr>
    <tr>
    <td align="right">Interior 2:</td>
    <td><INPUT TYPE="text" NAME="inside1"></td>
    </tr>
    <tr>
    <td align="right">Interior 3:</td>
    <td><INPUT TYPE="text" NAME="inside2"></td>
    </tr>
    <tr>
    <td align="right">Large 2d:</td>
    <td><INPUT TYPE="text" NAME="lg2d"></td>
    </tr>
    <tr>
    <td align="right">Small 2d:</td>
    <td><INPUT TYPE="text" NAME="sm2d"></td>
    </tr>
    <tr>
    <td align="right">Large 3d:</td>
    <td><INPUT TYPE="text" NAME="lg3d"></td>
    </tr>
    <tr>
    <td align="right">Small 3d:</td>
    <td><INPUT TYPE="text" NAME="sm3d"></td>
    </tr>
    <tr>
    <td align="right">PDF:</td>
    <td><INPUT TYPE="text" NAME="pdf"></td>
    </tr>
    <tr>
    <td align="right">About:</td>
    <td><textarea name="about" rows="10" cols="40"></textarea></td>
    </tr>
    <tr>
    <td align="right">Need:</td>
    <td><textarea name="need" rows="10" cols="40"></textarea></td>
    </tr>
    <tr>
    <td align="right">Solution:</td>
    <td><textarea name="solution" rows="10" cols="40"></textarea></td>
    </tr>
    <tr>
    <td><input type="submit" name="submittitle" value="SUBMIT"/></td></tr></table>
    </form>
    </body>
    </html>
    <?php


            
    break;
    ?>
    <?php


        
    case :
            include (
    'db.inc');
            
    $query "SELECT * FROM case_plans Where id = $id";
            
    $result mysql_query($query) or die('Error, query failed');

            while (
    $row mysql_fetch_array($result)) {
                
    $id $row["id"];
                
    $plan $row["plan"];
                
    $study $row["study"];
                
    $model $row["model"];
                
    $cat $row["cat"];
                
    $sqft $row["sqft"];
                
    $title $row["title"];
                
    $name $row["name"];
                
    $location $row["location"];
                
    $about $row["about"];
                
    $need $row["need"];
                
    $solution $row["solution"];
                
    $pdf $row["pdf"];
                
    $lgpic $row["lgpic"];
                
    $smpic $row["smpic"];
                
    $lg2d $row["lg2d"];
                
    $sm2d $row["sm2d"];
                
    $lg3d $row["lg3d"];
                
    $sm3d $row["sm3d"];

                print 
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"."<html>"."<head>"."<title>Edit Case Studies &amp; Floor Plans</title>"."</head>"."<body>"."<form action=\"admin.php\" method=\"post\">"."<table summary=\"Form Table\">"."<tr>"."<td>Model Name and/or Number: </td>"."<td><INPUT TYPE=\"text\" NAME=\"model\" value=\"$model\"></td>"."</tr>"."<tr>"."<td>Modular Building Category:</td>"."<td><INPUT TYPE=\"text\" NAME=\"cat\" value=\"$cat\"></td>"."</tr>"."<tr>"."<td>Building Type: </td>"."<td><INPUT TYPE=\"text\" NAME=\"title\" value=\"$title\"></td>"."</tr>"."<tr>"."<td>Square Footage: </td>"."<td><INPUT TYPE=\"text\" NAME=\"sqft\" value=\"$sqft\"></td>"."</tr>"."<tr>"."<td>Company or Name:</td>"."<td><INPUT TYPE=\"text\" NAME=\"name\" value=\"$name\"></td>"."</tr>"."<tr>"."<td>Location:</td>"."<td><INPUT TYPE=\"text\" NAME=\"location\" value=\"$location\"></td>"."</tr>"."<tr>"."<td>Large Outside:</td>"."<td><INPUT TYPE=\"text\" NAME=\"lgpic\" value=\"$lgpic\"></td>"."</tr>"."<tr>"."<td>Small Outside :</td>"."<td><INPUT TYPE=\"text\" NAME=\"smpic\" value=\"$smpic\"></td>"."</tr>"."<tr>"."<td>Interior 1:</td>"."<td><INPUT TYPE=\"text\" NAME=\"inside\" value=\"$inside\"></td>"."</tr>"."<tr>"."<td>Interior 2:</td>"."<td><INPUT TYPE=\"text\" NAME=\"inside1\" value=\"$inside1\"></td>"."</tr>"."<tr>"."<td>Interior 3:</td>"."<td><INPUT TYPE=\"text\" NAME=\"inside2\" value=\"$inside2\"></td>"."</tr>"."<tr>"."<td>Large 2d:</td>"."<td><INPUT TYPE=\"text\" NAME=\"lg2d\" value=\"$lg2d\"></td>"."</tr>"."<tr>"."<td>Small 2d:</td>"."<td><INPUT TYPE=\"text\" NAME=\"sm2d\" value=\"$sm2d\"></td>"."</tr>"."<tr>"."<td>Large 3d:</td>"."<td><INPUT TYPE=\"text\" NAME=\"lg3d\" value=\"$lg3d\"></td>"."</tr>"."<tr>"."<td>Small 3d:</td>"."<td><INPUT TYPE=\"text\" NAME=\"sm3d\" value=\"$sm3d\"></td>"."</tr>"."<tr>"."<td>PDF:</td>"."<td><INPUT TYPE=\"text\" NAME=\"pdf\" value=\"$pdf\"></td>"."</tr>"."<tr>"."<td>About:</td>"."<td><textarea name=\"about\" rows=\"10\" cols=\"40\">$about</textarea></td>"."</tr>"."<tr>"."<td>Need:</td>"."<td><textarea name=\"need\" rows=\"10\" cols=\"40\">$need</textarea></td>"."</tr>"."<tr>"."<td>Solution:</td>"."<td><textarea name=\"solution\" rows=\"10\" cols=\"40\">$solution</textarea></td>"."</tr>"."<tr>"."<td><input type=\"submit\" name=\"edittitle\" value=\"SUBMIT\"/></td></tr></table>"."</form>"."</body>"."</html>";
            }
    ?>
    <?php


            
    break;
    ?>
    <?php


        
    default;
            
    // Connect to the database server

            
    include ('db.inc');
            echo (
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"."<html>"."<head>"."<title>View Case Studies &amp; Floor Plans</title>"."<link rel=\"stylesheet\" type=\"text/css\" href=\"stylemaster.css\">"."</head>"."<body>"."<table class=\"page\" cellpadding=\"0\" cellspacing=\"0\" summary=\"layout\">"."<tr>"."<td>"."<table class=\"mainspecial\" cellpadding=\"0\" cellspacing=\"0\" summary=\"layout\">"."<tr>"."<td>"."<a href=\"/\">"."<img alt=\"Whitley Manufacturing\" src=\"/images/mast_2.jpg\" border=\"0\" width=\"750\" height=\"88\"></a>"."</td>"."</tr>"."</table>"."</td>"."</tr>"."<tr valign=\"top\">"."<td>"."<table class=\"content\" cellpadding=\"0\" cellspacing=\"0\" summary=\"layout\">"."<tr>"."<td valign=\"top\" width=\"150\">"."[+ inc('.mnu') +]"."</td>"."<td valign=\"top\" width=\"600\" align=\"center\">");
            echo (
    "<br><p align=\"center\"><a href='$PHP_SELF?input=1'>Add a title!</a></p><p align=\"center\">Here are all the titles in our database: </p><hr>");

            if (
    "SUBMIT" == $edittitle) {
                
    $sql "UPDATE case_plans SET study='$study', plan='$plan', model='$model', cat='$cat', sqft='$sqft', title='$title', name='$name', location='$location', lgpic='$lgpic', smpic='$smpic', inside='$inside', inside1='$inside1', inside2='$inside2', lg2d='$lg2d', sm2d='$sm2d', lg3d='$lg3d', sm3d='$sm3d', pdf='$pdf', about='$about', need='$need', solution='$solution' WHERE id='$id'";
                if (
    mysql_query($sql)) {
                    echo (
    "<P>Your title has been updated.</P>");
                } else {
                    echo (
    "<P>Error updating title: ".mysql_error()."</P>");
                }
            }

            
    // If a title has been submitted,
            // add it to the database.

            
    if ("SUBMIT" == $submittitle) {
                
    $sql "INSERT INTO case_plans SET study='$study', plan='$plan', model='$model', cat='$cat', sqft='$sqft', title='$title', name='$name', location='$location', lgpic='$lgpic', smpic='$smpic', inside='$inside', inside1='$inside1', inside2='$inside2', lg2d='$lg2d', sm2d='$sm2d', lg3d='$lg3d', sm3d='$sm3d', pdf='$pdf', about='$about', need='$need', solution='$solution'";
                if (
    mysql_query($sql)) {
                    echo (
    "<P>Your title has been added.</P>");
                } else {
                    echo (
    "<P>Error adding submitted title: ".mysql_error()."</P>");
                }
            }

            
    // If a title has been deleted,
            // remove it from the database.
            
    if (isset ($deletetitle)) {
                
    $sql "DELETE FROM case_plans WHERE id=$deletetitle";
                if (@ 
    mysql_query($sql)) {
                    echo (
    "<p>The title has been deleted.</p>");
                } else {
                    echo (
    "<p>Error deleting title: ".mysql_error()."</p>");
                }
            }
            
    // Request the ID and text of all the titles
            
    $result = @ mysql_query("SELECT * FROM case_plans");
            if (!
    $result) {
                echo (
    "<p>Error performing query: ".mysql_error()."</p>");
                exit ();
            }

            
    // Display the text of each title in a paragraph
            // with a "Delete this title" link next to each.

            
    while ($row mysql_fetch_array($result)) {
                
    $id $row["id"];
                
    $plan $row["plan"];
                
    $study $row["study"];
                
    $model $row["model"];
                
    $cat $row["cat"];
                
    $sqft $row["sqft"];
                
    $title $row["title"];
                
    $name $row["name"];
                
    $location $row["location"];
                
    $lgpic $row["lgpic"];
                
    $smpic $row["smpic"];
                
    $inside $row["inside"];
                
    $inside1 $row["inside1"];
                
    $inside2 $row["inside2"];
                
    $lg2d $row["lg2d"];
                
    $sm2d $row["sm2d"];
                
    $lg3d $row["lg3d"];
                
    $sm3d $row["sm3d"];
                
    $pdf $row["pdf"];
                
    $about $row["about"];
                
    $need $row["need"];
                
    $solution $row["solution"];

                echo (
    "<BR><TABLE class=\"main\" summary=\"Modular Case Study - "."$name"." \">"."<TBODY>"."<TR>"."<TD valign=\"top\">"."<TABLE border=\"0\" width=\"100%\" cellpadding=\"2\" cellspacing=\"1\" summary=\"layout\">"."<TBODY>"."<TR>"."<TD colspan=\"2\">"."<P class=\"bannerhead\">"."$title"." - "."$location"."</P>"."</TD>"."</TR>"."<TR bgcolor=\"#ffffff\">"."<TD align=\"center\" width=\"200\">"."<P>"."<A onclick=\"MM_openBrWindow('"."$lgpic"."','','scrollbars=yes,width=535,height=400')\" href=\"javascript:;\">"."<IMG src=\""."$smpic"."\" alt=\""."$name"." - "."$location"."\" style=\"border: 0px\"></A>"."</P>"."</TD>"."<TD valign=\"top\">"."<p class=\"about\">About "."$name"."</p>"."<p>"."$about"."</P>"."</TD>"."</TR>"."<TR valign=\"top\">"."<TD colspan=\"2\" rowspan=\"1\" class=\"footer\">");
                if (
    $study == '1') {
                    echo (
    " <A href=\"case_study.html?"."$category"."&amp;"."$id"."\">Case Study</A> |");
                } else {
                    echo (
    "");
                }
                if (
    $plan == '1') {
                    echo (
    " <A href=\"floor_plans.html?"."$category"."&amp;"."$id"."\">Floor Plan</A> |");
                } else {
                    echo (
    "");
                }
                echo (
    " <A href=\""."$pdf"."\">PDF Brochure</A>"."<BR>"."<a href=\"$PHP_SELF?deletetitle=$id\">"."Delete this title</a> "."| <a href=\"$PHP_SELF?input=2&amp;id=$id\">Edit this title</a>"."</TD>"."</TR>"."</TBODY>"."</TABLE>"."</TD>"."</TR>"."</TBODY>"."</TABLE>");
            }
            echo (
    "<br><table class=\"footer\" summary=\"layout\" cellpadding=\"0\" cellspacing=\"0\">"."<tbody><tr valign=\"top\">"."<td height=\"2\"></td>"."</tr>"."</tbody></table></tr></table><br>"."</td></tr></table></body>"."</html>");
            break;
    }
    // When clicked, this link will load this page
    // with the title submission form displayed.
    ?>

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does no one use Postgre, have experience related or have I not phrased my need/problem correctly?
    Last edited by ShadowTR; Jan 4, 2006 at 16:33.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump....

    still looking for answers

  6. #6
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have a typo.

    $query = "SELECT * FROM case_plans WERE id = $id";
    should be:
    $query = "SELECT * FROM case_plans WHERE id = $id";

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doh, you're right there, I missed it... Made the change, yet I'm still getting an error...

    Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at end of input at character 37 in /web/html/mysite.com/test/index.php on line 110
    Error, query failed

    107-122:

    PHP Code:
        case :
            include (
    'db.inc');
            
    $query "SELECT * FROM case_plans WHERE id = $id";
            
    $result pg_query($query) or die('Error, query failed');
            while (
    $row pg_fetch_array($result)) {
            include (
    'array.inc'); 

  8. #8
    _ silver trophy ses5909's Avatar
    Join Date
    Jul 2003
    Location
    NoVa
    Posts
    5,466
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Doesn't look like you have a closing brace there.
    Sara

  9. #9
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I'm missing it, please illustrate...

  10. #10
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check $id is set ok, e.g:
    $query = "SELECT * FROM case_plans WHERE id = $id";
    echo 'DEBUG: '.$query;

  11. #11
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    added:
    PHP Code:
    $id $_GET['id']; 
    to the top of the page...

    That fixed the problem with pulling the edit page up with the correct data loaded for editing.... Thanks!

    Yet my edit (update) routine does not seem to be working.

  12. #12
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please exercise some input filtering on that!

    for example
    PHP Code:
     $id $_GET['id'];
     if ( 
    ctype_digit$id ) )
     {
         
    // proceed
     
    } else {
         echo 
    'Type mismatch with ID value';
     } 
    Otherwise you're leaving yourself WIDE open for SQL injection
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  13. #13
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks beetle,

    Excerpt the echo is shown on the initial default landing now... and causes the delete function to stop working...

  14. #14
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what I posted was just an example - you need to properly check for type and throw errors so that they work with your script/application.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  15. #15
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I follow that, would you say this is necessary even if the script in question is stored in secured folder?

  16. #16
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW: Any thoughts on my scripting problems above?

  17. #17
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ShadowTR
    Okay, I follow that, would you say this is necessary even if the script in question is stored in secured folder?
    The location of the PHP file on you server's drive has nothing to do with it's vulnerability to attacks crafted in query-string values.

    You should always, always, ALWAYS filter input - especially if that input is being stored into a databse.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  18. #18
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks

  19. #19
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If anyone would be so kind to look over my script and tell me why the add & edit portions of my script are not working it would be greatly appreciated...

  20. #20
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Fort Wayne, Indiana
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm still having no luck with the update/add parts of this script. Please take a look and tell me where I have gone wrong...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •