PHP Code Help Please

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
Gairo
Forum Newbie
Posts: 3
Joined: Mon Aug 19, 2013 3:22 pm

PHP Code Help Please

Post by Gairo »

Hi,

Decided to use MYSQL. Having an issue updating/inserting/deleting from my PHP script but I can cut and paste the SQL Query into PHPMyAdmin SQL and the commands work.

This SQL Query works from PHP MyAdmin but fails in my code:
INSERT INTO `frtplus_setup_frtpluscom519443`.`setup` (`f_upsrec`, `f_add1`, `F_add2`) VALUES ('zz', 'test address AS1 rtec 2', 'test addd AS2 rec 2 ')


Code connects to database, list f_add1 content which works but the insert does not update

<?php virtual('/Connections/bhhgh.php');

mysql_select_db($database_bhhgh, $bhhgh);

$query_Recordset1 = "SELECT * FROM setup ";

$Recordset1 = mysql_query($query_Recordset1, $bhhgh) or die(mysql_error());

// display f_add1 contents of database
while ($row = mysql_fetch_assoc($Recordset1))
{
echo $row['f_upsrec'] . " " . $row['f_add1'];
echo "<br>";
}

$mqlstring= "INSERT INTO `frtplus_setup_frtpluscom519443`.`setup` (`f_upsrec`, `f_add1`, `F_add2`) VALUES ('zz', 'test address AS1 rtec 2', 'test addd AS2 rec 2 ')";

mysqli_query($bhhgh,$mqlstring);

mysql_free_result($Recordset1);
?>

Any help would be appreciated.

Gary
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Code Help Please

Post by Celauran »

Code: Select all

mysql_select_db($database_bhhgh, $bhhgh);

Code: Select all

mysqli_query($bhhgh,$mqlstring);
mysql != mysqli
Gairo
Forum Newbie
Posts: 3
Joined: Mon Aug 19, 2013 3:22 pm

Re: PHP Code Help Please

Post by Gairo »

Hi,

What are you saying here? I'm not getting it
Gairo
Forum Newbie
Posts: 3
Joined: Mon Aug 19, 2013 3:22 pm

Re: PHP Code Help Please

Post by Gairo »

I figured it out... Need to have a ; after "rec 2" but before the ')

Good
$mqlstring= "INSERT INTO `frtplus_setup_frtpluscom519443`.`setup` (`f_upsrec`, `f_add1`, `F_add2`) VALUES ('zz', 'test address AS1 rtec 2', 'test addd AS2 rec 2 ;')";

Not Good
$mqlstring= "INSERT INTO `frtplus_setup_frtpluscom519443`.`setup` (`f_upsrec`, `f_add1`, `F_add2`) VALUES ('zz', 'test address AS1 rtec 2', 'test addd AS2 rec 2 ')";
akhilesh1010
Forum Newbie
Posts: 15
Joined: Thu Aug 22, 2013 1:56 am

Re: PHP Code Help Please

Post by akhilesh1010 »

Lets try this
$mqlstring="INSERT INTO 'setup' ('f_upsrec', 'f_add1', 'F_add2') VALUES ('zz', 'test address AS1 rtec 2', 'test addd AS2 rec 2 ')";
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Code Help Please

Post by Celauran »

You'd want backticks around the table name, not single quotes. The biggest problem above is that he is using mysql_ and mysqli_ functions interchangeably.
Post Reply