DasHaas Posted May 24, 2007 Share Posted May 24, 2007 Im trying to run an insert statement that inserts the site name, url, and compiled html code to my mysql table. Needless to say it is not working and I'm sure its the compiled html field that is giving me problems. Here is my code, any help would be greatly appreciated :-\ $compurl = "<a href="http://$txturl" target="_blank">$txtname</>"; $query = "INSERT INTO PXS_Links(site_name, site_url, compiled_url) VALUES('$name', '$url','$compurl')"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); I dont think it likes the double quotes here is an example of what i want to put into the table: example: $name = 'Yahoo' $url = 'www.yahoo.com' $compurl should be <a href="http://www.yahoo.com" "_blank">Yahoo</> Quote Link to comment https://forums.phpfreaks.com/topic/52864-solved-mysql-insert-a-compiled-html-link/ Share on other sites More sharing options...
Wildbug Posted May 24, 2007 Share Posted May 24, 2007 You need to escape those double quotes. Just put a slash (\) in front of those double quotes inside the string. Otherwise, use single quotes and concatenate or sprintf(). (Also you're missing the "a" in "</a>") Quote Link to comment https://forums.phpfreaks.com/topic/52864-solved-mysql-insert-a-compiled-html-link/#findComment-261031 Share on other sites More sharing options...
fenway Posted May 24, 2007 Share Posted May 24, 2007 There's a mysql_real_escape_string() function just for that purpose, AFAIK. Quote Link to comment https://forums.phpfreaks.com/topic/52864-solved-mysql-insert-a-compiled-html-link/#findComment-261105 Share on other sites More sharing options...
DasHaas Posted May 24, 2007 Author Share Posted May 24, 2007 I made the changes that Wildbug posted and I got the following error: Error in query: INSERT INTO PXS_Links(site_name, site_url, compiled_url) VALUES(Myspace, www.myspace.com,Myspace). You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Myspace)' a <html> <head> <link href="css/StyleSheet1.css" rel="stylesheet" type="text/css"> <body> <!-- standard page header begins --> <table width="100%" class="table1"> <tr> <td><div align="center" class="text2">Add Links </div></td> </tr> </table<br> <!-- standard page header ends --> <?php // form not yet submitted // display initial form if (!$_POST['submit']) { ?> <table cellpadding="5" cellspacing="5" class="table1"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <tr> <td valign="top"><b class="text5"><font size="-1">Site Name </font></b></td> <td> <input name="txtname" type="text" class="table2" id="txtname" value="ex. Yahoo" size="50" maxlength="250"> </td> </tr> <tr> <td valign="top"><b class="text5"><font size="-1">Site URL </font></b></td> <td><input name="txturl" type="text" class="table2" id="txturl" value="ex. www.yahoo.com" size="50" maxlength="250"></td> </tr> <tr> <td colspan="2" valign="top"><input type="Submit" name="submit" value="Add"> <input type="reset" name="Reset" value="Reset"></td> </tr> </form> </table> <?php } else { // includes include('Includes/PXS_Conf.php'); // set up error list array $errorList = array(); $name = $_POST['txtname']; $url = $_POST['txturl']; // validate text input fields if (trim($_POST['txtname']) == '') { $errorList[] = 'Invalid entry: Site Name'; } if (trim($_POST['txturl']) == '') { $errorList[] = "Invalid entry: Site Url"; } // check for errors // if none found... if (sizeof($errorList) == 0) { // open database connection $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect to MySql server! Please contact PXS customer support.'); // select database mysql_select_db($db) or die ('Unable to select database! Please contact PXS customer support.'); //set link url $compurl = "<a href=\"http://$txturl\" target=\"_blank\">$txtname</a>"; // generate and execute query $query = "INSERT INTO PXS_Links(site_name, site_url, compiled_url) VALUES($name, $url,$compurl)"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // close database connection mysql_close($connection); // print result echo '<center><a href=PXS_ListLinks.php>Addition successful click here to go back to the links list</a></center>'; } else { // errors found // print as list echo '<font size=-1>The following errors were encountered:'; echo '<br>'; echo '<ul>'; for ($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo '</ul></font>'; } } ?> <!-- standard page footer begins --> <br><table width="100%" class="table1"> <tr> <td><div align="center" class="text1"> <div align="center">Copyright © 2006 Projekt-X-Studios. All Rights Reserved </div> </div></td> </tr> </table> <!-- standard page footer ends --> </body> </html> any suggestions, I have been staring at this for the last 30 min and cant find the error :'( Im sure its something obvious but my brian is jello today ??? Quote Link to comment https://forums.phpfreaks.com/topic/52864-solved-mysql-insert-a-compiled-html-link/#findComment-261179 Share on other sites More sharing options...
bubblegum.anarchy Posted May 25, 2007 Share Posted May 25, 2007 The values listed in the error are not quoted. Quote Link to comment https://forums.phpfreaks.com/topic/52864-solved-mysql-insert-a-compiled-html-link/#findComment-261249 Share on other sites More sharing options...
DasHaas Posted May 25, 2007 Author Share Posted May 25, 2007 I'm an idiot lol Quote Link to comment https://forums.phpfreaks.com/topic/52864-solved-mysql-insert-a-compiled-html-link/#findComment-261565 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.