| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Apr 2004 Location: Australia
Posts: 814
![]() ![]() ![]() ![]() | PHP/MySQL question Can someone tell me why this dosent work. after submitting it just restes without entering any data Code: <html>
<body>
<?php
if ($submit) {
// process form
$db = mysql_connect("localhost", "bertie_username", "password");
mysql_select_db("bertie_assesment",$db);
$sql = "INSERT INTO profiles (username,password,email,firstname,lastname,city,state,countrey,zip,birthday,gender,squestion,sawnser) VALUES ('$username','$password','$email','$firstname','$lastname','$city','$state','$countrey','$zip','$birthday','$gender','$squestion','$sawnser')";
$result = mysql_query($sql);
echo "<?php echo $PHP_SELF?>";
}
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<table border=0>
<TR>
<TD>Username:</TD><TD><input type="Text" name="username"></TD>
</TR>
<TR>
<TD>Password:</TD><TD><input type="Text" name="password"></TD>
</TR>
<TR>
<TD>Valid Email Address:</TD><TD><input type="Text" name="email"></TD>
</TR>
<TR>
<TD>Given Names:</TD><TD><input type="Text" name="firstname"></TD>
</TR>
<TR>
<TD>Family Name:</TD><TD><input type="Text" name="lastname"></TD>
</TR>
<TR>
<TD>City:</TD><TD><input type="Text" name="city"></TD>
</TR>
<TR>
<TD>State:</TD><TD><input type="Text" name="state"></TD>
</TR>
<TR>
<TD>Country:</TD><TD><input type="Text" name="countrey"></TD>
</TR>
<TR>
<TD>Zip Code:</TD><TD><input type="Text" name="zip"></TD>
</TR>
<TR>
<TD>Birth Date</TD><TD><input type="Text" name="birthday"></TD>
</TR>
<TR>
<TD>Gender:</TD><TD><input type="Text" name="gender"></TD>
</TR>
<TR>
<TD>Secret Question:</TD><TD><input type="Text" name="squestion"></TD>
</TR>
<TR>
<TD>Secret Answer:</TD><TD><input type="Text" name="sawnser"></TD>
</TR>
<TR>
<TD colspan="2"><center><input type="Submit" name="submit" value="Enter information"></center></TD>
</TR>
</form>
<?php
// end if
?>
</body>
</html> ????: NamePros.com http://www.namepros.com/programming/49837-php-mysql-question.html Code:
<html>
<body>
<?php
if ($submit) {
// process form
$db = mysql_connect("localhost", "bertie_username", "password");
mysql_select_db("bertie_mobster",$db);
$sql = "INSERT INTO employees (msg) VALUES ('$msg')";
$result = mysql_query($sql);
echo "<?php echo $PHP_SELF?>";
}
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<table border=0>
<TR>
<TD>Email:</TD><TD><input type="Text" name="msg"></TD>
</TR>
<TR>
<TD colspan="2"><center><input type="Submit" name="submit" value="Enter information"></center></TD>
</TR>
</form>
<?php
// end if
?>
</body>
</html> ????: NamePros.com http://www.namepros.com/showthread.php?t=49837 50np$'s to whoever helps |
| |
| | #2 (permalink) |
| NamePros Member Join Date: Jul 2003 Location: Canterbury, UK
Posts: 99
![]() | I don't know why it doesn't work, but try the following code and see what happens (I've added some debugging messages to your code, so it might help show whats going wrong). Hope that helps, Sam Code: <html>
<body>
<?php
// turn on all error reporting...
error_reporting(E_ALL);
if (isset($_POST['submit'])) {
// process form
echo "Processing submission...";
$db = mysql_connect("localhost", "bertie_username", "password") or die("Could not connect to database: ".mysql_error());
mysql_select_db("bertie_assesment",$db) or die("Could not select database: ".mysql_error());
$sql = "INSERT INTO profiles (username,password,email,firstname,lastname,city,state,countrey,zip,birthday,gender,squestion,sawnser) VALUES ('$username','$password','$email','$firstname','$lastname','$city','$state','$countrey','$zip','$birthday','$gender','$squestion','$sawnser')";
$result = mysql_query($sql) or die("Error with insert: ".mysql_error()." <br />SQL: $sql");
echo "<?php echo $PHP_SELF?>";
}
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<table border=0>
<TR>
<TD>Username:</TD><TD><input type="Text" name="username"></TD>
</TR>
<TR>
<TD>Password:</TD><TD><input type="Text" name="password"></TD>
</TR>
<TR>
<TD>Valid Email Address:</TD><TD><input type="Text" name="email"></TD>
</TR>
<TR>
<TD>Given Names:</TD><TD><input type="Text" name="firstname"></TD>
</TR>
<TR>
<TD>Family Name:</TD><TD><input type="Text" name="lastname"></TD>
</TR>
<TR>
<TD>City:</TD><TD><input type="Text" name="city"></TD>
</TR>
<TR>
<TD>State:</TD><TD><input type="Text" name="state"></TD>
</TR>
<TR>
<TD>Country:</TD><TD><input type="Text" name="countrey"></TD>
</TR>
<TR>
<TD>Zip Code:</TD><TD><input type="Text" name="zip"></TD>
</TR>
<TR>
<TD>Birth Date</TD><TD><input type="Text" name="birthday"></TD>
</TR>
<TR>
<TD>Gender:</TD><TD><input type="Text" name="gender"></TD>
</TR>
<TR>
<TD>Secret Question:</TD><TD><input type="Text" name="squestion"></TD>
</TR>
<TR>
<TD>Secret Answer:</TD><TD><input type="Text" name="sawnser"></TD>
</TR>
<TR>
<TD colspan="2"><center><input type="Submit" name="submit" value="Enter information"></center></TD>
</TR>
</form>
<?php
// end if
?>
</body>
</html> |
| |