Jump to content

Recommended Posts

I have a test.php page and a insert.php page on my site

 

Here is the code for the insert.php

 

<?php
$connection = mysql_connect("mysql","madjack87","polosport1");
if (!$connection){
	die("Could not connect: ") . mysql_error());
}

mysql_select_db("madjacknews", $connection);

$sql="INSERT INTO members (email)
VALUES
('$_POST[email]')";

if(!mysql_query($sql,$connection)){
	die("Error: " . mysql_error());
}
echo "1 record added";
mysql_close($connection)
?>

 

Here is the code for the test.php page

 

<form action="insert.php" method="post">
Email: <input type="text" name="email" />
<input type="submit" />
</form>

 

After clicking submit on the form it takes me to insert.php and the page is blank.

 

And when checking phpmyadmin there where no new records added.

 

Any help?

You do not need mysql_close as an fyi.

 

<?php
   $connection = mysql_connect("mysql","madjack87","polosport1");
   if (!$connection){
      die("Could not connect: ") . mysql_error());
   }
   
   mysql_select_db("madjacknews") or die("Unable to select database: " . mysql_error());
   
   $sql="INSERT INTO members (email)
   VALUES
   ('{$_POST['email']}')"; // notice the use of { and }, doing that will allow the array index to display without error.
   
   if(!is_resource(mysql_query($sql))){
      die("Error: " . mysql_error());
   }
   echo "1 record added";
?>

 

Also the $connection is not required for mysql unless you are using multiple databases.

 

Try the above and see what happens...I also added to your if the is_resource definition. If the SQL had a syntax error it will not return a valid resource, so that is a decent check to do.

I just tried this exact code still no change.

 

You do not need mysql_close as an fyi.

 

<?php
   $connection = mysql_connect("mysql","madjack87","polosport1");
   if (!$connection){
      die("Could not connect: ") . mysql_error());
   }
   
   mysql_select_db("madjacknews") or die("Unable to select database: " . mysql_error());
   
   $sql="INSERT INTO members (email)
   VALUES
   ('{$_POST['email']}')"; // notice the use of { and }, doing that will allow the array index to display without error.
   
   if(!is_resource(mysql_query($sql))){
      die("Error: " . mysql_error());
   }
   echo "1 record added";
?>

 

Also the $connection is not required for mysql unless you are using multiple databases.

 

Try the above and see what happens...I also added to your if the is_resource definition. If the SQL had a syntax error it will not return a valid resource, so that is a decent check to do.

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.