hmm, not getting errors when this is executed but no results

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

aredden
Forum Commoner
Posts: 29
Joined: Fri May 25, 2007 7:10 am

hmm, not getting errors when this is executed but no results

Post by aredden »

Here is what I have coded.

Code: Select all

<?php
session_start();

$_SESSION['sessid'] = $id;

$con = mysql_connect("********);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("******", $con);

mysql_query("INSERT INTO main2 (name, email, deptcity, deptdate, arrivalcity, retdate, pass1name, pass1age, pass1nation, pass2name, pass2age, pass2nation, pass3name, pass3age, pass3nation, pass4name, pass4age, pass4nation, comment) SELECT name, email, deptcity, deptdate, arrivalcity, retdate, pass1name, pass1age, pass1nation, pass2name, pass2age, pass2nation, pass3name, pass3age, pass3nation, pass4name, pass4age, pass4nation, comment FROM main1 WHERE main1.id = $id");

mysql_close($con);
//session_destroy();
?>
but no data gets moved. any thoughts?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Well, if you tell us the error that occurred, we can probably point out the error relative quickly.

Code: Select all

mysql_query("....") or die(mysql_error());
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Whoa whoa whoa whoa whoa. What are you doing here?

Code: Select all

INSERT INTO
main2
(name, email, deptcity, deptdate, arrivalcity, retdate, pass1name, pass1age, pass1nation, pass2name, pass2age, pass2nation, pass3name, pass3age, pass3nation, pass4name, pass4age, pass4nation, comment)
SELECT
name, email, deptcity, deptdate, arrivalcity, retdate, pass1name, pass1age, pass1nation, pass2name, pass2age, pass2nation, pass3name, pass3age, pass3nation, pass4name, pass4age, pass4nation, comment
FROM
main1
WHERE
main1.id = $id
What is this supposed to do?
Last edited by superdezign on Thu May 31, 2007 11:24 am, edited 1 time in total.
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

I hope it's because you removed your login details but the connection string doesn't have an ending "
aredden
Forum Commoner
Posts: 29
Joined: Fri May 25, 2007 7:10 am

Post by aredden »

ok the error i get now is

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

and I was trying to move data from one table to another. heh. but im new to the php game and i might not have done that properly.

but i was trying to insert into table2 with values from table 1 with a corrisponding table id = $id.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

aredden wrote:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Your whole sql statement is one single line, therefore the error message doesn't help you much ;)

try

Code: Select all

session_start();
$_SESSION['sessid'] = $id;

$con = mysql_connect("********");
if (!$con) {
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("******", $con) or die(mysql_error();

$query = "INSERT INTO
		main2
		(name, email, deptcity, deptdate,
		arrivalcity, retdate, pass1name, pass1age,
		pass1nation, pass2name, pass2age, pass2nation,
		pass3name, pass3age, pass3nation, pass4name,
		pass4age, pass4nation, comment)
	SELECT
		name, email, deptcity, deptdate,
		arrivalcity, retdate, pass1name, pass1age,
		pass1nation, pass2name, pass2age, pass2nation,
		pass3name, pass3age, pass3nation, pass4name,
		pass4age, pass4nation, comment
	FROM
		main1
	WHERE
		main1.id = $id";
mysql_query($query, $con) or die('<pre>mysql_error().': '.$query.'</pre>');

mysql_close($con);
What is $id and where does it come from?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Interesting... Well, it's totally possible. You should look up some SQL tutorials and read a bit of the manual.

Code: Select all

INSERT INTO `tableName` (columnNames) VALUES(columnValues);
Seeing as you're new to it, I'd suggest selecting the values, saving them in PHP, and then inserting them into the query from there.
aredden
Forum Commoner
Posts: 29
Joined: Fri May 25, 2007 7:10 am

Post by aredden »

found the problem I had $_SESSION.... = $id;
works as $id = $_SESSION['sessid']; :) thanks guys
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

aredden wrote:found the problem I had $_SESSION.... = $id;
works as $id = $_SESSION['sessid']; :) thanks guys
^_^ That made me giggle. :-p
aredden
Forum Commoner
Posts: 29
Joined: Fri May 25, 2007 7:10 am

Post by aredden »

superdezign wrote:
aredden wrote:found the problem I had $_SESSION.... = $id;
works as $id = $_SESSION['sessid']; :) thanks guys
^_^ That made me giggle. :-p
Did I miss something?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

aredden wrote:Did I miss something?
No no :lol:

It was one of those errors that was right in front of our face, but none of us noticed. Too simple. :-p
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

volka wrote:What is $id and where does it come from?
I did ;)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

volka wrote:
volka wrote:What is $id and where does it come from?
I did ;)
Showoff. :lol: I assumed he meant to set it to the session... Didn't even think that it was undefined.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

superdezign wrote:
volka wrote:
volka wrote:What is $id and where does it come from?
I did ;)
Showoff. :lol: I assumed he meant to set it to the session... Didn't even think that it was undefined.
Beware... volka sees things almost like feyd sees things...
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Everah wrote:
superdezign wrote:
volka wrote:I did ;)
Showoff. :lol: I assumed he meant to set it to the session... Didn't even think that it was undefined.
Beware... volka sees things almost like feyd sees things...
8O

Oh! Almost. Okay then.
There were almost two of them.
Post Reply