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','[email protected]',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
https://forums.phpfreaks.com/topic/167490-solved-insert-trouble-with-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.