hype 0 Report post Posted June 7, 2005 How do I make a code such that it shows a input box that will be inserted into the certain field and database of a specific database?Like how do I make a field like in this forum like the textbox of the topic title.Lets say I wanted a user to input his friend email, then how do I create it so that the info will go to my database? Share this post Link to post Share on other sites
HmmZ 0 Report post Posted June 7, 2005 well first, you need to connect to mysql and make your way to your DB $conn=mysql_connect('localhost','username','password');$db=mysql_select_db("dbname",$conn);if(!conn){die("could not connect to server.."); }if(!db){die("could not connect to database.."); } then make a form code and complete your script:<form method=post action='thispage.php?insert=yes'>insert into table: <input type='text' name='insert' size=30><input type=submit value=submit name='go'>$insert=$_GET['insert'];if($insert=yes){ mysql_query("INSERT field into table VALUES('')"); } it should be something similar to that.. Share this post Link to post Share on other sites
hype 0 Report post Posted June 7, 2005 thanx...Just a stupid question, I need to close the form right? Share this post Link to post Share on other sites
hype 0 Report post Posted June 8, 2005 It doesnt really works...ok, lets say I want to put in the following fieldcommentrating(option form)and I also want the it to remember the userid that enter the field so that I can set it like only the user can edit the field. So how do I do that? Thanx in advance... Share this post Link to post Share on other sites
HmmZ 0 Report post Posted June 8, 2005 Sorry for the non-working script  <form method=post action='submit.php'>$user=$_SESSION['username']//the session name of $user (in brackets) has to correspond with the $_SESSION[''] you//are using for your user(login)$userid=mysql_query("SELECT userid from usertable where username='$user'")//adjust tablename to correspond with your usertableYour comment: <input type='textarea' name='comment' cols='30' rows='10'>Your rating: <select name='rating'><option value='0'>NONE</option><option value='10'>10</option><option value='9'>9</option><option value='8'>8</option><option value='7'>7</option><option value='6'>6</option><option value='5'>5</option><option value='4'>4</option><option value='3'>3</option><option value='2'>2</option><option value='1'>1</option></select><input type='hidden' name='userid' value=$userid><input type=submit value=submit name='go'> then just make a new page called submit.phpfor this page you need to insert a field in your 'comment/rating' table with something like author <?php$comment=$_POST['comment'];$rating=$_POST['rating'];$author=$_GET['userid'];if(!$user || !$userid){die("A problem occured when connecting to the database");if(empty($comment) {echo "Please write your comment";}if($rating==0){echo "Please give a rating";}} else {mysql_query("INSERT INTO commenttable VALUES('$comment','$rating','$author')") or die("A problem occured when trying to post your comment");} Hope this helps.. Share this post Link to post Share on other sites
hype 0 Report post Posted June 9, 2005 Thank you +1 rep :PJust a follow-up question, how do you make something that could check a input value whether if its a number the the script will allows it to pass through the checker, and how do I make a checker that doesnt allows ppl to put html tags or codes into the input? Share this post Link to post Share on other sites
HmmZ 0 Report post Posted June 9, 2005 you mean like with ratings? It's all done through if() statements, if you want to put an if() on a value (for example with the ratings), it's something like this: if($rating['X'] { } wich means that if the variable $rating gets the property value of X (NONE-10) it will whatever you specify.Hope that helps Share this post Link to post Share on other sites
hype 0 Report post Posted June 9, 2005 No, I dont mean rating... What I means is like what I'm typing into now, a textarea, and they have something that filter out all html tag like / <a href= and many others, so how do make this filter?And how do I make a textbox that doesnt allows any character except numbers? Share this post Link to post Share on other sites
HmmZ 0 Report post Posted June 10, 2005 well i think the following could work: <textarea name=$textarea cols='10' rows='30'></textarea>$textarea=htmlspecialchars($textarea,ENT_QUOTES);$textarea=StrReplace($textarea,'<','>');$textarea=StripSlashes($textarea); That kind of stuff is normally used for SQL Injection prevention, but it should strip all the < and >, wich are the characters needed to get html going.. Share this post Link to post Share on other sites
HmmZ 0 Report post Posted June 10, 2005 Sorry for the double post, i didnt know what to do with "numbers-only textbox", googled and the only possible way is javascript: <script language="javascript" type="text/javascript"><!--function intOnly(i) { if(i.value.length>0) { Â i.value = i.value.replace(/[^\d]+/g, ''); }}//--></script>Integer Only Textbox:<br><input type="text" onChange="intOnly(this);" onKeyUp="intOnly(this);" onKeyPress="intOnly(this);"> Source: Evoluted.net Share this post Link to post Share on other sites
hype 0 Report post Posted June 11, 2005 I went to google it too and what I got is something like yours,It gives me something like (/[^0-9]+/) or some else, also a javascipt, but what I dont understand is how do I combine javascript checker with php checker? I direct the form to the php checker but how do I direct it to both of them?Another thing is how to restrict others not to insert html so as to prevent them from inserting html that will destroy the page like a drop database code.. Share this post Link to post Share on other sites
Tyssen 0 Report post Posted June 11, 2005 It gives me something like (/[^0-9]+/) or some elseThat's called a regular expression. I don't know much about regular expressions but if you Google it you should come up with something useful. Share this post Link to post Share on other sites
HmmZ 0 Report post Posted June 11, 2005 The code i gave you should disable the use of ['s and ]'s, wich are the tags needed for html, people won't be able to insert html, because they will then show as plain text, you can't disable all characters used inside of html tags, as this would cause a great disability to your textarea.. Share this post Link to post Share on other sites
hype 0 Report post Posted June 12, 2005 I want to make like the forum where post are being filter and html tags will be change to 46; and show on the browser instead of the normal sign... Share this post Link to post Share on other sites