MySQL database is not getting populated

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manishrathi
Forum Newbie
Posts: 6
Joined: Mon May 14, 2012 5:16 pm

MySQL database is not getting populated

Post by manishrathi »

I am using wamp server on windows 7 home premium.

When following php script is run on server, it runs fine without ay error. But when I check the database table, I find it empty. So table is not getting populated by the script. Why is that ? Whats wrong in here ?

Code: Select all

<html>
<head>
</head>

<body>
<?php
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$email = $_POST['emailid'];
$when = $_POST['happenedon'];
$howlong = $_POST['gonefor'];
$whosaw = $_POST['seenby'];
$description = $_POST['describe'];
$what = $_POST['whatdidtheydo'];

$add = $_POST['anythingtoadd'];

echo "Your first name is ".$fname."<br />";
echo "Your last name is ".$lname."<br />";
echo "Your email is ".$email."<br />";
echo "Your dog is gone since ".$when."<br />";
echo "Your dog is gone for ".$howlong."<br />";
echo "Your dog was seen by ".$whosaw."<br />";
echo "Your dog looked ".$description."<br />";
echo "They ".$what."<br /><br />";
echo "Thanks for Reporting Abduction" ;

echo "report is sent" ;

$connect = mysqli_connect('localhost', 'root', '', 'phptest') or die ("Error connecting to database") ;

$query1 = "insert into gwar (firstname, lastname) values ($fname, $lname)";

mysqli_query($connect, $query1);
?>
</body>
</html>
Thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: MySQL database is not getting populated

Post by requinix »

The mysqli extension supports prepared statements. You need to use them. Take a look at the examples for mysqli_prepare to see how - don't worry, it's really simple.
It also takes care of the SQL injection problem you have right now.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: MySQL database is not getting populated

Post by Celauran »

What errors are you getting?

mysqli::$error
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: MySQL database is not getting populated

Post by requinix »

Celauran wrote:What errors are you getting?

mysqli::$error
Syntax error: no quotes around the first- and lastname values.
Post Reply