Jump to content

insert HTML code into sql table via php form


Alexhoward

Recommended Posts

hi does any one know how to insert a html code like this

<a href="http://rover.ebay.com/rover/1/710-5232-2978-8/1?aid=5834748&pid=2804964" target="_blank" onmouseover="window.status='http://www.ebay.co.uk';return true;" onmouseout="window.status=' ';return true;">
<img src="http://www.tqlkg.com/image-2804964-5834748" width="120" height="30" alt="Click here to buy & sell on eBay!" border="0"/></a>

into a sql table via a php form?

 

i'm really stuck... ???

 

Thanks in advance! :D

Link to comment
Share on other sites

  • Replies 58
  • Created
  • Last Reply

You have to be more specific, and need to elaborate more on your questions. You are giving the viewers of your thread or those who wan't to help limited information on your problem....

 

I am guessing you want to add that HTML code to your Mysql using PHP ? correct?

Link to comment
Share on other sites

i would assume

<?php
$avar = '<a href="http://rover.ebay.com/rover/1/710-5232-2978-8/1?aid=5834748&pid=2804964" target="_blank" onmouseover="window.status=\'http://www.ebay.co.uk\';return true;" onmouseout="window.status=' ';return true;">';
$avar .= '<img src="http://www.tqlkg.com/image-2804964-5834748" width="120" height="30" alt="Click here to buy & sell on eBay!" border="0"/></a>'

$SQL = "INSERT INTO `table` SET field = '$avar';";
?>

 

Link to comment
Share on other sites

hi guys,

 

sorry i'll explain.

 

the links are all saved in a table.

 

they are then all pulled out and arranged nicely in a grid on the page using some adapted code i found on here.

 

then with the submit button it saves the username (from a cookie) and the link into another table

 

ready to be pull on to the users login page

 

the problem i'm having is that when it saves it into the 2nd table, it only inserts

 

<a href="http://rover.ebay.com/rover/1/710-5232-2978-8/1?aid=5834748&pid=2804964" target="_blank" onmouseover="window.status=

 

rather than the full

 

<a href="http://rover.ebay.com/rover/1/710-5232-2978-8/1?aid=5834748&pid=2804964" target="_blank" onmouseover="window.status='http://www.ebay.co.uk';return true;" onmouseout="window.status=' ';return true;">
<img src="http://www.tqlkg.com/image-2804964-5834748" width="120" height="30" alt="Click here to buy & sell on eBay!" border="0"/></a>

Link to comment
Share on other sites

sorry

 

yes you guys are correct that's what i want to do,

 

but it's confusing things as i'm pulling them out of a table to start with.

 

i would post the current code.

 

but my last post got deleted for double posting, and the previous post is now out of date

Link to comment
Share on other sites

due to the way this code is working i'll have to say:

<?php

$_POST['user2'] = mysql_real_escape_string(nl2br(addslashes($_POST['user2'])));

?>

 

or

 


<?php

$_POST['user2'] = htmlspecialchars($_POST['user2'], ENT_QUOTES);

?>

 

that's ok.... isn't it???

Link to comment
Share on other sites

Thankyou soo much,

 

this really means alot!!

 

see page here: http://www.everyonlinestore.co.uk/change_password.php          (ignore the name)

 

you'll get an error as you're not logged in, but feel free to click the banner and sign up. then go back to the page and refresh

i obviously haven't gone live yet :D

 

page of links with submit function

 

<?php

$mysite_username = $_COOKIE["mysite_username"];

$conn = mysql_connect($server, $db_user, $db_pass)
or die ("could not connect to mysql");  #Connect to mysql
$rs = mysql_select_db( $database, $conn )
or die ("Could not select database"); #select database 

$sql = "Select link FROM links";  //pull the users from the table

$result= mysql_query($sql)
or die(" Could not add style facts");

echo "<table align=center border=1>";        // display the users in table
$c = 0;
while($row = mysql_fetch_array($result)) { 
  $user2 = $row['link'];
  if($c%5 == 0) echo "<tr height=\"200px\">"; // If the counter has ticked 6 times, start a new row.
echo "<td><FORM action='addlinks.php' method='post'><p><input type=HIDDEN name='user' value='$mysite_username'></p><p align=center><input type=hidden name='user2' value='$user2'></p><p align=center>rating script here</p><p align=center><input type=submit></p></form>";

  if($c%5 == 4) echo "</tr>"; // If we're drawing the 6th pic, end this row.
  $c++;
}
if($c%5 != 4) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row
echo "</table>"; // end the table


?>

 

Add links php

 

<?php

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

// insert the data
$insert = mysql_query("insert into memberlinks values ('".$_POST['user']."', '".$_POST['user2']."')")
or die("Could not insert data because ".mysql_error());

// print a success message
echo "Your link has been added!<br>"; 
echo "Now you can <a href=change_password.php>add another link</a>"; 

?>

 

Thankyou!!

 

Link to comment
Share on other sites

add link should look like this

<?php

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database) or die ("Could not select database because ".mysql_error());

// insert the data
$user = mysql_real_escape_string($_POST['user']);
$user2 = htmlspecialchars($_POST['user2'],  ENT_QUOTES);
$insert = mysql_query("insert into memberlinks values ('$user', '$user2')") or die("Could not insert data because ".mysql_error());

// print a success message
echo "Your link has been added!<br>"; 
echo "Now you can <a href=change_password.php>add another link</a>"; 

?>

Link to comment
Share on other sites

Oppps, noticed that the input boxes were hidden.....

so see update..

also change hidden to text while testing..

 

<?php

$mysite_username = $_COOKIE["mysite_username"];

$conn = mysql_connect($server, $db_user, $db_pass)
or die ("could not connect to mysql");  #Connect to mysql
$rs = mysql_select_db( $database, $conn )
or die ("Could not select database"); #select database 

$sql = "Select link FROM links";  //pull the users from the table

$result= mysql_query($sql)
or die(" Could not add style facts");

echo "<table align=center border=1>";        // display the users in table
$c = 0;
while($row = mysql_fetch_array($result)) { 
//update line below
$user2 = htmlspecialchars($row['link'],  ENT_QUOTES);
  if($c%5 == 0) echo "<tr height=\"200px\">"; // If the counter has ticked 6 times, start a new row.
echo "<td><FORM action='addlinks.php' method='post'><p><input type=HIDDEN name='user' value='$mysite_username'></p><p align=center><input type=hidden name='user2' value='$user2'></p><p align=center>rating script here</p><p align=center><input type=submit></p></form>";

  if($c%5 == 4) echo "</tr>"; // If we're drawing the 6th pic, end this row.
  $c++;
}
if($c%5 != 4) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row
echo "</table>"; // end the table


?>

 

3am here in the UK, i got to be up in 4hours... night all.

Link to comment
Share on other sites

hello again!

 

it works in the way that a user can add a link, and when they go back to their page it will be on there.

 

however i have another problem around the same code

 

using the code you gave me it doesn't display the link as an image. just as text so i'm trying to do something like this.

 

can you see where i'm going wrong?  the problem is it's displaying the onmouse...etc etc section

 

<?php
echo "<table align=center border=1>";        // display the users in table
$c = 0;
while($row = mysql_fetch_array($result)) { 
   $user2 = htmlspecialchars($row['link'],  ENT_QUOTES);
   $user3 = $row['link'];

if($c%5 == 0) echo "<tr height=\"200px\">"; // If the counter has ticked 6 times, start a new row.


echo "<td><FORM action='addlinks.php' method='post'>
<p><input type=HIDDEN name='user' value='$mysite_username'></p>
<p align=center><input type=HIDDEN name='user2' value='$user2'></p>
<p align=center>'$user3'</p>
<p align=center>rating script here</p>
<p align=center><input type=submit></p></form>";

  if($c%5 == 4) echo "</tr>"; // If we're drawing the 6th pic, end this row.
  $c++;
}
if($c%5 != 4) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row
echo "</table>"; // end the table


?>

Link to comment
Share on other sites

ok,

 

and so i turn for help again... :)

 

I'm trying to check if the link has already been added for the user using:

 

<?php
//check to see if link has already been added to username

$match = "SELECT link FROM memberlinks WHERE username = '".$_POST['user']."' 
and link = '".$_POST['user2']."';"; 

$qry = mysql_query($match) 
or die ("Could not match data because ".mysql_error()); 
$num_rows = mysql_num_rows($qry); 

if ($num_rows <= 0) { 
echo "You've already added that link.<br>"; 
echo "<a href=change_password.php>choose another</a>"; 
exit; 
}
?>

 

however, user2 is only bringing back half the code again!

 

although we encoded it before the post...?

 

what's going on ?!?

 

Thanks in advance

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • 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.