كيف أقوم بإصلاح الإشعار: متغير غير محدد: خطأ في C:\xampp\htdocs\new.php على الإنترنت


مرحبًا، أنا مبتدئ في PHP، وأحاول تصميم موقع ويب باستخدام php وphpmyadmin. من المفترض أن يقوم هذا الموقع بعرض جميع السجلات من قاعدة البيانات وحذف السجلات وإضافتها. الكود التالي مخصص لإضافة سجل جديد، لدي أخطاء في السطر 16 و20 و30 و32 و34 و36 و83.

مثال خطأ: ملاحظة: متغير غير محدد: خطأ في C:\xampp\htdocs\New.php في السطر 16 ينطبق الأمر نفسه على الأسطر 20 و30 و32 و34 و36 و83 كما ذكرنا سابقًا.

لقد قمت بتضمين أرقام الأسطر بجانب أسطر التعليمات البرمجية مع وجود الأخطاء (egLine30)

ما الذي يسبب هذه المشاكل وماذا يجب أن أفعل لحلها ؟؟؟

بي أتش بي
	<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 ومواقع على الإنترنت ويوتيوب واستشارة الزملاء.

الحل 1

لم تقم بتعريف المتغير error المشار إليها في السطر 16. تركيب العبارات الأخرى غير صحيح، ينبغي أن يكون كذلك

بي أتش بي
<div>
<!-- note the position of the tag closer (/>) should come before the PHP statement
 -->
ID: * <input type="int" name="ID" /><?php echo $ID; ?> <br>

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

Price:  * <input type="text" name="Price" /><?php echo $Price; ?><br>

Stock:  * <input type="int" name="Stock" /><?php echo $Stock; ?><br>

<p>* required</p>



</div>

コメント

タイトルとURLをコピーしました