jiameow Posted March 15, 2013 Share Posted March 15, 2013 I was wondering how can you solve this type of error "undefined index? please answer Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/ Share on other sites More sharing options...
jazzman1 Posted March 15, 2013 Share Posted March 15, 2013 When you defined it Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418853 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 how do you do that? I can't understand it :x Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418855 Share on other sites More sharing options...
requinix Posted March 15, 2013 Share Posted March 15, 2013 Here's a how-to for using a great resource to solve this kind of problem. Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418856 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 we can't seem to make it work Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418858 Share on other sites More sharing options...
Maq Posted March 15, 2013 Share Posted March 15, 2013 POST YOUR CODE. Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418861 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 <?phpinclude_once "add2.php";connect();?><?phpif (!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 https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418870 Share on other sites More sharing options...
jazzman1 Posted March 15, 2013 Share Posted March 15, 2013 Where do you declare the protect function in that script? Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418877 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 in our else statement Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418878 Share on other sites More sharing options...
jazzman1 Posted March 15, 2013 Share Posted March 15, 2013 On 3/15/2013 at 8:46 PM, jiameow said: in our else statement No, that's wrong! Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418879 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 where should we put it then? Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418880 Share on other sites More sharing options...
jazzman1 Posted March 15, 2013 Share Posted March 15, 2013 You need to create that function before to use it. Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418881 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 here is our full code <?phpinclude_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><?phpecho "<br/>";echo '<script type="text/javascript"> show_alert(); </script>';echo "<br/>";echo "<br/>";echo "<br/>";}}?> Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418882 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 we dont have any knowledge about php so far :/ Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418883 Share on other sites More sharing options...
jazzman1 Posted March 15, 2013 Share Posted March 15, 2013 On 3/15/2013 at 8:54 PM, jiameow said: we dont have any knowledge about php so far :/ Me too. What do you have in the add2.php file? Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418886 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 it holds the protect function and connection Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418887 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 On 3/15/2013 at 8:58 PM, jazzman1 said: 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 https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418888 Share on other sites More sharing options...
jazzman1 Posted March 15, 2013 Share Posted March 15, 2013 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/>"; } } Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418889 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 On 3/15/2013 at 9:07 PM, jazzman1 said: 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 https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418892 Share on other sites More sharing options...
jazzman1 Posted March 15, 2013 Share Posted March 15, 2013 Which is the line 93? Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418894 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 On 3/15/2013 at 9:18 PM, jazzman1 said: Which is the line 93? $service = protect($_POST['services']); Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418896 Share on other sites More sharing options...
jazzman1 Posted March 15, 2013 Share Posted March 15, 2013 There is only 63 rows inside that particular file Are you sure that that file is called - admin-addservice.php? Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418897 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 yes Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418898 Share on other sites More sharing options...
jazzman1 Posted March 15, 2013 Share Posted March 15, 2013 And.... you posted the entire script? Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418899 Share on other sites More sharing options...
jiameow Posted March 15, 2013 Author Share Posted March 15, 2013 yup the entire php script Link to comment https://forums.phpfreaks.com/topic/275705-php-error-undefined-index/#findComment-1418901 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.