Jump to content

Php Mysql Code


phpnewbie1212

Recommended Posts

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

Link to comment
Share on other sites

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
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.