Forum Moderators: coopster
here is my very simple script
im just trying to sent a value to another page and display it
<html>
<head>
<title>who are you?</title>
</head>
<body>
<form action = "youare.php" method="POST">
please enter your name:<br />
I am.......
<?php print('<input type="text" name ="person" value="' . $person . '" size ="15" />');?>
<input type="submit" value ="go!" size ="15" />
</form>
</body>
</html>
<html>
<head>
<title>you are</title>
</head>
the page that recieves it all
<body>
<?php
print('well, hello ' . $person . ', nice to meet you!');
print('<br />');
print('<a href="whoareyou.php?person=' . urlencode($person) . '">back to who are you?</a>');
?>
</body>
</html>
i get the following
well, hello , nice to meet you!
back to who are you?
i had this issue before but cant seem to fix it
can you help?
i run the pages and add data myself, i get no error msgs and it confirms that its been added but when I check phpmyadmin the table remains empty, can you help?
<html>
<head>
<title>Please enter details</title>
</head>
<body>
<form action="insert.php" method ="POST">
<?php
echo "please insert details";
echo "<p>";
print('<Last name: <input type="text" name="last_name" size="15" />');
echo "<br />";
print('First name: <input type="text" name="first_name" size="15" />');
echo "<br />";
print('address: <input type="text" name="theaddress" size="15" />');
echo "<br />";
print('City: <input type="text" name="city" size="15" />');
echo "<br />";
print('State: <input type="text" name="state" size="15" />');
echo "<br />";
print('Zip_code: <input type="text" name="zip_code" size="15" />');
echo "<p>";
?>
<input type="submit" value="submit!">
</form>
</body>
</html>
recieving page
<?php
print('Hello ' . $first_name . ' thank you for adding your details and welcome');
echo "<p>";
$link = mysql_connect();
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$databasename='mydatabase';
mysql_select_db($databasename, $link)
or die('Could not connect: ' . mysql_error());
echo "we have now connected";
$lastname = $_POST[last_name];
$firstname = $_POST[first_name];
$theaddress = $_POST[theaddress];
$city = $_POST[city];
$state = $_POST[state];
$zipcode = $_POST[zip_code];
//now inserting the data to addresses table
$query="UPDATE addresses SET last_name='$lastname', theaddress='$theaddress', first_name='$firstname', city='$city', state=$state', zip_code = '$zipcode'";
mysql_query($query, $link);
echo "<p>";
echo "data has been added to database!";
mysql_close($link);
?>
edit - I get actually Gget this as a response
Hello aaron thank you for adding your details and welcome
we have now connected Notice: Use of undefined constant last_name - assumed 'last_name' in c:\phpdev\www\insert.php on line 19 Notice: Undefined index: last_name in c:\phpdev\www\insert.php on line 19 Notice: Use of undefined constant first_name - assumed 'first_name' in c:\phpdev\www\insert.php on line 20 Notice: Use of undefined constant theaddress - assumed 'theaddress' in c:\phpdev\www\insert.php on line 21 Notice: Use of undefined constant city - assumed 'city' in c:\phpdev\www\insert.php on line 22 Notice: Use of undefined constant state - assumed 'state' in c:\phpdev\www\insert.php on line 23 Notice: Use of undefined constant zip_code - assumed 'zip_code' in c:\phpdev\www\insert.php on line 24
data has been added to database!
do i just edit my php.ini file to get ride of some of this?
you should provide mysql_connect() with 3 parameters.
syntax : mysql_connect(server, username, password)
if you're on your local machine something like this would do,
mysql_connect("localhost", "root", "");
when you're using $_POST[] use single quotes ($_POST['variable']) to get rid of those notices. also you don't need to print all html using php. (unless ur doing for leaning purposes) . one more thing, you're trying to UPDATE the database, not INSERT. So you won't have any more than one row in your table.
Oh! and don't try to bring up php.ini for every error msg u get. It's better off that you don't edit it at all from now on, unless its absolutely essential. ;)