Forum Moderators: coopster

Message Too Old, No Replies

Does this code look right?

         

ganderla

11:21 pm on Nov 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am trying to insert form values into a database. The code I have worked for one field, but when I added 2 more fields, it is not working. I would appreciate if someone could tell me if the code looks right, then I will see if I can find the problem in the DB.

<?php
require_once("config2.php");
require_once("helper.php");
require_once("class.mysql.php");

$db = new MySQL($host,$dbUser,$dbPass,$dbName);

$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];

if(isValidEmail($the_email))
{
$email = mslash($the_email);

$sql = "SELECT * FROM offers WHERE email = $email";
$result = $db->query($sql);

if($result->size() == 0)
{
$sql = "INSERT INTO offers(name, phone, email) VALUES($name, $phone, $email)";
$result = $db->query($sql);

if($db->isError())
{
die("error inserting email");
}
}
}
?>

charlier

11:28 pm on Nov 29, 2005 (gmt 0)

10+ Year Member



Hmm I think you probably need ''s around your name field in the insert statement. All char, text and blob fields need to be quoted, if you have embeded 's you need to escape them.

ganderla

5:02 am on Nov 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I tried this, and it is still not going in. Any other suggestions?

$sql = "INSERT INTO offers('name', 'phone', 'email') VALUES('$name', '$phone', '$email')";

tomda

5:46 am on Nov 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try
$sql = "INSERT INTO offers(name, phone, email) VALUES('$name', '$phone', '$email')";

Also, note that you can echo your query to debug it.
Just echo $sql before call the result.

To know what wrong with the query, copy it and paste it in SQLMyAdmin, a tool to manage your database. It will tell what wrong with the query.

varunkrish

9:20 am on Nov 30, 2005 (gmt 0)

10+ Year Member



try using

$name = $_POST["name"];
$phone = $_POST["phone"];
$email = $_POST["email"];

ganderla

9:34 am on Nov 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I appreciate everyone's help, I stopped trying. I have never written code before and I need this on the 1st. I just changed it so I would get emailed the results. Did not make a difference to me.

Thank you all again. I will try again when I am not stressed about getting it done.

charlier

11:14 pm on Nov 30, 2005 (gmt 0)

10+ Year Member



Post the definition of your table.