<html>
<head>
<title>Incidence Reporting</title>
</head>
<body>
<h2>Incidence Reporting</h2>
<?php
$db_s = "localhost";
$db_u = "bs_72";
$db_p = "tmmd2f";
$db_n = "bs_72";
$co = mysqli_connect($db_s,$db_u,$db_p)
or die('Error connecting to MySQL server.');
mysql_select_db($db_n);
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$e_mail = $_POST['email'];
$when_it_happened = $_POST['whenithappened'];
$phone_number = $_POST['phonenumber'];
$i_description = $_POST['idescription'];
$query = “INSERT INTO las_cruces (first_name, last_name, e_mail, when_it_happened, “ .
“phone_number, i_description) “ .
“VALUES (‘$first_name’, ‘$last_name’,‘$e_mail’, ‘$when_it_happened’ , ‘$phone_number’, “ .
“’$i_description’)”;
$result = mysql_query($co, $query);
or die('Error querying database.');
echo 'Hello, ' . $first_name . ' ' . $last_name . '<br />';
echo 'Thanks for submitting the form.<br />';
echo 'Your email is ' . $e_mail . '<br />';
echo 'Your phone number? ' . $phone_number . '<br />';
echo 'The date of the incidence was ' . $when_it_happened . '<br />';
echo 'What Happened: ' . $i_description . '<br />';
?>
</body>
</html>
<form method="post" action="report.php">
php forms and mysql querying
Page 1 of 14 Replies - 273 Views - Last Post: 16 November 2012 - 01:58 AM
#1
php forms and mysql querying
Posted 15 November 2012 - 02:59 AM
I'm beginning mysql and php, I'm trying to get this php file to add values to a mysql database. The problem is when I run the query I keep getting an error, I'm following what the book I purchased said but all I get is a server cannot be found erro
Replies To: php forms and mysql querying
#2
Re: php forms and mysql querying
Posted 15 November 2012 - 06:19 AM
You seem to be mixing up the MySQLi and MySQL extensions. You connect using MySQLi but then select the database using MySQL.
I suggest you cange the latter. MySQLi is better.
I suggest you cange the latter. MySQLi is better.
#3
Re: php forms and mysql querying
Posted 15 November 2012 - 05:04 PM
<html>
<head>
<title>Incidence Reporting</title>
</head>
<body>
<h2>Incidence Reporting</h2>
<?php
$db_s = "localhost";
$db_u = "bs_72";
$db_p = "tmmd2f";
$db_n = "bs_72";
$co = mysqli_connect($db_s,$db_u,$db_p)
or die('Error connecting to MySQL server.');
mysqli_select_db($db_n);
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$e_mail = $_POST['email'];
$when_it_happened = $_POST['whenithappened'];
$phone_number = $_POST['phonenumber'];
$i_description = $_POST['idescription'];
$query = “INSERT INTO las_cruces (first_name, last_name, e_mail, when_it_happened, “ .
“phone_number, i_description) “ .
“VALUES (‘$first_name’, ‘$last_name’,‘$e_mail’, ‘$when_it_happened’ , ‘$phone_number’, “ .
“’$i_description’)”;
$result = mysqli_query($co, $query);
or die('Error querying database.');
echo 'Hello, ' . $first_name . ' ' . $last_name . '<br />';
echo 'Thanks for submitting the form.<br />';
echo 'Your email is ' . $e_mail . '<br />';
echo 'Your phone number? ' . $phone_number . '<br />';
echo 'The date of the incidence was ' . $when_it_happened . '<br />';
echo 'What Happened: ' . $i_description . '<br />';
?>
</body>
</html>
<form method="post" action="report.php">
<p>Share where you saw the suspicous activity:</p> <form method="post" action="submit.php"> <label for="firstname">First name:</label> <input type="text" id="firstname" name="firstname" /><br /> <label for="lastname">Last name:</label> <input type="text" id="lastname" name="lastname" /><br /> <label for="email">What is your email address?</label> <input type="text" id="email" name="email" /><br /> <label for="whenithappened">When did it happen?</label> <input type="text" id="whenithappened" name="whenithappened" /><br /> <label for="phonenumber">What is your phone number?</label> <input type="text" id="phonenumber" name="phonenumber" /><br /> <label for="idescription">Describe what happened:</label> <input type="text" id="idescription" name="idescription" size="100" /><br /> <input type="submit" value="Report" name="submit" /> </form>
Ok I fixed what you said, but it's still not working, I also included my html form, why isn't working still
#4
Re: php forms and mysql querying
Posted 15 November 2012 - 07:56 PM
Are you still getting a server not found error? Do you see your form at all? Are you testing this on your own machine?
If so, make sure you have php, apache and mysql installed. If you're starting out then it's best to use a collection like XAMPP as it handles a lot of the configuration for you and is well documented.
If you are using an online hosting service, make sure they host with php.
If so, make sure you have php, apache and mysql installed. If you're starting out then it's best to use a collection like XAMPP as it handles a lot of the configuration for you and is well documented.
If you are using an online hosting service, make sure they host with php.
#5
Re: php forms and mysql querying
Posted 16 November 2012 - 01:58 AM
there is no need to use mysqli_select_db(), you can pass the DB name as 4th parameter in mysqli_connect().
while I’m at it: line #28, wrong quote type (hint, strings would appear blue)
while I’m at it: line #28, wrong quote type (hint, strings would appear blue)
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|