Jump to content

Php error Undefined Index


jiameow

Recommended Posts

<?php
include_once "add2.php";
connect();
?>

<?php
if (!isset($_POST['submit'])){

echo "<form method=\"post\" action=\"admin-addservice.php\" name=\"Registration Form\">";
echo "<br/>";
echo 'Name of Service: ' . '<br/>' . '<input type=\"text\" name=\"service\" style="width:400px;"/>' . '<br/>' . '<br/>';
echo "Description: " . "<br/>";
echo '<textarea cols="80" rows="10" name=\"description\" maxlength=\"1000\" style=\"overflow: hidden;\">';
echo '</textarea>' . '<br/>' . '<br/>';
echo "Price: " . '<br/>';
echo "<input type=\"text\" name=\"price\" style='width:200px;'/>" . '<br/>';
echo "<input type=\"submit\" name=\"submit\" value=\"Finish Registration!\" />";
echo "</form>";

?>
<?php

}else {

$service = protect($_POST['service']);
$description = protect($_POST['description']);
$price = protect($_POST['price']);

$errors = array();

Link to comment
Share on other sites

here is our full code

 

 


<?php
include_once "add2.php";
connect();

mysql_connect("localhost","root","");
mysql_select_db("patient");

if (!isset($_POST['submit'])){
echo "<form method=\"post\" action=\"admin-addservice.php\" name=\"Registration Form\">";
echo "<br/>";
echo 'Name of Service: ' . '<br/>' . '<input type=\"text\" name=\"services\" style="width:400px;"/>' . '<br/>' . '<br/>';
echo "Description: " . "<br/>";
//echo '<textarea cols="80" rows="10" name=\"description\" maxlength=\"1000\" style=\"overflow: hidden;\">';
//echo '</textarea>' . '<br/>' . '<br/>';
echo "<input type=\"text\" name=\"\">";
echo "Price: " . '<br/>';
echo "<input type=\"text\" name=\"price\" style='width:200px;'/>" . '<br/>';
echo "<input type=\"submit\" name=\"submit\" value=\"Finish Registration!\" />";
echo "</form>";

}else {

$service = protect($_POST['services']);
$description = protect($_POST['description']);
$price = protect($_POST['price']);

$errors = array();
if(!$service) {
$errors[] = "Invalid Name of Service!";
}
if(!$description) {
$errors[] = "Invalid Description!";
}
if(!$price) {
$errors[] = "Invalid Price!";
}
if (count($errors) > 0) {
foreach($errors AS $error) {
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('$error')
window.location.href='admin-addservice.php'
</SCRIPT>");
}
}
else {
$sql = "INSERT INTO services(services , description , price) VALUES('$_POST[services]' , '$_POST[description]' , '$_POST[price]')";
$res = mysql_query($sql) or die (mysql_error());
?>
<script type=text/javascript>
function show_alert() {
var msg = "Successfully Saved!";
alert(msg);
}
</script>
<?php

echo "<br/>";
echo '<script type="text/javascript"> show_alert(); </script>';
echo "<br/>";
echo "<br/>";
echo "<br/>";

}
}

?>
Link to comment
Share on other sites

Me too.

 

What do you have in the add2.php file?

<?php

 

function protect($string)

{

$string = mysql_real_escape_string($string);

$string = strip_tags($string);

$string = addslashes($string);

 

return $string;

 

}

function connect () {

$con = mysql_connect("localhost", "root",'') or die(mysql_error());

$db = mysql_select_db("patient", $con);

 

}

 

?>

Link to comment
Share on other sites

Ok, then!

 

Put the error_reporting(-1) to the top of the file and tell us what error(s) do you get?

 

Copy/Paste my script!

 

Ops....there is no return $con in connect() function inside the add2.php file!

 

 

 

 
function connect () {
$con = mysql_connect("localhost", "root",'') or die(mysql_error());
$db = mysql_select_db("patient", $con);
return $con;
}

 

<?php
error_reporting(-1);
include_once "add2.php";
connect();

if (!isset($_POST['submit'])){
echo "<form method=\"post\" action=\"admin-addservice.php\" name=\"Registration Form\">";
echo "<br/>";
echo 'Name of Service: ' . '<br/>' . '<input type=\"text\" name=\"services\" style="width:400px;"/>' . '<br/>' . '<br/>';
echo "Description: " . "<br/>";
//echo '<textarea cols="80" rows="10" name=\"description\" maxlength=\"1000\" style=\"overflow: hidden;\">';
//echo '</textarea>' . '<br/>' . '<br/>';
echo "<input type=\"text\" name=\"\">";
echo "Price: " . '<br/>';
echo "<input type=\"text\" name=\"price\" style='width:200px;'/>" . '<br/>';
echo "<input type=\"submit\" name=\"submit\" value=\"Finish Registration!\" />";
echo "</form>";

}else {

$service = protect($_POST['services']);
$description = protect($_POST['description']);
$price = protect($_POST['price']);

$errors = array();
if(!$service) {
$errors[] = "Invalid Name of Service!";
}
if(!$description) {
$errors[] = "Invalid Description!";
}
if(!$price) {
$errors[] = "Invalid Price!";
}
if (count($errors) > 0) {
foreach($errors AS $error) {
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('$error')
window.location.href='admin-addservice.php'
</SCRIPT>");
}
}
else {
$sql = "INSERT INTO services(services , description , price) VALUES('$_POST[services]' , '$_POST[description]' , '$_POST[price]')";
$res = mysql_query($sql) or die (mysql_error());
?>
<script type="text/javascript">
function show_alert() {
var msg = "Successfully Saved!";
alert(msg);
}
</script>
<?php

echo "<br/>";
echo '<script type="text/javascript"> show_alert(); </script>';
echo "<br/>";
echo "<br/>";
echo "<br/>";

}
}
Edited by jazzman1
Link to comment
Share on other sites

 

Ok, then!

 

Put the error_reporting(-1) to the top of the file and tell us what error(s) do you get?

 

Copy/Paste my script!

 

<?php
error_reporting(-1);
include_once "add2.php";
connect();

if (!isset($_POST['submit'])){
echo "<form method=\"post\" action=\"admin-addservice.php\" name=\"Registration Form\">";
echo "<br/>";
echo 'Name of Service: ' . '<br/>' . '<input type=\"text\" name=\"services\" style="width:400px;"/>' . '<br/>' . '<br/>';
echo "Description: " . "<br/>";
//echo '<textarea cols="80" rows="10" name=\"description\" maxlength=\"1000\" style=\"overflow: hidden;\">';
//echo '</textarea>' . '<br/>' . '<br/>';
echo "<input type=\"text\" name=\"\">";
echo "Price: " . '<br/>';
echo "<input type=\"text\" name=\"price\" style='width:200px;'/>" . '<br/>';
echo "<input type=\"submit\" name=\"submit\" value=\"Finish Registration!\" />";
echo "</form>";

}else {

$service = protect($_POST['services']);
$description = protect($_POST['description']);
$price = protect($_POST['price']);

$errors = array();
if(!$service) {
$errors[] = "Invalid Name of Service!";
}
if(!$description) {
$errors[] = "Invalid Description!";
}
if(!$price) {
$errors[] = "Invalid Price!";
}
if (count($errors) > 0) {
foreach($errors AS $error) {
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('$error')
window.location.href='admin-addservice.php'
</SCRIPT>");
}
}
else {
$sql = "INSERT INTO services(services , description , price) VALUES('$_POST[services]' , '$_POST[description]' , '$_POST[price]')";
$res = mysql_query($sql) or die (mysql_error());
?>
<script type="text/javascript">
function show_alert() {
var msg = "Successfully Saved!";
alert(msg);
}
</script>
<?php

echo "<br/>";
echo '<script type="text/javascript"> show_alert(); </script>';
echo "<br/>";
echo "<br/>";
echo "<br/>";

}
}

invalid name of service!

 

"Undefined index: service D:\xampp\htdocs\def\admin-addservice.php on line 93

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.