Jump to content

HTML FROM + PHP + MySQL fault - suspected fault in PHP


FreedomandDemocrazy

Recommended Posts

Greetz,

 

 

I am trying to write a simple newsletter sign up form using HTML FORM + PHP + MySQL.

 

I seem to be having a problem getting it working and I suspect the issue is in my PHP code and was wondering if someone could take a look at it for me to see if they can spot any obvious mistakes.

 

<?php

$link = mysql_connect('localhost', 'testuser', 'pass1');

if (!$link) {

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

}

echo 'Connected successfully';

mysql_select_db("testdb", $link);

$sql="INSERT INTO newsletters(mens)

VALUES

('$_POST[e-mail]')";

if (!mysql_query($sql,$link))

{

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

}

echo "Done!";

mysql_close($link);

?>

 

Note: My SQL Database is named "testdb", I have a table called "newsletters" and a field called "mens".

 

Kind regards.

Link to comment
Share on other sites

There was really nothing wrong with the way you had it to start with. When you start concatenating variables into strings when it isn't necessary, all you do is introduce a greater number of chances to make a typo.

 

The more common way to write it would be to leave array indices that are strings quoted, and use complex notation.

 

$sql="INSERT INTO newsletters(mens)VALUES('{$_POST['e-mail']}')";

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.