JohnDoe1 Posted July 19, 2009 Share Posted July 19, 2009 This may be a noob question to ask but i'm stuck writing a simple form to make work with php. and once I get it written for php does it create data table entries for mysql? I'm confused. <body> <table class="style8" style="WIDTH: 70%" cellSpacing="3" cellPadding="2" align="center"> <tr> <td class="style15" colSpan="2" style="height: 47px"> <span class="style12"><a name="CRep">Claims Rep Info</a><br /> <span class="style7"><a href="#Top">Back to Top</a> | <a target="_self" href="http://www.wholescaleone.com/AdminiClaim/Claims_Rep.php"> Add Info</a> | <a target="_self" href="http://www.wholescaleone.com/AdminiClaim/edit_Claims_Rep.php?INSURED_CLAIM_ID="> Edit Info</a></span></span></td> </tr> <tr> <td class="style24" style="WIDTH: 200px">Other Ins Claim No.</td> <td class="style23" style="WIDTH: 492px"> <input name="OtherIns_Claim_No" type="text" style="width: 289px" /></td> </tr> <tr> <td class="style18" style="WIDTH: 200px">Company Name</td> <td class="style17" style="WIDTH: 492px"> <input name="Company_Name" type="text" style="width: 289px" /></td> </tr> <tr> <td class="style24" style="WIDTH: 200px">Claims Rep Name</td> <td class="style23" style="WIDTH: 492px"> <input name="CRep_Name" type="text" style="width: 289px" /></td> </tr> <tr> <td class="style18" style="WIDTH: 200px">Phone</td> <td class="style17" style="WIDTH: 492px"> <input name="Phone" type="text" style="width: 163px" /></td> </tr> <tr> <td class="style24" style="WIDTH: 200px">Fax</td> <td class="style23" style="WIDTH: 492px"> <input name="Fax" type="text" style="width: 163px" /></td> </tr> <tr> <td class="style18" style="WIDTH: 200px"> </td> <td class="style17" style="WIDTH: 492px"> <input name="Submit" type="submit" value="submit" /></td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/166540-making-html-work-for-phpmysql/ Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 I see an html table with a couple of input fields in it. I don't see any form tags, so you don't even have a working html form. Also, I don't see any php code for handling data submitted from this non-existent form. Maybe this tutorial might help you out: http://www.phpfreaks.com/tutorial/php-basic-database-handling Quote Link to comment https://forums.phpfreaks.com/topic/166540-making-html-work-for-phpmysql/#findComment-878246 Share on other sites More sharing options...
JohnDoe1 Posted July 19, 2009 Author Share Posted July 19, 2009 Thanks for the response. yeah you're right. but do you think this would be a good representation of a php document for a simple form? <? $other ins claim no=$_POST['Other Ins Claim No.']; $company name=$_POST['Company Name']; $claims rep name=$_POST['Claims Rep Name']; $phone=$_POST['phone']; $fax=$_POST['fax']; mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()); mysql_select_db("Database_Name") or die(mysql_error()); mysql_query("INSERT INTO `data` VALUES ('$other ins claim no', '$company name', '$claims rep name', '$phone', '$fax' )"); Print "Your information has been successfully added to the database."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/166540-making-html-work-for-phpmysql/#findComment-878252 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 That's the basic idea, yes. But there is a lot of work to be done with that. Examples: - Since you don't have any form tags, there's not going to be anything in that $_POST array. You will need to put form tags in your form, specifying the method as post. - Your variable names are not right. (ex: in your form you use underscores but in your post array you have spaces) - Use <?php not <? - You can't use spaces in variables (ex: "$other ins claim no" php will see that as a variable called "$other" and then throw an error because the rest of that is invalid syntax) - You need to validate the data (ex: making sure the user entered in properly formatted data, there's nothing dangerous in it, like attemped sql injection attacks, etc...) - you should not end things in ..or die(mysql_error()); setup proper error handling instead. Quote Link to comment https://forums.phpfreaks.com/topic/166540-making-html-work-for-phpmysql/#findComment-878263 Share on other sites More sharing options...
JohnDoe1 Posted July 19, 2009 Author Share Posted July 19, 2009 Thanks alot! Quote Link to comment https://forums.phpfreaks.com/topic/166540-making-html-work-for-phpmysql/#findComment-878277 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.