Jump to content

[SOLVED] newbie mySql problem


footbagger

Recommended Posts

I'm extremley new to mySql, and trying to get a basic mySql page working on my computer before I upload it.

 

The aim is to use the POST form to put data into a database, but it always seems to have trouble connecting to the database. Here's the output:

 

Test sql page Name Entered:

joe

Info Entered:

213453251

 

 

Connected successfully

Could not select database

 

here is the code:

 

<html>
<head>
<title>php post form test </title>
</head>
test sql page
<hr />

Name Entered:<br /><?php echo $_REQUEST["Name"]; ?><br />
Info Entered:<br /><?php echo $_REQUEST["Info"]; ?><br />

<br />
<br />

<?php
$db = mysql_connect("127.0.0.1","janis","test") ;
if (!$db){
echo "error";
	die('Could not connect: ' . mysql_error());
/*catches connection errors and aborts if the databse can't be updated*/
}

/*connects to the sql server at localhost, with username: janis password: test*/

echo 'Connected successfully';

$table = "testDatabase";
mysql_select_db($table) or die('Could not select database');
/*having trouble connecting...??????????????????*/

mysql_query ('INSERT INTO ' . $table . ' VALUES ( $_REQUEST["Name"], $_REQUEST["Info"] );') or die('Error, query failed. ' . mysql_error());
/*insert the data tuple (name,info) using the data sent by POST from the form on the other page.*/


// Performing SQL query
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());


echo "<br />";
echo "the new table is now:  <hr />";
// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($db);

?>

<body>
</body>
</html>

 

Any help is greatly appreciated

 

 

 

-Janis

Link to comment
Share on other sites

ok sorted that problem 8)

 

now this is happening:

joe

Info Entered:

213453251

 

 

Connected successfully

Error, query failed. 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 '["Name"], $_REQUEST["Info"] )' at line 1

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.