Jump to content

Recommended Posts

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</>

Link to comment
https://forums.phpfreaks.com/topic/52864-solved-mysql-insert-a-compiled-html-link/
Share on other sites

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 ???

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.