Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple insert not working

Status
Not open for further replies.

LWolf

Programmer
Feb 3, 2008
77
US
I am putting a simple page together for friends to add their name to my super bowl party. The insert is not working.

The insert line echo's this...
INSERT INTO peeps(pname, pcnt, dish) VALUES('Raquel', 1, 'Brownies')

There are 4 variables passed: rec (to determine if it needs to add a rec), pname, pcnt and dish.

Here is the code (yes I know it is open to sql injection but it is only up for a week and my friends do not understand computers!)...
if ($_GET['rec']=="add"){
$peep_insert="INSERT INTO peeps(pname, pcnt, dish) VALUES('" . $_GET['pname'] . "', " . $_GET['people'] . ", '" . $_GET['dish'] . "')";
$my_insert=$pdo->prepare($peep_insert);
echo $peep_insert . "<br>";
$my_insert->execute();
}

What am I doing wrong?
 
assuming you already have the $pdo variable properly instantiated
Code:
if ($_GET['rec']=="add"){
 $peep_insert="INSERT INTO peeps(pname, pcnt, dish) VALUES(?,?,?)";
 $params = array($_GET['pname'],$_GET['people'],$_GET['dish']);
 $s=$pdo->prepare($peep_insert);
 if($s === false){ print_r($pdo->errorInfo());}
 $result = $s->execute($params);
 if($result === false){ print_r($s->errorInfo());}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top