joshgarrod Posted January 30, 2008 Share Posted January 30, 2008 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 Quote Link to comment Share on other sites More sharing options...
c_shelswell Posted January 30, 2008 Share Posted January 30, 2008 can you give an example of one of the links you're trying to add? I think a link should go in to the database fine as they can't contain " anyway Quote Link to comment Share on other sites More sharing options...
joshgarrod Posted January 30, 2008 Author Share Posted January 30, 2008 <a href="www.google.com">Google</a> Quote Link to comment Share on other sites More sharing options...
c_shelswell Posted January 30, 2008 Share Posted January 30, 2008 ah right so you're trying to add the whole a href bit too. You should just add do: $link = addslashes('yourlink'); then you can add it to the db. Don't forget to stripslashes on the way back tho hope that helps Quote Link to comment Share on other sites More sharing options...
joshgarrod Posted January 30, 2008 Author Share Posted January 30, 2008 I am sorry, how do you mean? Quote Link to comment Share on other sites More sharing options...
joshgarrod Posted January 30, 2008 Author Share Posted January 30, 2008 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"); } ?> Quote Link to comment Share on other sites More sharing options...
c_shelswell Posted January 30, 2008 Share Posted January 30, 2008 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 Quote Link to comment Share on other sites More sharing options...
joshgarrod Posted January 30, 2008 Author Share Posted January 30, 2008 ok and to remove slashes i assum 'stripslashes' Quote Link to comment Share on other sites More sharing options...
c_shelswell Posted January 30, 2008 Share Posted January 30, 2008 sure is cheers Quote Link to comment Share on other sites More sharing options...
joshgarrod Posted January 30, 2008 Author Share Posted January 30, 2008 thanks v much, helped me out Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.