#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    St. Petersburg, Fl. USA
    Posts
    2
    Rep Power
    0
    Please forgive me as I am new to this. I tried the escaping code in a variety of ways in my script and still no luck. My server is running PHP3 and MySQL 3.22. The only fields where apostrophes will need to be dealt with are the 'name' and 'location1' thru 'location3'.

    Here is the code from the form generating PHP script for modifying the database:

    mysql_select_db("meetings",$db);

    if ($submit) {



    if ($id) {

    $sql = "UPDATE list SET day='$day',time='$time',ampm='$ampm',sort='$sort',code='$code',name='$name',location1='$location1',l ocation2='$location2',location3='$location3' WHERE id=$id";

    } else {

    $sql = "INSERT INTO list (day,time,ampm,sort,code,name,location1,location2,location3) VALUES ('$day','$time','$ampm','$sort','$code','$name','$location1','$location2','$location3')";

    }



    $result = mysql_query($sql);

    echo "Record updated/edited!<p>";

    echo "<center><a href="edit.php3">Back</a></center>";

    } elseif ($delete) {

    // delete a record

    $sql = "DELETE FROM list WHERE id=$id";

    $result = mysql_query($sql);

    echo "$sql Record deleted!<p>";

    echo "<center><a href="edit.php3">Back</a></center>";

    } else {

    // this part happens if we don't press submit

    if (!$id) {

    // print the list if there is not editing

    $result = mysql_query("SELECT * FROM list",$db);

    while ($myrow = mysql_fetch_array($result)) {

    printf("<a href="%s?id=%s">%s %s %s</a> n", $PHP_SELF, $myrow["id"], $myrow["day"], $myrow["time"], $myrow["name"]);

    printf("<a href="%s?id=%s&delete=yes">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);

    }

    }

    ?>

    <P>

    <a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>

    <P>

    <form method="post" action="<?php echo $PHP_SELF?>">

    <?php

    if ($id) {

    // editing so select a record

    $sql = "SELECT * FROM list WHERE id=$id";

    $result = mysql_query($sql);

    $myrow = mysql_fetch_array($result);

    $id = $myrow["id"];

    $day = $myrow["day"];

    $time = $myrow["time"];

    $ampm = $myrow["ampm"];

    $sort = $myrow["sort"];

    $code = $myrow["code"];

    $name = $myrow["name"];

    $location1 = $myrow["location1"];

    $location2 = $myrow["location2"];

    $location3 = $myrow["location3"];

    // print the id for editing

    ?>

    <input type=hidden name="id" value="<?php echo $id ?>">

    <?php

    }

    ?>

    <center>
    <table width="80%" cellpadding="5" align="CENTER">
    <tr>
    <td align="right">Day: </td><td><input type="Text" name="day" value="<?php echo $day ?>"></td><td align="right">Time: </td><td><input type="Text" name="time" value="<?php echo $time ?>"></td>
    </tr>
    <tr>
    <td align="right">AM,Noon,PM,Mid: </td><td><input type="Text" name="ampm" value="<?php echo $ampm ?>"></td><td align="right">1=AM,2=Noon,3=PM,4=Midnight: </td><td><input type="Text" name="sort" value="<?php echo $sort ?>"></td>
    </tr>
    <tr>
    <td align="right">Codes: </td><td><input type="Text" name="code" value="<?php echo $code ?>"></td><td align="right">Group: </td><td><input type="Text" name="name" value="<?php echo $name ?>"></td>
    </tr>
    <tr>
    <td align="right">Location 1: </td><td><input type="Text" name="location1" value="<?php echo $location1 ?>"></td><td align="right">Location 2: </td><td><input type="Text" name="location2" value="<?php echo $location2 ?>"></td>
    </tr>
    <tr>
    <td align="right">Location 3: </td><td><input type="Text" name="location3" value="<?php echo $location3 ?>"></td>
    </tr>
    </table></center>
    <center><input type="Submit" name="submit" value="Enter information"></center>
    </form>


    <?php

    }

    ?>


    Here is the code for the script that prints out records from the database:


    mysql_select_db("meetings",$db);

    $bgcolor = "99CCFF";


    $result = mysql_query("SELECT * FROM list WHERE day = 'Saturday' ORDER BY sort, time",$db);

    if ($myrow = mysql_fetch_array($result)) {


    echo "<center><table cellspacing="0" cellpadding="10" width="80%" border="0">n";

    echo "<th align="center" colspan="4"><font face="Times New Roman, Helvetica, Swiss" size="+2" color="#000099">Saturday Meetings</font></th>n";

    echo "<tr>
    <td colspan="4"><font face="Arial, sans-serif, Helvetica" size="-2">Meeting Codes: O - Open (all wellcome);
    C - Closed (addicts only); D - Discussion; NS - Non-smoking; H - Handicapped Accessible; S&amp;T - Steps &amp; Traditions; PT - Principles and tools;
    HW - How and Why; W - Women's Meeting; BT - Basic Text Study; ST - Step Meeting; LS - Literature Study; SP - Speaker Meeting; T - Topic; M - Men's meeting; ASL - Interpreted; BEG - Beginners</font></td>
    </tr>";

    echo "<tr bgcolor="#99ccff">
    <td><font face="Arial, sans-serif, Helvetica" size="+1" color="#993333">Time</font></td>
    <td><font face="Arial, sans-serif, Helvetica" size="+1" color="#993333">Codes</font></td>
    <td><font face="Arial, sans-serif, Helvetica" size="+1" color="#993333">Group</font></td>
    <td><font face="Arial, sans-serif, Helvetica" size="+1" color="#993333">Location</font></td>
    </tr>n";


    do {

    if ($bgcolor = "99CCFF") {

    $bgcolor = "FFFFCC";



    }else{

    $bgcolor = "99CCFF";



    }

    printf("<tr bgcolor="$bgcolor">
    <td><font face="Arial, sans-serif, Helvetica" size="2">%s %s</font></td>
    <td><font face="Arial, sans-serif, Helvetica" size="2">%s</font></td>
    <td><font face="Arial, sans-serif, Helvetica" size="2">%s</font></td>
    <td><font face="Arial, sans-serif, Helvetica" size="2">%s<br>%s<br>%s</font></td>
    </tr>n", $myrow["time"], $myrow["ampm"], $myrow["code"], $myrow["name"], $myrow["location1"], $myrow["location2"], $myrow["location3"]);


    } while ($myrow = mysql_fetch_array($result));


    echo "</table></center>n";

    } else {

    echo "Sorry, no records were found!";

    }

    ?>

    Any help would be very much appreciated.

    Kindest Regards,

    Dave Lavallee
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    24
    Rep Power
    0
    If u need to deal with apostrophes to write to the mysql database, all u need to do is :

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $var = addslashes($var);
    [/code]

Similar Threads

  1. Escaping special characters in XML
    By JessJenn in forum PHP Development
    Replies: 1
    Last Post: January 5th, 2004, 05:19 PM
  2. showing special characters in a javascript menu
    By Whip in forum JavaScript Development
    Replies: 9
    Last Post: October 20th, 2003, 02:47 AM
  3. mod_rewrite & special characters - % screws things up! (HELP)
    By hknight in forum Apache Development
    Replies: 1
    Last Post: July 31st, 2003, 12:12 PM
  4. Catching special characters
    By hijinx in forum PHP Development
    Replies: 0
    Last Post: March 1st, 2003, 09:13 PM
  5. Dealing with special characters in forms
    By michaelcaplan in forum HTML Programming
    Replies: 1
    Last Post: January 4th, 2003, 02:37 PM

IMN logo majestic logo threadwatch logo seochat tools logo