Alexhoward Posted March 11, 2008 Share Posted March 11, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/ Share on other sites More sharing options...
phpSensei Posted March 11, 2008 Share Posted March 11, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490047 Share on other sites More sharing options...
MadTechie Posted March 11, 2008 Share Posted March 11, 2008 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';"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490052 Share on other sites More sharing options...
phpSensei Posted March 11, 2008 Share Posted March 11, 2008 I think he wants to do this using a FORM <?php $avar = mysql_real_escape_string(nl2br($_POST['html_code'])); $SQL = "INSERT INTO `table` SET field = '$avar';"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490059 Share on other sites More sharing options...
Alexhoward Posted March 11, 2008 Author Share Posted March 11, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490060 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490062 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 even using mysql_real_escape_string(nl2br($_POST['html_code'])); it does not insert the whole code sorry to be a pain Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490063 Share on other sites More sharing options...
MadTechie Posted March 12, 2008 Share Posted March 12, 2008 <?php mysql_real_escape_string(nl2br(addslashes($_POST['html_code']))); ?> or <?php htmlspecialchars($_POST['html_code'], ENT_QUOTES); //on output i use nl2br ?> Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490069 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 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??? Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490076 Share on other sites More sharing options...
MadTechie Posted March 12, 2008 Share Posted March 12, 2008 i would use <?php $user2 = htmlspecialchars($_POST['user2'], ENT_QUOTES); //now refer to $user2 instead of $_POST['user2'] in the remaining code ?> Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490080 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 ... neither of these post the full link, it stops at <?php href="http://rover.ebay.com/rover/1/710-5232-2978-8/1?aid=5834748&pid=2804964" target="_blank" onmouseover="window.status= ?> i'm lost.... Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490081 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 i can't would you like to see the code...? thanks for helping Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490082 Share on other sites More sharing options...
MadTechie Posted March 12, 2008 Share Posted March 12, 2008 please post the code i'll review it Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490084 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 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 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!! Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490088 Share on other sites More sharing options...
MadTechie Posted March 12, 2008 Share Posted March 12, 2008 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490090 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 Thanks, that's excellent! however it's still only posting href="http://www.dpbolvw.net/click-2804964-5590692" target="_blank" onmouseover="window.status= and not the full link.....??? Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490094 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 Thanks for all you help dude, however it's 01:00 here, and i've got to go to bed. i'll check the forum in around 8 hours when i'm at work Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490098 Share on other sites More sharing options...
MadTechie Posted March 12, 2008 Share Posted March 12, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490181 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 man! you were up late! Nice one!! the input box now contains all of the link!! but how do i how display it on the page....? Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490316 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 oops that should have said "now display" thanks for all this! so it saves it into the memberlinks table, and changes " to " and the like so how do i pull them out again, and back to as it was before...? Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490321 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 yay! i worked it out!! <?php $user2 = html_entity_decode($row['link']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490372 Share on other sites More sharing options...
MadTechie Posted March 12, 2008 Share Posted March 12, 2008 i was going to say change $user2 = htmlspecialchars($row['link'], ENT_QUOTES); to $user2 = addslashes($row['link']); to stop the double encoding but decoding will work also Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490375 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490383 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 STOP THE BUS!!! I got it!!! The original link wasn't saved in the table correctly!! i'm so stupid Thanks so much for all your help! I'm sure i'll be asking another question real soon Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490388 Share on other sites More sharing options...
Alexhoward Posted March 12, 2008 Author Share Posted March 12, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/95713-insert-html-code-into-sql-table-via-php-form/#findComment-490432 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.