Using insert variable

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
peter.kathae
Forum Newbie
Posts: 1
Joined: Fri Oct 23, 2009 3:24 am

Using insert variable

Post by peter.kathae »

need a way to inert variable data to mysql database

$acc = "212121212";
$nok = "Nokia1100";
$db_link = mysql_connect("localhost","root", "");
mysql_select_db('Phones', $db_link ) or die (mysql_error());
$sql = "INSERT INTO `phones`.`phonedata` (`accNum`, `model`) VALUES ($acc,$nok)";

the coloured part is the one bringing
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Using insert variable

Post by Mark Baker »

SQL requires you to quote your strings:
$sql = "INSERT INTO `phones`.`phonedata` (`accNum`, `model`) VALUES ($acc,'$nok')";
Post Reply