NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP/MySQL question

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 10-01-2004, 01:39 AM THREAD STARTER               #1 (permalink)
NamePros Regular
 
QBert's Avatar
Join Date: Apr 2004
Location: Australia
Posts: 814
QBert is just really niceQBert is just really niceQBert is just really niceQBert is just really nice
 


Save a Life Alzheimer's Breast Cancer

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>
However this one works, the only thing ive changed is added more feilds in the form and trying to do it to a different database.
????: 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>
Thanks heaps
????: NamePros.com http://www.namepros.com/showthread.php?t=49837

50np$'s to whoever helps
QBert is offline  
Old 10-01-2004, 04:22 AM   #2 (permalink)
NamePros Member
Join Date: Jul 2003
Location: Canterbury, UK
Posts: 99
samscripts is on a distinguished road
 



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>
samscripts is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 01:01 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger