|
-
the cheesy child
Php+MySQL Help!
hey everybody, havent been on for a while. but i have a bit of an issue here:
I'm making a flash chat based with PHP and MySQL (finally.)
And right now im just trying to get used to connecting PHP with MySQL. there's always seemed to be problems whenever i do, hoping somebody can help me with this one.
(note: dont mind my immature notes... its only a test file)
Here's my php file:
PHP Code:
<?php
$con = mysql_connect("secret","secret","secret");
if (!$con)
{
die('Could not connect because you suck.');
}
mysql_select_db("jchee_chat", $con);
$sql = mysql_query("INSERT INTO Users (Username, Age)
VALUES ('$_POST[Username]', '$_POST[Age]')");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "you were added!"
mysql_close($con);
?>
Note: replaced my details with "secret" and for a very good reason.
in case you wanna see where i get the POST variables "username" and "age" from, here's the form it comes from:
PHP Code:
<html>
<head>
</head>
<body bgcolor=#CC9966>
<font size="100" face="Arial" color="#0066FF">
<form action="test1.php" method="post">
Username: <input type="text" name="Username" />
Age: <input type="text" name="Age" />
<input type="submit" />
</form>
</font>
</body>
</html>
Last edited by bounceboy; 04-05-2010 at 05:13 AM.
-
Help
Hey, as I understand there are many issues with this script so I have made you a less complex one that does exactly the same.
PHP Code:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'database';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect because you suck.');
mysql_select_db($dbname);
$sql = mysql_query("INSERT INTO Users (Username, Age) VALUES ('$_POST[Username]', '$_POST[Age]')");
echo "you were added!"
?>
PHP Code:
<html>
<head>
</head>
<body bgcolor=#CC9966>
<font size="100" face="Arial" color="#0066FF">
<form action="test1.php" method="post">
Username: <input type="text" name="Username" />
Age: <input type="text" name="Age" />
<input type="submit" />
</form>
</font>
</body>
</html>
Regards,
Sir. Parker
-
the cheesy child
Thanks! That helped alot! It should hopefully work now!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|