Welcome, Guest. Please login or register.
Did you miss your activation email?
05/23/12, 00:56
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  MySQL, PostgreSQL, MS SQL, Access (Moderators: Flash-db, Musicman, Ronald Wernecke, Jorge Solis, Andries Seutens)
| | |-+  inserting data to SQL through PHP
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 Print
Author Topic: inserting data to SQL through PHP  (Read 6550 times)
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« on: 04/15/02, 11:08 »

I have been having problems inserting data into my SQL databse.  I have scaled it down so the simplest code to try and get it to work, I am still having problems. I am using this php code....

<?php
$server-"localhost";
$user="mw9net_test";
$pass="test";
$database="mw9net_Login";
$table="test";

$connect="mysql_connect($server,$user,$pass);

mysql_select_db($database,$connect);

$sql="INSERT INTO $table (ename, email) VALUES('$name','$email')";
mysql_query($sql,$connect);
?>

This gives me a parse error on line 12.  I can't seem to locate the problem.  A little help would be much appreciated.
Logged
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #1 on: 04/15/02, 16:50 »

well....I have no clue what the problem was...but it just magically started to work. Oh well. Lates.
                                                                                            -Ian
Logged
Flash-db
Administrator
Systems Administrator
*****
Posts: 1867



View Profile WWW
« Reply #2 on: 04/18/02, 18:33 »

Looks correct to me.  Where you using this on a hosting service server or on your on computer - if it was on a hosting service maybe their database was down for a bit.  Other then that the syntax looks correct.
Logged

-Jeff.
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #3 on: 04/18/02, 22:34 »

     well...I am running it on a server.  I rewrote the code exactly...then it worked I thought maybe there was an error in the way I wrote it originally, but I compared and no.  The database wasn't down, because I had been working in it in a sqladmin internet program they have that links to your databse. That was working fine.
    I have this working...but my database queries won't work now.  This is starting to be more trouble with every new thing I add. A one day job is spanning over two weeks.  

I query the database.....
<?php
$server="localhost";            
$DBuser="mw9net";              
$DBpass="*******";
$database ="mw9net_Login";
$table="profiles";

$DBconnect = mysql_connect($server, $DBuser, $DBpass);

mysql_select_db($database,$DBconnect);

$sql="SELECT * FROM $table WHERE username = 'a'";
$result= mysql_query($sql,$DBconnect);

print($result);

mysql_close($DBconnect);

?>

and I get this in return when I put the URL in my browser....
Resource id #2


I have a username value of "a" and my password is "a" so that I could test the querry.  Is this what it should be feeding me?
Logged
Flash-db
Administrator
Systems Administrator
*****
Posts: 1867



View Profile WWW
« Reply #4 on: 04/18/02, 22:51 »

Oh - that's cause the $result is more like a pointer to the result then the actual result.

You'll have to use something like,

(get rid of the print($result); part.

...
$i = 0;
$result= mysql_query($sql,$DBconnect);
$UserName =   mysql_result($result,$i,"UserName");

print "The UserName is $UserName";

---------------
So you've got to break apart the $result resource into individual parts that correspond to Columns in the Database.  In this case you would have a column named UserName - that value would be taked out and assigned to the variable $Username.  

Their are other ways to do this I'll try to post another way later - but this should work for now.  

Let me know if that made sense.  If not i'll try to explain it a bit more.
Logged

-Jeff.
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #5 on: 04/19/02, 11:08 »

Dang....thank you so much.  This was really starting to stress me out.  
  About the $i variable....if I put a "1" instead of a "0"....will that give me the second column in the query?....what does this actually reference too?
  Man I cannot find good material on this stuff.  It really makes it hard to learn.  I know some SQL and am learing more everyday.  I also know some PHP and am learning more everyday, but I cannot find enough information on their integration.  Everything that I do find, doesn't work....well I thanx for the help.
Logged
Flash-db
Administrator
Systems Administrator
*****
Posts: 1867



View Profile WWW
« Reply #6 on: 04/19/02, 15:06 »

Maybe this will help:
Usually I use something like this to loop through multiple results. The $numR value is the number of results returned.  The $i value starts at zero then increase's by one for each record set.  


$numR = mysql_num_rows($result);

$i = 0;
while ($i < $numR) {
   $Email = mysql_result($result,$i,"Email");
   $FirstName = mysql_result($result,$i,"FirstName");
   $LastName = mysql_result($result,$i,"LastName");
   $Name = "$FirstName $LastName";
               mail($Name." <".$Email.">",$Subject, $Message, "From: ".$FromName." <".$FromEmail.">");

$i++;
}
Logged

-Jeff.
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #7 on: 04/19/02, 16:32 »

Yeah...this was the first method I used with slightly different syntax...it wouldn't work...I am sure it was my bad.  Well I will mess aound with this one and see how it goes.  PHP > SQL integration is pretty touchy.  I've totally got the concepts down for the loops...I took a VBA 6.0 class last year....I learned all of that stuff....it is just getting thte correct syntax I guess.  And I do not know all of the different SQL commands that PHP comes with or how they are supposed to be coded.  I have no problem with the SQL itself.  Thanx again....I will try this one out now and get back to you. Lates.
Logged
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #8 on: 04/19/02, 21:08 »

this is the code that I originally used for the whole thing with querying the database for the username and seeing if it is valid....then I check if the corresponding passwor was correct....I think that I need to change it to the $sql="blah blah"
mysql_query($sql, $DBconnect) format.....maybe you could spot the syntax error....

<?php
$server="localhost";            
$DBuser="mw9net";              
$DBpass="qweasdzxc";
$database ="mw9net_Login";
$table="profiles";

$DBconnect = mysql_connect($server, $DBuser, $DBpass);

mysql_select_db($database,$DBconnect);

$result = mysql_query(SELECT * FROM $table, $DBconnect);

$numrows = $numrows-1;

$username="a";
$counter=0;
do{
$username = (mysql_result($result, $counter, "username"));
++$counter;
}
while($search !=$username && $counter <=$numrows);

if($search != $username) {
$feedback = "Invalid username.";
print ("$feedback");
}

$match = $counter-1;
$passwordtest = (mysql_result($result2, $match, "password"));
if ($passwordtest != $password) {
$feedback = "Incorrect password.";
print ("$feedback");
}

mysql_close($DBconnect);

?>


It gives me the php parse error....
Parse error: parse error in /home/mw9net/public_html/login/login2.php on line 12

I am not very good as you can see with the PHP, but I am tryin.  If you see a prob I would appreciate the guidence or if this method is no good...then fell free to tell me that too. Lates.
Logged
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #9 on: 04/19/02, 21:15 »

oh...and I didn't blow off the code yu gave me in your last message...I was just wondering if this code might work with some minor adjustments.....I will try your method if this is a total loss...Thanx Jeff.
Logged
Musicman
Administrator
Systems Administrator
*****
Posts: 2685



View Profile WWW Email
« Reply #10 on: 04/20/02, 17:24 »

Hi,

count down to line 12 - there is some sql statements inside the php - place them inside quotes
$result = mysql_query("SELECT * FROM $table", $DBconnect);

Musicman
Logged
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #11 on: 04/22/02, 00:12 »

Hey Musicman,
   Thanx....That did the trick.  Now for my next dilema.  This is my new code.

<?php
$server="localhost";            
$DBuser="mw9net";              
$DBpass="******";
$database ="mw9net_Login";
$table="profiles";

$DBconnect = mysql_connect($server, $DBuser, $DBpass);

mysql_select_db($database,$DBconnect);

$result = mysql_query("SELECT * FROM $table", $DBconnect);

$numrows = "$numrows-1";

$username="a";
$counter=0;
do{
$username = (mysql_result($result, $counter, "username"));
++$counter;
}
while($search !=$username && $counter <=$numrows);
if($search != $username) {
$feedback = "Invalid username.";
$status="_root.status=$feedback";
print ("$status");
$match = $counter-1;
$passwordtest = (mysql_result($result, $match, "password"));
}
elseif ($passwordtest != $password) {
$feedback = "Incorrect password.";
$status="_root.status=$feedback";
print ("$status");
}
else{
$status="access granted.";
$status="_root.status=$status";
print ("$status");
mysql_close($DBconnect);
}
?>


Now the variables are not being passed back to Flash.  I tried it with and without the _root.    .  I have a dynamic textbox on the main stage on frame 3.  It is not inside a mc or anything.  It name is "status" and it will not populate with the text.  Maybe you could give me a little help on this one too. Oh and the code is working.  If you open the PHP file in your browser the text will show up as "_root.status=invalidusername". Lates.
                                                                          -Ian
Logged
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #12 on: 04/25/02, 17:05 »

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Well I tested out the code a little further and it appears it was a false signal....it still does not work.  I put this as my code to see if it was working....

<?php
$server="localhost";            
$DBuser="mw9net";              
$DBpass="*******";
$database ="mw9net_Login";
$table="profiles";

$DBconnect = mysql_connect($server, $DBuser, $DBpass);

mysql_select_db($database,$DBconnect);

$result = mysql_query("SELECT * FROM $table", $DBconnect);

$numrows = "$numrows-1";

$counter=0;
do{
$memberid = (mysql_result($result, $counter, "username"));
++$counter;

while($search !=$memberid && $counter <=$numrows
$match = $counter-1;
}
mysql_close($DBconnect);
}
?>

I have a username with the value of BurtonRider1983 in the SQL database.....and a password of test.....if I put in the browser window.........
....../login.php?memberid=BurtonRider1983.....
I get the message....invalid username...any help????Please
Logged
Musicman
Administrator
Systems Administrator
*****
Posts: 2685



View Profile WWW Email
« Reply #13 on: 04/26/02, 16:15 »

Hi,

what do you want to achieve with this code:
$numrows = "$numrows - 1";
in particular with those quote marks?

Musicman
Logged
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #14 on: 04/26/02, 16:29 »

hmmm....well as you can see I am new to this.  I guess that that code is an error.  I believe that I left it there from some previous version in which I queried the database from Flash with a value for numrows.  I will get rid of that, but that still wouldn't explain why it wouldn't locate the name, right?
Logged
Pages: [1] 2 Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!