Hi guys i have a small problem to do with sql/php im trying to add a basic form so i can add info into a database ive created in sql please help me figure out where im going wrong Any help will be greatly appreciated!!! heres thee code
Page 1 -getfunction2.php
<html>
<body style="background-color:black">
<center>
<u>
<p style="font family:segoe script; Color:red; font-size:25px;">Welcome to my database, I hope you find this usefull!</p>
</u>
<br>
<form action="welcome.php" method="get">
<font color="#cccccc">
<font face='segoe script'='7'>
<Center>
<p>
Contact search
</p>
<input type='text' size='50' name='search'>
<input type='submit' name='submit' value='search'>
<html>
<body style="background-color:black">
<center>
<p style="font family:segoe script; Color:red; font-size:25px;">Join our database</p>
</body>
</html>
<br>
<form action="insert2.php" method="post">
<font color="#cccccc">
<font face='segoe script'='4'>
Name
<input type='text' size='50' name='name'>
<br>
Mobile number
<input type='text' size='50' name='mobile number'>
<br>
Email Address
<input type='text' size='50' name='email address'>
<br>
Postcode
<input type='text' size='50' name='postcode'>
<br>
<input type='submit' name='mobile number' value='add'>
</body>
</html>
Page 2 welcome.php
<?php
//get data
$button= $_GET['submit'];
$search= $_GET['search'];
if (!$button)
echo "You havent entered anything";
else
echo "You searched for $search <hr size='7'>";
//connect to our database
$connection= mysql_connect("localhost","root","");
$db_selected=mysql_select_db("work",$connection);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
} else {
echo "Database Found";
}
$sql = "SELECT * from `contact list` where name like '%$search%';";
echo "<br>" .$sql . "<br>";
$result = mysql_query($sql, $connection);
print_r($result);
while ($row=mysql_fetch_assoc($result))
{
print_r($row);
}
?>
Page 3 - insert2.php
<html>
<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('could not connect: ' . mysql_error());
}
mysql_select_db("work", $con);
$sql="INSERT INTO database (name, mobile number, email address,postcode)
VALUES
('$_POST[name]','$_POST[mobile number]','$_POST[email address]','$_POST[postcode]')";
if (!mysql_query($sql,$con))
{
die(@error: ' . mysql_error());
}
echo"1 record added";
mysql_close($con)
?>
</body>
</html>
begginer programmer needs help
Moderator: General Moderators
Re: begginer programmer needs help
It would be helpful if you told us which part of the code in particular you're having trouble with; error messages, etc.
Re: begginer programmer needs help
oh sorry um when i try to add info into the database and hit the form submit button it come s back with - Notice: Undefined index: submit in C:\wamp\www\tutorial02\welcome.php on line 4
You havent entered anythingDatabase Found
I need it to add info into the database THANKS !
You havent entered anythingDatabase Found
I need it to add info into the database THANKS !
Re: begginer programmer needs help
Welcome.php is using GET for forms and your database is trying to read POST from it.