Jump to content

[SOLVED] PHP Insert


ChompGator

Recommended Posts

Hello,

 

Im having a problem with a subscription script I made. Its a basic script, and the purpose of it is to allow a user to enter their email address, forename, surname, and select weather they are a business user or home user, then click "submit" and the information gets entered into the database/table I made for the script.

 

Now the problem Im having is the script works, and it submits, the problem is if I go look in the database the script didn't actually insert any information into the database.

 

Below I have included the html form, and the handle.php (the php script that handles the form information)

I was hoping someone may be able to provide some insight/advice as to why its not inserting whats in the field values into the database. - Thanks

 

HTML Script:

<html>

<body>

FORM id=mailinglist name=mailinglist

onsubmit="return emailOnly(this.emaillist.value,'emaillist');"

action="handle.php" method=post <INPUT

type=hidden value="Interactive Systems" name=thispage> <INPUT type=hidden

value=Main name=thissection>

<a title="AIIM Calgary Home Page" target="_self" href="http://www.aiimcalgary.org">Home</a> | 

<a href="http://calendar.aiimcalgary.org">Calendar</a> | Join The Calgary Chapter Mailing List: <INPUT class=small id=emaillist

onkeydown="hideshow('mldetails','on');"

onblur="return handleEmp(this,'Your Email');"

onfocus="clearThis(this,'Your Email');hideshow('mldetails','on');" align=top

size=24 value="Your email" name=emaillist> <INPUT class=submit id=join type=submit align=top value=Join name=join>

 

<DIV class=off id=mldetails onmouseover="hideshow('mldetails','on');"

onmouseout="hideshow('mldetails','off');">

<FIELDSET><LEGEND>Optional Details:</LEGEND><LABEL

for=mlfname>Forename:</LABEL><INPUT class=small id=mlfname maxLength=50

name=mlfname><BR><LABEL for=mllname>Surname:</LABEL><INPUT class=small

id=mllname maxLength=50 name=mllname><BR>[<A

title="View AIIM' Privacy Policy: How we handle your personal information"

href="javascript:openWin('/legal/privacy_policy.asp','privacy','795','550')">Privacy</A>]

          <SELECT class=small

size=1 name=mltype> <OPTION value=business selected>I'm a Business

  User</OPTION> <OPTION value=home>I'm a Home User</OPTION><OPTION value=home>I'm a New User</OPTION></SELECT> </FIELDSET>

</DIV></FORM>

<SCRIPT type=text/javascript>

//hide mailing list options on load

hideshow('mldetails','off');

</SCRIPT>

</body>

</html

 

 

PHP Script:

<?php

$con = mysql_connect("mysql105.mysite4now.com","aiim","k7YuHeFv");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }mysql_select_db("login", $con);$sql="INSERT INTO subscribe (email, forename, surname, user)

VALUES

('$_POST','$_POST[forename]','$_POST[surname]','user')";if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo "1 record added";mysql_close($con)

?>

 

 

 

 

Link to comment
Share on other sites

I'm going to teach you the OR clause when using functions ;D

 

<?php
$con = mysql_connect("mysql105.mysite4now.com","aiim","k7YuHeFv") or die('Could not connect: ' . mysql_error());
mysql_select_db("login", $con);

$sql="INSERT INTO subscribe (email, forename, surname, user) VALUES ('$_POST[email]','$_POST[forename]','$_POST[surname]','user')";
$query = mysql_query($sql,$con) or die('Error: ' . mysql_error());

if ($query)
{
  echo "1 record added";mysql_close($con);
}
else
{
  echo "Not added..";
}
?>

 

try that code ^

 

Also, is anything being sent to the $_POST vars?

what error are you getting?

Link to comment
Share on other sites

^ Did you use the code I posted above?

 

also,  clean up your html.. is is so messy, ive never seen it so bad.. also, put <> tags around your FORM:

 

<FORM id=mailinglist name=mailinglist onsubmit="return emailOnly(this.emaillist.value,'emaillist');" action="handle.php" method=post>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.