Jump to content


Photo

Php Mysql Code


  • Please log in to reply
4 replies to this topic

#1 phpnewbie1212

phpnewbie1212

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 15 December 2012 - 09:57 AM

Hello All, I am new to this forum and new to PHP. In Flash i am building a login system for my website. To do this I need to create a php file for Flash to connect to the mysql database. Now, i am a complete novice to php and i am struggling to find the right code for my php file.
Mysql database is called "example" and my table is called "users" it has six columns... email,username,password,age,country,and gender.
My php file is below: Can you please take a close look. I know it's probably full of errors but i have only just started learning php. Can you please highlight the errors for me and if i am missing something can you please tell me.

Thank You Mark

#2 phpnewbie1212

phpnewbie1212

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 15 December 2012 - 09:59 AM

Oops sorry i forgot to show the code lol. Here it is:
<?php
//Declare variables
$username = $_POST['username'];
$password = $_POST['password'];
//
//mysql connection variables
$email = $_Post['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$age = $_POST['age'];
$country = $_POST['location']
//
//connects to database
$link = mysql_connect("localhost","example_database","password") or die (mysql_error());
mysql_select_db("table_users") or die(mysql_error());
?>
$email = $_Post['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$age = $_POST['age'];
$country = $_POST['location']

//collects data from table
$data = mysql_query("SELECT * FROM users");
$results = mysql_query($query)
or die(mysql_error());
//put users info into the $info array
$info = mysql_fetch_array( $data ))
$userbio = $data["name"];
echo "systemResult=$userbio";

}
} else {
echo "systemResult=The login detail dont much our records
}
?>


#3 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 15 December 2012 - 10:07 AM

If you're having errors you need to post them. If you don't see errors, enable error_reporting and set to E_ALL. If you still don't see errors then you need to describe what your script does that you don't expect or doesn't do that you do expect. Asking someone to find the errors in your code without you taking any steps to debug it yourself is rude.

Also, wrap your code in code tags next time.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#4 gizmola

gizmola

    Advanced Member

  • Administrators
  • 3,968 posts
  • LocationLos Angeles, CA USA

Posted 15 December 2012 - 02:13 PM

A couple of obvious things:

- Check your syntax... there is a php end block in the middle of your code.
- The line $info = mysql_fetch_array( $data )) is incorrect in several ways. It should be

$info = mysql_fetch_array($data);

-The $_POST superglobal array name must be uppercase. In several places you attempt to access $_Post. PHP variable names are case sensitive ($Foo is not the same as $foo!). Of course you probably have not noticed the issue at this point because you aren't doing anything with the $_POST variables in the script.
-Your current query doesn't work because you try and do 2 queries in a row, where the first result is stored to $data, and the 2nd query attempts to use a $query variable that doesn't exist. It's a bit of a mess, and doesn't do much at present. A better intermediary test would be something like this:

$result = mysql_query("SELECT * FROM users") || die(mysql_error());

if ($result) {
} else {
  echo "No users found.";
}

$rows = array();

while ($row = mysql_fetch_assoc($result)) {
    $rows[] = $row;
}

foreach ($rows as $row) {
    echo "Email: {$row['email']} <br>
          Username: {$row['username']} <br>
          Age: {$row['age']} <br><br>\n";
}


#5 phpnewbie1212

phpnewbie1212

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 19 December 2012 - 10:13 AM

Hey, Thank you both for your replys. Your advice was great! I appreciate your help. Thank You




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com