Add User script "Could not execute query"
Posted on
16th Feb 2014 07:03 pm by
admin
This should be an easy script but I can't get it to run. Can someone please help me?
<html><head><title>Adding a User</title></head>
<body>
<?php
$self = $_SERVER['PHP_SELF'];
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$user_email = $_POST['useremail'];
if( (!$first_name) or (!$last_name) or (!$user_email) )
{
$form ="Please enter all new user details...";
$form.="<form action="$self"";
$form.=" method="post">First Name: ";
$form.="<input type="text" name="firstname"";
$form.=" value="$first_name">
Last Name: ";
$form.="<input type="text" name="lastname"";
$form.=" value="$last_name">
Email: ";
$form.="<input type="text" name="useremail"";
$form.=" value="$user_email">
";
$form.="<input type="submit" value="Submit">";
$form.="</form>";
echo($form);
}
else
{
#connect to MySQL
$conn = @mysql_connect("localhost","xxxx","xxxx")
or die("Could not connect to MySQL");
#select a database
$db = @mysql_select_db("xxxx",$conn)
or die("Could not select database");
#create the SQL query
$sql = "insert into tablename (firstname, lastname, useremail)
values ("$first_name",'"$last_name","$user_email" )";
#execute the query
$result = @mysql_query($sql,$conn)
or die("Could not execute query");
if($result)
{ echo("New user $user_email added"); }
}
?>
</body></html>
No comments posted yet
Your Answer:
Login to answer
331
7
Other forums
Problem with variable declaration in switch statement
Hello, I am having some trouble assigning a value to a variable inside a switch statement. What I a
Basic Question Regarding PHP Includes
Hi
Just starting out with PHP.
Working on a site that uses some basic includes, these
Add trigger to UpdatePanel programmatically
Hi,I'm working on a website which uses AJAX and Masterpages. What I have is an AJAX UpdatePanel whi
Extracting URL pointer within XML tag
Hi.
I'm trying to extract text between two quotation marks in XML. For example, I want to ex
Logging and nologging bulk insert
Hi,
oracle version: 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
how to query data from website using VC?
I want to query some datum from a website,so I need a program to read data from a .csv file, and ass
natcasesort works on one server but not on another
Hi
I have a problem that I was hoping that someone can help me with.
I'm trying to use
Mysterious Timeouts
I've deployed a few simple AJAX-enabled web page to a local server that is accessed through the Inte
Problem with "dynamic" index page
Hi. I have one question. In my index.php page I have this kind of code:
Code: // listaa sivut
Help with Contact Form
I have this Form on an html page and the associated code on page.php (below).
I keep getting the