Jump to content

[SOLVED] what to do with the ""'s


joshgarrod

Recommended Posts

Hi all, a really simple dimwit question here i guess. I have written a script that i can add links to a database and another script to display them on a page. Is there anything I can add in my code or is there anyway to stop it from messing up when i put hyperlinks into the form? I guess hat it is the ""'s that is doing it. I am submitting them using a form but the form goes all screwy??? if you know the answer to this please help me. thanks

Link to comment
Share on other sites

Here is a copy of my script for submitting daa:

 

<?php

    $usr = "sgfdjdfghj";
    $pwd = "ijhfhjk";
    $db = "stfghjk";
    $host = "localhost";

    # connect to database
    $cid = mysql_connect($host,$usr,$pwd);
    mysql_selectdb($db);
    if (!$cid) { echo("ERROR: " . mysql_error() . "\n");    }

?>
   </font></p>
   <TITLE></TITLE>
<P>Update feature catgories </P>

   <font face="Arial, Helvetica, sans-serif">
<?php
      $query = "SELECT * FROM `hometext`";
        $result = mysql_query($query);

$Catname1=mysql_result($result,0,"Catname1");
$Catname2=mysql_result($result,0,"Catname2");
$Catname3=mysql_result($result,0,"Catname3");
$Cat1Article1=mysql_result($result,0,"Cat1Article1");
$Cat1Article2=mysql_result($result,0,"Cat1Article2");
$Cat1Article3=mysql_result($result,0,"Cat1Article3");
$Cat1Article4=mysql_result($result,0,"Cat1Article4");
$Cat1Article5=mysql_result($result,0,"Cat1Article5");
$Cat2Article1=mysql_result($result,0,"Cat2Article1");
$Cat2Article2=mysql_result($result,0,"Cat2Article2");
$Cat2Article3=mysql_result($result,0,"Cat2Article3");
$Cat2Article4=mysql_result($result,0,"Cat2Article4");
$Cat2Article5=mysql_result($result,0,"Cat2Article5");
$Cat3Article1=mysql_result($result,0,"Cat3Article1");
$Cat3Article2=mysql_result($result,0,"Cat3Article2");
$Cat3Article3=mysql_result($result,0,"Cat3Article3");
$Cat3Article4=mysql_result($result,0,"Cat3Article4");
$Cat3Article5=mysql_result($result,0,"Cat3Article5");

    # this is processed when the form is submitted
    # back on to this page (POST METHOD)
    if ($REQUEST_METHOD=="POST") {

$Catname1=$_POST["Catname1"];
$Catname2=$_POST["Catname2"];
$Catname3=$_POST["Catname3"];
$Cat1Article1=$_POST["Cat1Article1"];
$Cat1Article2=$_POST["Cat1Article2"];
$Cat1Article3=$_POST["Cat1Article3"];
$Cat1Article4=$_POST["Cat1Article4"];
$Cat1Article5=$_POST["Cat1Article5"];
$Cat2Article1=$_POST["Cat2Article1"];
$Cat2Article2=$_POST["Cat2Article2"];
$Cat2Article3=$_POST["Cat2Article3"];
$Cat2Article4=$_POST["Cat2Article4"];
$Cat2Article5=$_POST["Cat2Article5"];
$Cat3Article1=$_POST["Cat3Article1"];
$Cat3Article2=$_POST["Cat3Article2"];
$Cat3Article3=$_POST["Cat3Article3"];
$Cat3Article4=$_POST["Cat3Article4"];
$Cat3Article5=$_POST["Cat3Article5"];

        # double-up apostrophes
	$Catname1 = str_replace("'","''",$Catname1);
	$Catname2 = str_replace("'","''",$Catname2);
	$Catname3 = str_replace("'","''",$Catname3);
	$Cat1Article1 = str_replace("'","''",$Cat1Article1);
	$Cat1Article2 = str_replace("'","''",$Cat1Article2);
	$Cat1Article3 = str_replace("'","''",$Cat1Article3);
	$Cat1Article4 = str_replace("'","''",$Cat1Article4);
	$Cat1Article5 = str_replace("'","''",$Cat1Article5);
	$Cat2Article1 = str_replace("'","''",$Cat2Article1);
	$Cat2Article2 = str_replace("'","''",$Cat2Article2);
	$Cat2Article3 = str_replace("'","''",$Cat2Article3);
	$Cat2Article4 = str_replace("'","''",$Cat2Article4);
	$Cat2Article5 = str_replace("'","''",$Cat2Article5);
	$Cat3Article1 = str_replace("'","''",$Cat3Article1);
	$Cat3Article2 = str_replace("'","''",$Cat3Article2);
	$Cat3Article3 = str_replace("'","''",$Cat3Article3);
	$Cat3Article4 = str_replace("'","''",$Cat3Article4);
	$Cat3Article5 = str_replace("'","''",$Cat3Article5);

        # setup SQL statement
	$SQL = "UPDATE `hometext` SET `Catname1` = '$Catname1',
	`Catname2` = '$Catname2',
	`Catname3` = '$Catname3',
	`Cat1Article1` = '$Cat1Article1',
	`Cat1Article2` = '$Cat1Article2',
	`Cat1Article3` = '$Cat1Article3',
	`Cat1Article4` = '$Cat1Article4',
	`Cat1Article5` = '$Cat1Article5',
	`Cat2Article1` = '$Cat2Article1',
	`Cat2Article2` = '$Cat2Article2',
	`Cat2Article3` = '$Cat2Article3',
	`Cat2Article4` = '$Cat2Article4',
	`Cat2Article5` = '$Cat2Article5',
	`Cat3Article1` = '$Cat3Article1',
	`Cat3Article2` = '$Cat3Article2',
	`Cat3Article3` = '$Cat3Article3',
	`Cat3Article4` = '$Cat3Article4',
	`Cat3Article5` = '$Cat3Article5' WHERE `hometext`.`ID` =1 ;";

        #execute SQL statement
        $result = mysql_db_query($db,"$SQL",$cid);
	$ID=mysql_insert_id();


        # check for error
        if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");    }

        echo ("<P>Feature categories updated updated</P>\n");

    }

?>

Link to comment
Share on other sites

i presume one of your $Cat1Article's contains the link with the " in it?

 

Before you add it to the database you should do the following:

 

$Cat1Article4 = addslashes($Cat1Article4);

 

A handy way, i find, to figure out the problem is to do an echo $SQL; that way you can see your query.

 

You probably have something like "UPDATE `hometext` SET `Catname1` = '<a href="www.google.com">Google[/url]',

 

so what's happening is the sql is closing on the first " if you do addslashes it'll look more like this:

 

"UPDATE `hometext` SET `Catname1` = '<a href=\"www.google.com\">Google[/url]',

 

the backslashes allow mysql to add the data

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.