Jump to content

[SOLVED] Insert trouble with script?


nomadsoul

Recommended Posts

I've been struggling with my insert.php script.  It won't insert into the users table.  However it will from the command line. Would anyone be kind enough to look at my insert statement in the insert.php script below? I've also included the submit form.  I'm just trying to keep it simple for now.

 

 

//This works:

mysql> insert into users (first_name, last_name, email, registration_date)values                  ('krunk','krunk','krunk@krunk.com',NOW());

Query OK, 1 row affected (0.00 sec)

 

//My insert.html

<form action="insert.php" method="post">

<p>First Name: <input type="text" name="first_name" size="15" maxlength="20" >

 

<p>Last Name: <input type="text" name="last_name" size="15" maxlength="40" >

</p>

<p>Email Address: <input type="text" name="email" size="20" maxlength="80" > </p>

 

<p><input type="submit" name="submit" value="Register" /></p>

<input type="hidden" name="submitted" value="TRUE" />

</form>

 

Here is the insert.php:

<?php

$con = mysql_connect("MySQL.host.com","myuname","mypword");

if (!$con)

  {

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

  }

 

mysql_select_db("db-language", $con);

//Is this correct?

$sql="INSERT INTO users (first_name, last_name, email,registration_date)

VALUES

('$_POST[first_name]','$_POST[last_name]','$_POST',NOW() )";

 

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

  {

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

  }

echo "1 record added";

 

mysql_close($con)

?>

 

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.