jiameow
-
Posts
19 -
Joined
-
Last visited
Posts posted by jiameow
-
-
Ok , and now:
echo "<input type=\"submit\" name=\"submit\" value=\"Finish Registration!\" />"; echo "</form>"; }else { // here echo '<pre>'.print_r($_POST['services'], true).'</pre>'; exit; $service = protect($_POST['services']);
still the same :/
-
still the same error
-
Sorry, it should be only:
echo __FILE__;
D:\xampp\htdocs\def\admin-addservices.php
-
Put it this on the top of that script and give me the path name:
EDIT: I am going to smoke
echo realpath(dirname(__FILE__));
D:\xampp\htdocs\def
-
yup the entire php script
-
-
Which is the line 93?
$service = protect($_POST['services']);
-
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
-
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);
}
?>
-
it holds the protect function and connection
-
we dont have any knowledge about php so far :/
-
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/>";
}
}
?> -
where should we put it then?
-
in our else statement
-
<?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(); -
we can't seem to make it work
-
how do you do that? I can't understand it :x
-
I was wondering how can you solve this type of error "undefined index? please answer
Php error Undefined Index
in PHP Coding Help
Posted
thanks for your help we already solved it.. thanks alot for your kindness