Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't insert into database

Status
Not open for further replies.

riffy

Programmer
Mar 29, 2001
106
US
hi,

this is my first time posting to this forum as i have been assigned to create a database for email for philips..
the mysql database is all set up, the database name is mailform and it has only one table user with 10 rows containing the various information from the mail page on their site..

my question is that i have queried the information to enter into the database but nothing seems to be entered...

the page is
the insert query is all the way at the bottom, i have an include file at the top that contains all the connection information to the database...can anyone tell me what i seem to be doing wrong?

thanks
arif X-) s-)
 
No one can tell what you are doing to the database without code, and, no one can get to a site with .htpasswd on it unless they know the username and password.

But post your code please.

-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
ok sorry about that..i forgot about the username and password...
the code is the following...i'll include the config.inc code in the next posting...all the php code is in bold..
the javascript is commented to understand...basically for rollovers and for a random fact link on the page...


<?include &quot;config.inc&quot;;?>

<html>
<head>
<title>Philips Lighting - Link to Us</title>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--

if (document.images) {

IMG1_hiLite = new Image(60,21);
IMG1_hiLite.src = &quot;/images/gh02h.jpg&quot;;
IMG1_normal = new Image(60,21);
IMG1_normal.src = &quot;/images/gh02.jpg&quot;;
IMG2_hiLite = new Image(60,21);
IMG2_hiLite.src = &quot;/images/gh03h.jpg&quot;;
IMG2_normal = new Image(60,21);
IMG2_normal.src = &quot;/images/gh03.jpg&quot;;
IMG3_hiLite = new Image(60,21);
IMG3_hiLite.src = &quot;/images/gh04h.jpg&quot;;
IMG3_normal = new Image(60,21);
IMG3_normal.src = &quot;/images/gh04.jpg&quot;;
IMG4_hiLite = new Image(60,21);
IMG4_hiLite.src = &quot;/images/i_b1b.gif&quot;;
IMG4_normal = new Image(60,21);
IMG4_normal.src = &quot;/images/i_b1.gif&quot;;
IMG5_hiLite = new Image(60,21);
IMG5_hiLite.src = &quot;/images/i_b3b.gif&quot;;
IMG5_normal = new Image(60,21);
IMG5_normal.src = &quot;/images/i_b3.gif&quot;;
IMG6_hiLite = new Image(60,21);
IMG6_hiLite.src = &quot;/images/i_b2b.gif&quot;;
IMG6_normal = new Image(60,21);
IMG6_normal.src = &quot;/images/i_b2.gif&quot;;
IMG7_hiLite = new Image(60,21);
IMG7_hiLite.src = &quot;/images/i_b4b.gif&quot;;
IMG7_normal = new Image(60,21);
IMG7_normal.src = &quot;/images/i_b4.gif&quot;;
IMG8_hiLite = new Image(60,21);
IMG8_hiLite.src = &quot;/images/i_b5b.gif&quot;;
IMG8_normal = new Image(60,21);
IMG8_normal.src = &quot;/images/i_b5.gif&quot;;
IMG9_hiLite = new Image(60,21);
IMG9_hiLite.src = &quot;/images/i_b6b.gif&quot;;
IMG9_normal = new Image(60,21);
IMG9_normal.src = &quot;/images/i_b6.gif&quot;;
IMG10_hiLite = new Image(60,21);
IMG10_hiLite.src = &quot;/images/i_b7b.gif&quot;;
IMG10_normal = new Image(60,21);
IMG10_normal.src = &quot;/images/i_b7.gif&quot;;
//BOTTOM OF COLUMN
//IMG_BOTTOM = new Image(118,39);
//IMG_BOTTOM.src = &quot;/images/i_b8.gif&quot;;
}
function hiLiteImage(normal, hiLite) {
if(document.images) {
document.images[normal].src = eval(hiLite + &quot;.src&quot;);
//if (doRollOver == 1) document.images[normal].src = eval
(hiLite + &quot;.src&quot;);
}
return;
}

// FACTS OF LIGHT
var MaxFacts = 17;
function loadFact() {
if(Math.random && Math.round) {
FactNum = Math.random()* MaxFacts;
thisFactNum = Math.round(FactNum) + 1
FactWindow = window.open(&quot;/facts/&quot; + thisFactNum +
&quot;.htm&quot;,&quot;definition&quot;,&quot;toolbar=no,loc
ation=no,directories=no,status=yes,menubar=no,scrollbars=yes
,resizable=no,copyhistory=no,width=275,height=220&quot;)
if(FactWindow.creator) {
FactWindow.creator = self;
}
if(window.FactWindow.focus) {
window.FactWindow.focus();
}
}
else {
if(Date && Math.round) {
Today = new Date();
PseudoRandomNumber = Math.round(((Today.getSeconds
()/59)*MaxFacts)%MaxFacts)
FactWindow = window.open(&quot;/facts/&quot; +
PseudoRandomNumber
+&quot;.htm&quot;,&quot;definition&quot;,&quot;toolbar=no,lo
cation=no,directories=no,status=yes,menubar=no,scrollbars=ye
s,resizable=no,copyhistory=no,width=275,height=220&quot;)
if(FactWindow.creator) {
FactWindow.creator = self;
}
}
else {
FactWindow = window.open(&quot;/facts/1.htm&quot;,&quot;definition&quot;,&quot;toolb
ar=no,location=no,directories=no,status=yes,menubar=no,scrol
lbars=yes,resizable=no,copyhistory=no,width=275,height=220&q
uot;)
if(FactWindow.creator) {
FactWindow.creator = self;
}
}
}
}
// -->
</script>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot; link=&quot;#0000FF&quot; vlink=&quot;#FF0000&quot; alink=&quot;#FF0000&quot;>

//<?include &quot;headfoot/mail_header_2.htm&quot;?>

<table border=&quot;0&quot; width=&quot;600&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td valign=&quot;top&quot; width=&quot;482&quot; bgcolor=&quot;#FFCC00&quot;><font color=&quot;#000000&quot; face=&quot;Arial, Helvetica&quot;>    <b>Join our Mailing List</b></font></td>
<td valign=&quot;top&quot;><img src=&quot;/images/sub3_6a.jpg&quot;></td>
</tr>
<tr>
<td></td>
<td valign=&quot;top&quot;><img src=&quot;/images/sub3_6b.jpg&quot;></td>
</tr>
</table>

<?
function register_email() {
global $fname, $lname, $email, $country, $occupation,
$feature_stories, $email_ok, $how_to_light, $site_news;

?>


<table border=&quot;0&quot; width=&quot;600&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td valign=&quot;top&quot; colspan=&quot;3&quot; width=&quot;600&quot;><tr>
</tr>
<tr>
<td valign=&quot;top&quot; colspan=&quot;2&quot; width=&quot;150&quot;><br><br>
<form method=&quot;post&quot; action=&quot;thankyou.php&quot;>
<input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;register&quot;>
<div align=&quot;center&quot;>
<table border=&quot;2&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; width=600>
<tr>
<td valign=&quot;top&quot;><font face=&quot;arial, helvetica, sans-
serif&quot; size=&quot;3&quot;>Join the Philips Light Site mail list. This
confidential information will be used by us solely to keep
you informed about Philips and The Light Site.</font></td>
</tr>
<tr>
<td valign=&quot;top&quot;>
<table border=&quot;0&quot;>
<tr>
<td><font face=&quot;arial, helvetica, sans-serif&quot;
size=&quot;2&quot;>First Name</font><br>
<input type=&quot;text&quot; size=&quot;20&quot; name=&quot;fname&quot;></td>
<td><font face=&quot;arial, helvetica, sans-serif&quot;
size=&quot;2&quot;>Last Name</font><br>
<input type=&quot;text&quot; size=&quot;20&quot; name=&quot;lname&quot;></td>
</tr>
<tr>
<td><font face=&quot;arial, helvetica, sans-serif&quot;
size=&quot;2&quot;>Email Address</font><br>
<input type=&quot;text&quot; size=&quot;20&quot; name=&quot;email&quot;></td>
<td><font face=&quot;arial, helvetica, sans-serif&quot;
size=&quot;2&quot;>Country</font><br>
<select name=&quot;country&quot; size=&quot;1&quot;>
<option>Select Country</option>
<option value=&quot;Argentina&quot;>Argentina</option>
<option value=&quot;Australia&quot;>Australia</option>
<option value=&quot;Austria&quot;>Austria</option>
<option value=&quot;Bolivia&quot;>Bolivia</option>
<option value=&quot;Brazil&quot;>Brazil</option>
<option value=&quot;Chile&quot;>Chile</option>
<option value=&quot;China&quot;>China</option>
<option value=&quot;Colombia&quot;>Colombia</option>
<option value=&quot;CostaRica&quot;>Costa Rica</option>
<option value=&quot;Czech&quot;>Cz Rep.</option>
<option value=&quot;Ecuador&quot;>Ecuador</option>
<option value=&quot;Salvador&quot;>El Salvador</option>
<option value=&quot;Finland&quot;>Finland</option>
<option value=&quot;Germany&quot;>Germany</option>
<option value=&quot;Guatemala&quot;>Guatemala</option>
<option value=&quot;Honduras&quot;>Honduras</option>
<option value=&quot;HongKong&quot;>Hong Kong</option>
<option value=&quot;Japan&quot;>Japan</option>
<option value=&quot;Korea&quot;>Korea</option>
<option value=&quot;NZealand&quot;>N. Zealand</option>
<option value=&quot;Paraguay&quot;>Paraguay</option>
<option value=&quot;Peru&quot;>Peru</option>
<option value=&quot;Poland&quot;>Poland</option>
<option value=&quot;Russia&quot;>Russia</option>
<option value=&quot;Singapore&quot;>Singapore</option>
<option value=&quot;Spain&quot;>Spain</option>
<option value=&quot;Sweden&quot;>Sweden</option>
<option value=&quot;Switzerland&quot;>Switzerland</option>
<option value=&quot;USA&quot;>United States</option>
<option value=&quot;Uruguay&quot;>Uruguay</option>
<option value=&quot;Venezuela&quot;>Venezuela</option>
<option value=&quot;Yugoslavia&quot;>Yugoslavia</option>
</select></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign=&quot;top&quot;>
<table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot;>
<tr>
<td align=&quot;right&quot; valign=&quot;top&quot;><font face=&quot;arial,
helvetica, sans-serif&quot; size=&quot;2&quot;>Click here if you would
like to be on our e-mail list to receive <b>ALL</b> notices
with regard to this site<br></font></td>
<td valign=&quot;bottom&quot;>
<input type=&quot;checkbox&quot; name=&quot;email_ok&quot;
value=&quot;1&quot;><br></td>
</tr>
<tr>
<td align=&quot;right&quot; valign=&quot;top&quot;><font face=&quot;arial,
helvetica, sans-serif&quot; size=&quot;2&quot;>Or, if you have a specific
area of interest, check whichever box you would like to
receive information about.</font></td>
<td valign=&quot;top&quot;><font face=&quot;arial, helvetica,
sans-serif&quot; size=&quot;2&quot;>
<input type=&quot;checkbox&quot; name=&quot;feature_stories&quot;
value=&quot;1&quot;>Feature Stories<br>
<input type=&quot;checkbox&quot; name=&quot;how_to_light&quot;
value=&quot;1&quot;>How To Light<br>
<input type=&quot;checkbox&quot; name=&quot;site_news&quot;
value=&quot;1&quot;>Site News<br></font>
</td>
</tr>
<tr>
<td align=&quot;right&quot;><font face=&quot;arial, helvetica, sans-serif&quot; size=&quot;2&quot;>Occupation/Area of
Interests</font></td>
<td><font face=&quot;arial, helvetica, sans-serif&quot;
size=&quot;2&quot;>
<select name=&quot;occupation&quot; size=&quot;1&quot;>
<option value>Please select... </option>
<option value=&quot;engineer&quot;>Engineer </option>
<option value=&quot;specifier&quot;>Specifier </option>
<option value=&quot;lighting_designer&quot;>Lighting
Designer</option>
<option value=&quot;architect&quot;>Architect </option>
<option value=&quot;hobbyist&quot;>Lighting Hobbyist
</option>
<option value=&quot;end_user&quot;>End User </option>
<option value=&quot;other&quot;>Other </option>
</select></font>
</td>
</tr>
<tr>
<td align=&quot;right&quot; colspan=&quot;2&quot;>
<input type=&quot;submit&quot; value=&quot;Submit Form&quot;>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</td>
</tr>
</table>
<?
}
function enter_info() {
global $fname, $lname, $email, $country, $occupation;
if (empty($fname)) error_message(&quot;Please enter a first
name.&quot;);
if (empty($lname)) error_message(&quot;Please enter a last
name.&quot;);
if (empty($email)) error_message(&quot;Pleae enter an email
address.&quot;);
if (empty($country)) error_message(&quot;Please select your
country.&quot;);
if (empty($occupation)) error_message(&quot;Please choose an
area of interest.&quot;);

$query = &quot;insert into user values
(NULL, '$fname', '$lname', '$email', '$country', '$email_ok'
, '$feature_stories', '$how_to_light', '$site_news', '$occup
ation', curdate())&quot;;
$result = mysql_query($query);
if(!$result) error_message(sql_error());
}
switch($action) {
case &quot;register&quot;:
enter_info();
break;
default:
register_email();
break;
}
?>


//<?include &quot;headfoot/global_footer_1.htm&quot;?>

</body>
</html>


any help will be greatly appreciated...
if i'm missing something or if i need something else, please do let me know...i've filled out the form countless number of times but nothing gets entered into the database...

thanks
arif X-) s-)
 
here is the code for the config.inc included in the previous code....

<?

//-- Database connection

$dbuser=&quot;root&quot;;
$dbhost=&quot;localhost&quot;;
$dbpassword=&quot;&quot;;
$dbdatabase=&quot;mailform&quot;;

$linkid = mysql_connect($dbhost,$dbuser,$dbpassword) or die($php_errormsg);
mysql_select_db($dbdatabase);

//-- sessions support
//-- include(&quot;./includes/sessions.inc&quot;);

$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';

function sql_error() {
global $MYSQL_ERRNO, $MYSQL_ERROR;

if (empty($MYSQL_ERROR)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
}
return &quot;$MYSQL_ERRNO: $MYSQL_ERROR&quot;;
}

?>

thanks
arif :cool: (-:
 
Here is your problem:

Its your INSERT statement:

You have:
[tt]
$query = &quot;insert into user values
(NULL, '$fname', '$lname', '$email', '$country', '$email_ok'
, '$feature_stories', '$how_to_light', '$site_news', '$occup
ation', curdate())&quot;;
[/tt]

After the user, you have to put the fields that you are going to insert values into:

[tt]
$query = &quot;insert into user
(id,field1,field2,field3,field4,field5,field6,field7,field8,
field9,field10,field11) values
(NULL, '$fname', '$lname', '$email', '$country', '$email_ok'
, '$feature_stories', '$how_to_light', '$site_news', '$occup
ation', curdate())&quot;;
[/tt]

Where field1..11 are the names of the fields in the database.

Hope this helps.

-Vic

vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
hey vic, thanks but apparently the switch statement at the bottom is not even being called...like i tried just filling out one field and pressing submit and it should tell me to fill out the other fields but it doesn't, just submits the form...

any suggestions?

action is the name of the hidden field up at the top right after the form tag...the switch statement calls that...

arif :)
 
ok so i'm posting the code again but only the relevant information...

Code:
<?
$dbuser=&quot;root&quot;;
$dbhost=&quot;localhost&quot;;
$dbpassword=&quot;&quot;;
$dbdatabase=&quot;mailform&quot;;

mysql_connect($dbhost,$dbuser,$dbpassword);
mysql_select_db($dbdatabase);
?>
<table border=&quot;0&quot; width=&quot;600&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
 <tr>
  <td valign=&quot;top&quot; colspan=&quot;3&quot; width=&quot;600&quot;></td>
 </tr>
 <tr>
  <td valign=&quot;top&quot; colspan=&quot;2&quot; width=&quot;150&quot;>
   <br><br>
   <form method=&quot;post&quot; action=&quot;thankyou.php&quot;>
    <div align=&quot;center&quot;>
    <table border=&quot;2&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; width=600>
     <tr> 
      <td valign=&quot;top&quot;><font face=&quot;arial, helvetica, sans-serif&quot; size=&quot;3&quot;>Join the Philips Light Site mail list. This confidential information will be used by us solely to keep you informed about Philips and The Light Site.</font></td>
     </tr>
     <tr>
      <td valign=&quot;top&quot;>
       <table border=&quot;0&quot;>
        <tr> 
         <td><font face=&quot;arial, helvetica, sans-serif&quot; size=&quot;2&quot;>First Name</font><br>
          <input type=&quot;text&quot; size=&quot;20&quot; maxlength=&quot;70&quot; name=&quot;fname&quot;></td>
         <td><font face=&quot;arial, helvetica, sans-serif&quot; size=&quot;2&quot;>Last Name</font><br>
          <input type=&quot;text&quot; size=&quot;20&quot; maxlength=&quot;70&quot; name=&quot;lname&quot;></td>
        </tr>
        <tr> 
         <td><font face=&quot;arial, helvetica, sans-serif&quot; size=&quot;2&quot;>Email Address</font><br>
          <input type=&quot;text&quot; size=&quot;20&quot; maxlength=&quot;70&quot; name=&quot;email&quot;></td>
         <td><font face=&quot;arial, helvetica, sans-serif&quot; size=&quot;2&quot;>Country</font><br>
          <select name=&quot;country&quot; size=&quot;1&quot;>
           <option>Select Country</option>
           <option value=&quot;Argentina&quot;>Argentina</option>
	   <option value=&quot;Australia&quot;>Australia</option>
           <option value=&quot;Austria&quot;>Austria</option>
           <option value=&quot;Bolivia&quot;>Bolivia</option>
           <option value=&quot;Brazil&quot;>Brazil</option>
	   <option value=&quot;Chile&quot;>Chile</option>
           <option value=&quot;China&quot;>China</option>
	   <option value=&quot;Colombia&quot;>Colombia</option>
	   <option value=&quot;CostaRica&quot;>Costa Rica</option>
	   <option value=&quot;Czech&quot;>Cz Rep.</option>
	   <option value=&quot;Ecuador&quot;>Ecuador</option>
	   <option value=&quot;Salvador&quot;>El Salvador</option>
	   <option value=&quot;Finland&quot;>Finland</option>
	   <option value=&quot;Germany&quot;>Germany</option>
	   <option value=&quot;Guatemala&quot;>Guatemala</option>
	   <option value=&quot;Honduras&quot;>Honduras</option>
	   <option value=&quot;HongKong&quot;>Hong Kong</option>
	   <option value=&quot;Japan&quot;>Japan</option>
	   <option value=&quot;Korea&quot;>Korea</option>
	   <option value=&quot;NZealand&quot;>N. Zealand</option>
	   <option value=&quot;Paraguay&quot;>Paraguay</option>
	   <option value=&quot;Peru&quot;>Peru</option>
	   <option value=&quot;Poland&quot;>Poland</option>
	   <option value=&quot;Russia&quot;>Russia</option>
	   <option value=&quot;Singapore&quot;>Singapore</option>
	   <option value=&quot;Spain&quot;>Spain</option>
	   <option value=&quot;Sweden&quot;>Sweden</option>
	   <option value=&quot;Switzerland&quot;>Switzerland</option>
	   <option value=&quot;USA&quot;>United States</option>
	   <option value=&quot;Uruguay&quot;>Uruguay</option>
	   <option value=&quot;Venezuela&quot;>Venezuela</option>
	   <option value=&quot;Yugoslavia&quot;>Yugoslavia</option>
	  </select></td>
        </tr>
       </table>
      </td>
     </tr>
     <tr> 
      <td valign=&quot;top&quot;>
       <table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot;>
        <tr> 
         <td align=&quot;right&quot; valign=&quot;top&quot;><font face=&quot;arial, helvetica, sans-serif&quot; size=&quot;2&quot;>Click here if you would like to be on our e-mail list to receive <b>ALL</b> notices with regard to this site<br></font></td>
         <td valign=&quot;bottom&quot;>
          <input type=&quot;checkbox&quot; name=&quot;email_ok&quot; value=&quot;1&quot;><br></td>
        </tr>
        <tr> 
         <td align=&quot;right&quot; valign=&quot;top&quot;><font face=&quot;arial, helvetica, sans-serif&quot; size=&quot;2&quot;>Or, if you have a specific area of interest, check whichever box you would like to receive information about.</font></td>
         <td valign=&quot;top&quot;><font face=&quot;arial, helvetica, sans-serif&quot; size=&quot;2&quot;>
          <input type=&quot;checkbox&quot; name=&quot;feature_stories&quot; value=&quot;1&quot;>Feature Stories<br>
          <input type=&quot;checkbox&quot; name=&quot;how_to_light&quot; value=&quot;1&quot;>How To Light<br>
          <input type=&quot;checkbox&quot; name=&quot;site_news&quot; value=&quot;1&quot;>Site News<br></font>
         </td>
        </tr>
        <tr> 
         <td align=&quot;right&quot;><font face=&quot;arial, helvetica, sans-serif&quot; size=&quot;2&quot;>Occupation/Area of Interests</font></td>
         <td><font face=&quot;arial, helvetica, sans-serif&quot; size=&quot;2&quot;>
          <select name=&quot;occupation&quot; size=&quot;1&quot;>
           <option value>Please select... </option>
           <option value=&quot;engineer&quot;>Engineer </option>
           <option value=&quot;specifier&quot;>Specifier </option>
           <option value=&quot;lighting_designer&quot;>Lighting Designer</option>
           <option value=&quot;architect&quot;>Architect </option>
           <option value=&quot;hobbyist&quot;>Lighting Hobbyist </option>
           <option value=&quot;end_user&quot;>End User </option>
           <option value=&quot;other&quot;>Other </option>
          </select></font>
         </td>
        </tr>
        <tr> 
         <td align=&quot;right&quot; colspan=&quot;2&quot;>
          <input type=&quot;submit&quot; value=&quot;Submit Form&quot;>
         </td>
        </tr>
       </table>
      </td>
     </tr>
    </table>
    </div>
   </form>
  </td>
 </tr>
</table>
<?

$query = &quot;insert into user values (NULL, '$fname', '$lname', '$email', '$country', '$email_ok', '$feature_stories', '$how_to_light', '$site_news', '$occupation')&quot;;

$result = mysql_query($query);

?>

can anyone see what's wrong with the code?? i thought that it's enough to just put the query into a variable and then call the function on that variable..

thanks in advance
arif
X-) s-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top