Pauls74462 Posted June 23, 2010 Share Posted June 23, 2010 I have a form to input information in and when I hit submit it should insert the information into the db. My version don't work, anyone have an ideal how to do this?My file is much too big to past here Link to comment Share on other sites More sharing options...
niche Posted June 23, 2010 Share Posted June 23, 2010 Define local variables with $_POST[] and insert the local variables into your database. Link to comment Share on other sites More sharing options...
Pauls74462 Posted June 23, 2010 Author Share Posted June 23, 2010 Define local variables with $_POST[] and insert the local variables into your database.I have but it inserts to the db when the page loads before I insert any information. Link to comment Share on other sites More sharing options...
niche Posted June 23, 2010 Share Posted June 23, 2010 What's an example between an expected value and an inserted value? Link to comment Share on other sites More sharing options...
Pauls74462 Posted June 23, 2010 Author Share Posted June 23, 2010 What's an example between an expected value and an inserted value?Here is the code warning it's long. The problem is the code inserts a blank field every time you load it before you click submint.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <link rel="SHORTCUT ICON" href="http://softseven-online.com/favicon.ico"> <meta name="COPYRIGHT" content="© 2010 bestautoselles.com"> <title>Bestautoselles domain</title></head><body style="background-color: white;"><p align="center"></p><form name="login" method="post" action="register.php"> <table style="background-color: white; text-align: left; margin-left: auto; margin-right: auto; width: 942px; height: 135px;" border="0"> <tbody> <tr align="center"> <td colspan="4" rowspan="1"><b><font face="Arial Black" size="3">AddDomain</font></b></td> </tr> <tr> <td style="width: 393px; background-color: rgb(255, 255, 255);"><b><font color="black" face="Arial Black" size="3">Domain</font></b></td> <td style="width: 172px;"><big style="font-family: Arial Black;"><span style="font-weight: bold;">City</span></big><br> </td> <td style="width: 43px; font-family: Arial Black; font-weight: bold;">State</td> <td style="width: 60px; font-family: Arial Black; font-weight: bold;">Zip</td> </tr> <tr> <td style="width: 393px;"><input size="100" name="domain"></td> <td style="width: 172px;"><input size="25" name="city"></td> <td style="width: 43px;"><input size="5" name="State" maxlength="100"></td> <td style="width: 60px;"><input size="7" name="zip"></td> </tr> <tr> <td colspan="4" rowspan="1" style="width: 393px;"> <p align="center"><input name="submit" value="Submit" type="submit"></p> </td> </tr> </tbody> </table></form><p align="center"><big style="font-weight: bold;">You IP address is being logged, If you have authority to be here we are glad do have you as a member. </big><br></p><p align="center"><font face="Arial Black">If your not authorized to be here we will find you.</font></p><?php // Get db connectionsinclude ("config.php");$ip = $_SERVER['REMOTE_ADDR'];echo '<p align="center?>';echo '<font size="4"><font face="Arial Black">';echo "Your IP is: $ip";echo '</font></font>';echo '<p></p>';// Make a MySQL Connection$link2 = mysql_connect( $dbhost, $dbuser, $dbpass)or die("Could notconnect: ".mysql_error());mysql_select_db($dbname) or die(mysql_error());// set varabels$domain = $_POST['domain'];$city = $_POST['city'];$state = $_POST['state'];$zip = $_POST['zip'];// Insert into $query = "INSERT INTO Members (Domain, City, State, Zip, Ip)VALUES('$domain', '$city', '$state', '$zip', '$ip')";mysql_query($query) or die(mysql_error());mysql_close();?></body></html> Link to comment Share on other sites More sharing options...
23.12.2012 Posted June 23, 2010 Share Posted June 23, 2010 Well... assuming that the file you pasted is called register.php, what you need to do is control the form submission. So you want to write something like this // If the form has been submittedif(isset($_POST['submit'])) { // Do your thing} else { // Display the form} So this is how you would adjust your code (I'm not 100% sure it works, I haven't tested it) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><link rel="SHORTCUT ICON"href="http://softseven-online.com/favicon.ico"><meta name="COPYRIGHT" content="© 2010 bestautoselles.com"><title>Bestautoselles domain</title></head><body style="background-color: white;"><p align="center"></p><?php // Get db connectionsif(isset($_POST['submit'])) {include ("config.php");$ip = $_SERVER['REMOTE_ADDR'];echo '<p align="center?>';echo '<font size="4"><font face="Arial Black">';echo "Your IP is: $ip";echo '</font></font>';echo '<p></p>';// Make a MySQL Connection$link2 = mysql_connect( $dbhost, $dbuser, $dbpass)or die("Could notconnect: ".mysql_error());mysql_select_db($dbname) or die(mysql_error());// set varabels$domain = $_POST['domain'];$city = $_POST['city'];$state = $_POST['state'];$zip = $_POST['zip'];// Insert into $query = "INSERT INTO Members (Domain, City, State, Zip, Ip)VALUES('$domain', '$city', '$state', '$zip', '$ip')";mysql_query($query) or die(mysql_error());mysql_close();} else {?><form name="login" method="post" action="register.php"><tablestyle="background-color: white; text-align: left; margin-left: auto; margin-right: auto; width: 942px; height: 135px;"border="0"><tbody><tr align="center"><td colspan="4" rowspan="1"><b><fontface="Arial Black" size="3">AddDomain</font></b></td></tr><tr><tdstyle="width: 393px; background-color: rgb(255, 255, 255);"><b><fontcolor="black" face="Arial Black" size="3">Domain</font></b></td><td style="width: 172px;"><bigstyle="font-family: Arial Black;"><spanstyle="font-weight: bold;">City</span></big><br></td><tdstyle="width: 43px; font-family: Arial Black; font-weight: bold;">State</td><tdstyle="width: 60px; font-family: Arial Black; font-weight: bold;">Zip</td></tr><tr><td style="width: 393px;"><input size="100"name="domain"></td><td style="width: 172px;"><input size="25"name="city"></td><td style="width: 43px;"><input size="5"name="State" maxlength="100"></td><td style="width: 60px;"><input size="7"name="zip"></td></tr><tr><td colspan="4" rowspan="1"style="width: 393px;"><p align="center"><input name="submit"value="Submit" type="submit"></p></td></tr></tbody></table></form><?php}?><p align="center"><big style="font-weight: bold;">You IP address is being logged, If you have authority to be here we are glad do have you as a member. </big><br></p><p align="center"><font face="Arial Black">If your not authorized to be here we will find you.</font></p></body></html> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.