Board index   FAQ   Search  
Register  Login
Board index PHP Your Scripts

Help with inserting data from url

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

Help with inserting data from url

Postby tomtheperson » Sat Nov 12, 2011 4:57 am

i have a problem inserting some data from the url to my mysql database. here is the code:
Code: Select all
<?php
include'all.php';
if(isset($_GET['text']))
{
   $text = sanitizeString($_GET['text']);
   if ($text != "")
   {
                $topic=$_GET['topic'];
      queryMysql("INSERT INTO forum VALUES(NULL,
               '$user','$topic','$text')");
   }

}
echo <<<_END
<form  method='get' action="viewtopic.php">
<textarea style="resize:none" cols="50" rows="5" name='text'></textarea><br>
<input type='submit' value='Answer'/>
</form>
_END;
?>


the $topic variable is from the URL. when i press the submit button in my form all the data goes to the database apart from the $topic variable data. I just need some help in sorting it out. Also sanitizeString is a function that makes it secure using mysql_real_escape_string.
Thanks
tomtheperson
New php-forum User
New php-forum User
 
Posts: 9
Joined: Sat Nov 12, 2011 3:29 am

Re: Help with inserting data from url

Postby NigelRen » Sat Nov 12, 2011 5:02 am

The value of topic might be in the URL calling the page - but you would need to add it to the URL in the form tag as well to ensure it's passed on. If you add the value - sort of like I've tried to show, then this should get passed on.
Code: Select all
<form  method='get' action="viewtopic.php?topic=topicvalue">
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am

Re: Help with inserting data from url

Postby tomtheperson » Sat Nov 12, 2011 5:38 am

Thanks for replying
I have tried that but it just returns this:
Code: Select all
http://localhost/mywebsite/viewtopic.php?text=hello
tomtheperson
New php-forum User
New php-forum User
 
Posts: 9
Joined: Sat Nov 12, 2011 3:29 am


Return to Your Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.