Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,165,347 members, 7,860,897 topics. Date: Friday, 14 June 2024 at 06:18 PM

Need Help With Insert - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Need Help With Insert (892 Views)

Problem With Insert Statement Mysql / Please Help On How To Insert Smiley In An Output Text In Java Script / Insert Image Into Mysql (2) (3) (4)

(1) (Reply) (Go Down)

Need Help With Insert by ckdoublene: 9:22pm On Feb 04, 2011
I'm trying to acquire data from one table(payments) and insert it into another (prerenthist).  Both tables are in the same database (prerentdb).  I get error message:
Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\hofiles\prerentadd.php on line 9
the code is below.  ?

<?php
$stat = mysql_connect(localhost,root,""wink or die('Unable to connect to database: ' . mysql_error());
$stat = mysql_select_db(prerentdb) or die('Unable to select database: ' . mysql_error());
$query = "INSERT INTO prerenthist (name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,late,comments,paidsum)
SELECT name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,late,comments,paidsum
FROM PAYMENTS;
$stat = mysql_query($query) or die('Query failed: ' . mysql_error());   
echo "data inserted</font>

"; 
mysql_close();
?>
Re: Need Help With Insert by segsalerty(m): 10:43pm On Feb 04, 2011
the keyword VALUES thats missing shld be causing problem
Re: Need Help With Insert by Kobojunkie: 1:20am On Feb 05, 2011
Check the column types. Make sure you the type you are selecting matches the type you are inserting into.
Re: Need Help With Insert by sweetpawn1: 10:31am On Feb 05, 2011
HELLO, WHATZ UP WITH THE LAST THING I ASKED YOU TO GIVE ME?

LET'S LOOK AT THIS ONE:

$query = "INSERT INTO prerenthist (name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,late,comments,paidsum)
SELECT name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,late,comments,paidsum
FROM PAYMENTS;


THE ABOVE SYNTAX IS WRONG BECAUSE YOU SHOULD HAVE AN END OF QUOTE.LIKE THIS:

$query = "INSERT INTO prerenthist (name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,late,comments,paidsum)
SELECT name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,late,comments,paidsum
FROM PAYMENTS";



EVEN AT THAT, THERE ARE LOGICAL ERRORS!
YOU WANT TO GET DATA FROM TABLE1 AND INSERT INTO TABLE2.
THAT MEANS THAT YOU SHOULD GO THROUGH EACH ROW OF TABLE1, GET OUT ALL THE DATA FIELDS IN THAT RECORD, AND TRANSFER THE DATA FIELD RECORDS TO TABLE2 .

I AM SPEAKING SPANISH - I KNOW. WILL BACK UP MY GIBBERISH WITH CODES SOON!
Re: Need Help With Insert by sweetpawn1: 11:00am On Feb 05, 2011
HERE IT IS:

<?php
$stat = mysql_connect(localhost,root,""wink or die('Unable to connect to database: ' . mysql_error());
$stat = mysql_select_db(prerentdb) or die('Unable to select database: ' . mysql_error());

$result= mysql_query("SELECT name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,late,comments,paidsum
FROM PAYMENTS"wink;
while($row=mysql_fetch_array($result))//this will let us go through the records of the payments table one by one.
{
//we extract the data from each field of the record and store in array called $row_record
for ($i=0;$i<=10;$i++)
{
$row_record[$i]=$row[$i];
}
/////////////////////////////



//now we put the array values into the prerenthist

$query = "INSERT INTO prerenthist ($row_record[0],$row_record[1],$row_record[2],$row_record[3],$row_record[4],$row_record[5],$row_record[6],$row_record[7],$row_record[8],$row_record[9],$row_record[10])";

$stat = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "data inserted</font>

";
/////////////////////////////////////////////////////////////////////////

}//end of loop

mysql_close();
?>



PLEASE, [size=18pt]RETURN FEED BACK!!!!!!!!!!!!![/size]
Re: Need Help With Insert by ckdoublene: 9:09pm On Feb 05, 2011
Sorry, I should have cleared this earlier. This was the solution:
<?php
$stat = mysql_connect(localhost,root,""wink or die('Unable to connect to database: ' . mysql_error());
$stat = mysql_select_db(prerentdb) or die('Unable to select database: ' . mysql_error());
$query = "INSERT INTO prerenthist
(name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,late,comments,paidsum)
SELECT name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,late,comments,paidsum
FROM payments";
echo "apt $apt data inserted</font>

";
$stat = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close();
?>
Re: Need Help With Insert by sweetpawn1: 2:32am On Feb 06, 2011
HMM, HOW DO YOU RUN THAT SCRIPT? DO YOU USE A FORM? WHERE DO YOU GET THE VALUES THAT ENTER INTO THE PRERENTHIST TABLE? I AM CURIOUS TO LEARN HOW YOU DID THAT! OR ARE YOU SHOWING A PIECE OF THE CODE?

HOW DID YOU SOLVE YOUR LAST PROBLEM?

OH AND FOR THE TRANSLATION OF WHAT I SAID LAST TIME WE MET.

NO SLEEP LEAVE ME O! ---> DO NOT SLEEP OFF AND LEAVE ME HERE WAITING FOR YOU TO POST BACK

MOSQUITOES DEY KILL ME FOR HERE! ---> WE HAVE THOSE VAMPIRE BLOOD SUCKING CREATURES EVERYWHERE IN OUR COUNTRY. THEY TAKE OVER FROM FILES AT NIGHT AND REALLY TORMENT US. SO THEY WERE BITING ME LIKE HELL!

I DEY SOUND THEM SLAP AND DEM DEY DO ME ODEOSHI! ---> I AM ATTACKING THEM BACK WITH SLAPS BUT ITS LIKE THEY JUST TAKE MY BLOWS, DUST DIRT OFF THEIR SHOULDERS AND SAY: THAT AIN'T NOTHING!
Re: Need Help With Insert by ckdoublene: 5:18am On Feb 06, 2011
Sweet, no there is no form.  I just read one table(current month's payments), which I refresh each month (the unresolved program) and insert the data into the next table(a history of payments). 
Don't tell me mosquitos are getting to you while you're at the computer? Here in Florida we have trouble with mosquitos during the warm months but not in the cooler months.  When I go hunting, if I'm near water , sometimes.  Still haven't figured out how to add the "add 10 to latechg" in the other program.
Re: Need Help With Insert by sweetpawn1: 5:03pm On Feb 06, 2011
HMM, INTERESTING!
YES THERE ARE MOSQUETOES EVERY WHERE IN THIS COUNTRY! THEY ARE EVEN GETTING IMMUNE TO INSECTICIDES. SOME FOLKS EVEN SUGGEST THAT WE USE JUJU (BLACK MAGIC) TO TACKLE THEM! AS I TYPE I CAN HEAR ONE HUMMING REASSURINGLY FROM A DISTANCE AS IF TO TELL ME OF THE FEAST THAT THEY WILL HAVE OF ME THIS NIGHT!

BUT STILL HOW DO YOU VIEW AND ENTER DATA INTO YOUR DATABASE?
Re: Need Help With Insert by ckdoublene: 10:52pm On Feb 06, 2011
the WHERE statement dictates which data is updated. You are referring to the original program?
Re: Need Help With Insert by sweetpawn1: 11:45pm On Feb 06, 2011
YES THE ORIGINAL, BUT YOU DON'T REALLY GET ME YET.
OKAY , IMAGINE YOU WERE GOING TO THE BERMUDA TRIANGLE AND WERE SCARED YOU WOULD BE "LOST"! THEN YOU WOULD LOOK FOR SOME ONE TO TAKE OVER YOUR WORK OF "PUSHING THE BUTTONS TO SAVE THE WORLD" FOR YOU. SO LET US SAY, THAT SOME ONE IS MOI! SO HOW WOULD YOU TELL ME TO ADD THE DATA TO YOUR CURRENT RENT UPDATING SYSTEM? OF COURSE YOU WOULD GIVE ME A GUIDE AS TO HOW YOU DO WHAT YOU DO AND THE TOOLS(SOFTWARE) YOU USE. THAT'S WHAT I WANT TO KNOW!
YOU ARE GIVING ME PART OF THE WHOLE PICTURE SO I CANNOT REALLY UNDERSTAND WHAT AND HOW YOU DO WHAT YOU DO!
IF I HAD A GLIMPSE OF THE WHOLE, THEN I CAN SURLY KNOW HOW TO MAKE IT WORK BETTER!
Re: Need Help With Insert by ckdoublene: 8:01am On Feb 07, 2011
Sweetheart, you speak my language so I don't understand the difficutlty explaining to you.   The below code says that all records in the database table which having the paidsum = rentdue or any records that have L in the late field should have the specified values  cleared (zeros or blanks).  This is to start the new month with a report ready to register payments for the new month.  The below code does that.  I want to expand the program to add $10 to the latechg field of any tenants who haven't paid the full rent (paidsum < rentdue) and increase the prevbal by the amount of the rent still owed (prevbal = prevbal +( rentdue - paidsum) for those late payers.  I have one glass of milk  - with marshmalloows in it - and cookies. Every cookie  I find in it, I want to remove. What am I saying, I'd rather have the cookies. This is the original problem with the original code.
<?php
$stat = mysql_connect("localhost","root",""wink;
$stat = mysql_select_db("prerentdb"wink;
$query = "SELECT name FROM payments Where apt='$apt'";
$stat = @mysql_fetch_assoc(mysql_query($query));
echo $stat["name"];
$sql = "UPDATE payments SET
amtpaid = 0, prevbal = 0,hudpay = 0, tentpay = 0, datepaid = ' ', late = ' ',
comments = ' ', paidsum = 0 WHERE paidsum = rentdue OR late = 'L'";
mysql_query($sql) or die("Update query failed."wink;
echo "Records have been updated";
?>

(1) (Reply)

Social Network / [Resolved Issue] Sql Syntax Needed / Android Developers, A Newbie Needs A Good Recommendation

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 29
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.