我如何修复通知:未定义的变量:C:\ xampp \htdocs \ new.php中的错误在线 [英] How do I fix notice: undefined variable: error in C:\xampp\htdocs\new.php on line

查看:278
本文介绍了我如何修复通知:未定义的变量:C:\ xampp \htdocs \ new.php中的错误在线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我是PHP的初学者,我正在尝试使用php和phpmyadmin设计一个网站。本网站应该查看数据库中的所有记录,删除和添加记录。以下代码用于添加新记录,我在第16,20,30,32,34,36和83行有错误。



错误示例:注意:未定义的变量:第16行的C:\ xampp \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ,32,34,36和83.



我在错误代码行旁边包含行号(例如,Line30)



造成这些问题的原因是什么以及解决这些问题需要做什么?









Hi there I am a beginner of PHP, I am attempting to design a website using php and phpmyadmin. This website is supposed to view all records from a database, delete and add records.The following code is for adding a new record, I have errors on line 16, 20, 30, 32, 34, 36 and 83.

Error Example: Notice: Undefined variable: error in C:\xampp\htdocs\New.php on line 16 the same applies to as mentioned previously, lines 20, 30, 32, 34, 36 and 83.

I have included the line numbers next to the lines of code with the errors (e.g.Line30)

What is causing these problems and what do I need to do to resolve them ???




	<title>New Record

	

	

	<?php

	// if there are any errors, display them

	(Line16)if ($error != '');

	{

	(Line20)echo '<div style="padding: 4px; color: red">'.$error.'</div>';
//if assist
	}

	?>

	

	<div>
       
	(Line30)ID: * <input type="int" name="ID"<?php echo $ID; ?> /><br>

	(Line32)ProductName: * <input type="VARCHAR" name="ProductName"<?php echo $ProductName; ?> /><br>

	(Line34)Price:  * <input type="text" name="Price"<?php echo $Price; ?> /><br>
	
	(Line36)Stock:  * <input type="int" name="Stock"<?php echo $Stock; ?> /><br>

	<p>* required</p>

	

	</div>

	

	

	

	<?php

	

	//connect to database
		 $con = mysqli_connect("localhost","root","");
		 if (!$con) 
		 {
			 mysqli_select_db("stationaryonlinecustomers", $con);
		 }


	
	// check if the form has been submitted. If it has, start to process the form and save it to the database

	if (isset($_POST['submit']))

	{

	// get form data, making sure it is valid

	$ID = mysql_real_escape_string(htmlspecialchars($_POST['ID']));

	$ProductName = mysql_real_escape_string(htmlspecialchars($_POST['ProductName']));

    $Price = mysql_real_escape_string(htmlspecialchars($_POST['Price']));
       
    $Stock = mysql_real_escape_string(htmlspecialchars($_POST['Stock']));
      
	}

	// check to make sure both fields are entered

	(Line 83)if ($ID == '' || $ProductName == '' || $Price == '' || $Stock =='')

	{

	// generate error message

	$error = 'ERROR: Please fill in all required fields!';
	
	}

	else{
	// save the data to the database

	$u = mysql_query($con, "INSERT productorders SET ID='".$ID."', ProductName='".$ProductName."', Price='".$Price."', Stock='".$Stock."'");
	

	// once saved, redirect back to the view page

	header("location:View.php");

	

	

	// if the form hasn't been submitted, display the form

	renderForm('','','');

	}

	?>





我尝试过:



PHP书籍,在线网站,youtube和咨询同事。



What I have tried:

PHP books, Online websites, youtube and consulting fellow colleagues.

推荐答案

error!= ' ');

{

(第20行)echo ' < div style =padding:4px; color:red>'
error != ''); { (Line20)echo '<div style="padding: 4px; color: red">'.


error。' < / DIV>';
// 如果协助
}

< span class =code-pagedirective>?>




< div >

(第30行) ID:* < 输入 type = int 名称 = ID <?php echo
error.'</div>'; //if assist } ?> <div> (Line30)ID: * <input type="int" name="ID"<?php echo


ID; > /> < br >

(第32行)产品名称:* < 输入 type = VARCHAR 名称 = ProductName <?php echo
ID; ?> /><br> (Line32)ProductName: * <input type="VARCHAR" name="ProductName"<?php echo


这篇关于我如何修复通知:未定义的变量:C:\ xampp \htdocs \ new.php中的错误在线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆