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 Like 7 Dislike
Previous forums Next forums
Other forums

Update Database
Hi All,


I have a problem with this:

Code: [Select]<?php
session_start();

Weird Problem with curl while sending data
I am facing a weird problem with sending data to a site via curl.

If i send the value by this

Error when call dll from oracle
Hi all, please help me!

I have dll write C language, I want call it from oracle procedur

SAP Logon Failed
I tried to login to SAP through MMC.

When i click start and give password.

it

need good snippet manager
Hi. as i am coding and learning more, it is becoming difficult to manage code snippets. how you mana

How do I replace any number of character occurences with one occurrence?
How do I replace any number of character occurences with one occurrence?

Let's say I have:

Delete HTML file after loading
I have limited experience with php and its been a year or two since I've last used it. I have a sma

How do I send data using an html link
Hi

If I have
<a href="main_file.php">

How do I send data t

DateObject and Nulls
Hi all,

I have an array mapped to a value object. One of the items in the array is a PHP Date

need help in update query
hi
i have a dynamic form. i need help in how can i use update query when values from dynamic for

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash