Forum Moderators: coopster
I'm sure someone here will spot this immediately I'm working on a (very) basic little script to add customers information to a database and being a visual designer moreso than a programmer, I can't see where I'm going wrong with this. It won't insert the info when I submit.
Any help would be appreciated, thanks!
gen
<?php
function createform() {
echo '<form action="'. $_SERVER['REQUEST_URI'] .'" method="post">
<p>Name:<br />
<input type="text" name="name" id="name" />
</p>
<p>Email:<br />
<input type="text" name="email" id="email" />
</p>
<p>Phone:<br />
<input type="text" name="phone" id="phone" />
</p>
<p>Address:<br />
<textarea name="address" id="address" cols="45" rows="5"></textarea>
</p>
<p>Comments: <br />
<textarea name="comments" id="comments" cols="45" rows="5"></textarea>
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit" />
<input type="reset" name="reset" id="reset" value="Reset" />
</p>
</form>';
}
$submit = $_GET['submit'];
if(isset($submit)) {
$name = $_GET['name'];
$email = $_GET['email'];
$phone = $_GET['phone'];
$address = $_GET['address'];
$comments = $_GET['comments'];
mysql_query("INSERT INTO customers (name, email, phone, address, details) VALUES('$name', '$email', '$phone', '$address', '$comments') ") or die(mysql_error());
echo '<p class="success">Customer Added!</p>
<ul>
<li>Name: '. $name .'</li>
<li>Email: '. $email .'</li>
<li>Phone: '. $phone .'</li>
<li>Address: '. $address .'</li>
<li>Comments: '. $comments .'</li>
</ul>';
} else {
createform();
}
?>
@Pic, I'll try it once I get finished work for the day and let you know how it goes.
Does it have anything to do with this part:
mysql_query("INSERT INTO customers (name, email, phone, address, details) VALUES('$name', '$email', '$phone', '$address', '$comments') ") or die(mysql_error()); Thanks again folks, if it were a CSS problem I'd be good to go but I'm lost when it comes to PHP...
mysql_query("INSERT INTO customers (name, email, phone, address, details) VALUES('$name', '$email', '$phone', '$address', '$comments') ") or die(mysql_error());
to
mysql_query("INSERT INTO customers (name, email, phone, address, details) VALUES("'.$name.'", "'.$email.'", "'.$phone.'", "'.$address.'", "'.$comments.'") ") or die(mysql_error());
and if that doesn't work, try this in case too:
mysql_query("INSERT INTO customers (name, email, phone, address, details) VALUES('".$name."', '".$email."', '".$phone."', '".$address."', '".$comments."') ") or die(mysql_error());