martinstan Posted June 18, 2007 Share Posted June 18, 2007 Hi All I'm a designer wanting to learn some PHP. I've gained a basic grasp of PHP and can I suppose 'hack' code that has already been written but can't write any code that would be much use at the minute. I'm looking for a tutorial that would allow me to create a form that could be used to collect basic user info. (Name, address, Tel etc..), store this in a Mysql db and then allow me to search by field. A 'bog standard' process using something like Access but I'd like this to be able to be used online. I'd appreciate either a tutorial as to where to start or even better some ready made code that I could hack around with. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/56066-user-input-to-mysql-db/ Share on other sites More sharing options...
per1os Posted June 18, 2007 Share Posted June 18, 2007 http://www.freewebmasterhelp.com/tutorials/phpmysql/3 Quote Link to comment https://forums.phpfreaks.com/topic/56066-user-input-to-mysql-db/#findComment-276891 Share on other sites More sharing options...
liam1412 Posted June 18, 2007 Share Posted June 18, 2007 Well as im feeling in a good mood create a file called form.php Create a database using phpmyadmin on your server and a table named details with 3 fields detail_id // This should be set up as an auto increment field name address <?php if(isset($_POST['submit'])){ // This checks to see if the submit button has been pressed. $name = $_POST['name']; //note the index in between the [] is the name of the inputs $address = $_POST['address']; $insert = mysql_query("INSERT INTO details (name, address) VALUES ('$name', '$address')"); if($insert){ echo 'Details added succesfully'; } else { echo ' There was a problem updating the database'; } } else { // Here we close the original if statement checking if submit had been pressed. If it hasn't then //the form will display. ?> //closing the php to display html <form name="form1" action="form.php" method="post"> <input type="text" name="name" /> <input type="address name="address" /> <input type="submit" name="submit" /> </form> <?php } ?> // this closes the else statement You should also look into sql injection. The data entered in a form can be used to edit details or even destroy tables in your database. There are a number of function to clean the data you collect in form to check it isn't mailicious. But that is a whole ne ball game. Is that any good Quote Link to comment https://forums.phpfreaks.com/topic/56066-user-input-to-mysql-db/#findComment-276899 Share on other sites More sharing options...
martinstan Posted June 18, 2007 Author Share Posted June 18, 2007 Hi Thanks guys. Gets me going in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/56066-user-input-to-mysql-db/#findComment-276917 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.