Jump to content

[SOLVED] PHP/SQL


mbrown

Recommended Posts

I have an issue that when I want to modify the database information in the table.

 

modification.php is the main modification file that sends the information to the modification2 file that actually edits the information in the db.

 

the only thing that will not change is the checked and paid

 

thanks

 

mbrown

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/137954-solved-phpsql/
Share on other sites

modification.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Modification</title>

<link href="css/style.css" rel="stylesheet" type="text/css" />

</head>



<body>

<?php

include "dbconnect.php";



//Query

$Query	=	"SELECT * FROM jos_signup";



$Display = mysqli_query ($db, $Query) or die("<p>Unable to execute the query.</p>" . "<p>Error Code</p>" . mysqli_errno($db) . ": " . mysqli_error($db) . "</p>");



$mike = mysqli_fetch_assoc($Display);



	echo "<form action='modification2.php' method='post'>";

	echo "<table border='5' align='center' width = '100%'>\n

				<tr>

					<th>chan?</th>

					<th>Date</th>

					<th>ID</th>

					<th>First Name</th>

					<th>Last Name</th>

					<th>Address</th>

					<th>Address 1</th>

					<th>City</th>

					<th>State</th>

					<th>Zip Code</th>

					<th>Phone</th>

					<th>E-mail</th>

					<th>People</th>

					<th>Guest Name</th>

					<th>Checked In</th>

					<th>Paid</th>

				</tr>";

			echo "\n";



	//counter variable

	$count = 0;

	$number = mysqli_num_rows(mysqli_query ($db,$Query));



		if ($number <= 0)

		{

			echo "<tr><td colspan='16' align='center'>There are no records in here that meet your criteria</td></tr>";

		}//end of else if ($number <= 0)



		else

		{



	while ($mike)

	{

		echo "

			<tr>\n

			<td><input type = 'checkbox' name = 'changed$count' size ='1''></td>

			<td><input type = 'text' name = 'Date$count' value ='$mike[Date]' readonly=readonly size='20'></td>\n

			<td><input type = 'text' name = 'ID$count' value ='$mike[iD]' readonly=readonly size = '5'></td>\n

			<td><input type = 'text' name = 'First_Name$count' value ='$mike[First_Name]' size = '10' maxsize = '10'</td>\n

			<td><input type = 'text' name = 'Last_Name$count' value ='$mike[Last_Name]' size = '10'</td>\n

			<td><input type = 'text' name = 'Address$count' value ='$mike[Address]' size = '20'</td>\n

			<td><input type = 'text' name = 'Address1$count' value ='$mike[Address1]' size = '10'</td>\n

			<td><input type = 'text' name = 'City$count' value ='$mike[City]' size = '10'</td>\n

			<td><input type = 'text' name = 'State$count' value ='$mike[state]' size '2' maxsize = '2'</td>\n

			<td><input type = 'text' name = 'Zipcode$count' value ='$mike[Zipcode]' size ='10'</td>\n

			<td><input type = 'text' name = 'Phone$count' value ='$mike[Phone]' size = '10'</td>\n

			<td><input type = 'text' name = 'Email$count' value ='$mike[Email]' size ='20'</td>\n

			<td><input type = 'text' name = 'People$count' value ='$mike[People]'size ='1'</td>\n

			<td><input type = 'text' name = 'Guest_Name$count' value ='$mike[Guest_Name]'size ='20'</td>\n

			<td><input type = 'text' name = 'Checked$count' value ='$mike[Checked]'size ='1'</td>\n

			<td><input type = 'text' name = 'Paid$count' value ='$mike[Paid]'size ='1'</td>\n";

	/*	echo "<td>";

			$StudyArray = explode(",", $mike[study]);

			foreach($StudyArray as $Study)

			{

				echo "<input type = 'text' name = 'study$count' value ='$Study'<br /> ";

			}//emd of foreach($StudyArray as $Study)



		echo "</td>\n";*/

		echo "</tr>\n";



		//goes through for each record

		$mike = mysqli_fetch_assoc($Display); 

		$count++;

	}//end of while ($mike)

	}//end of else

	echo "Total recrods: $count";



	echo "<tr><td colspan = '16'<input type = 'submit' ></td></tr>";

	echo "<input type = 'hidden' name = 'count' value = $count>";

	echo "</table>";

	echo "</form>";



?>

</body>

</html>

 

modification2.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Modification</title>

<link href="css/style.css" rel="stylesheet" type="text/css" />

</head>



<body>

<?php



function validatePhoneNo($phone)

{

  if(ereg('^[2-9]{1}[0-9]{2}-[0-9]{3}-[0-9]{4}$', $phone))

	 return true;

  else

	 return false;

}



function validateUSAZip($zipcode)

{

  if(preg_match("/^([0-9]{5})(-[0-9]{4})?$/i",$zipcode))

	return true;

  else

	return false;

}





include "dbconnect.php";



//variables

	$count = $_POST['count'];

	$numUpdated =0;

	$num = 0;

	//echo $count;

	while ($num < $count)

	{

		$checkbox = $_POST["changed$num"];

		if($checkbox)

		{

			//variables

			$date		=	$_POST["Date$num"];

			$id 		=	$_POST["ID$num"];

			$First_Name	=	$_POST["First_Name$num"];

			$Last_Name	=	$_POST["Last_Name$num"];

			$Address	=	$_POST["Address$num"];

			$Address1	=	$_POST["Address1$num"];

			$City		=	$_POST["City$num"];

			$State		=	$_POST["State$num"];

			$ZipCode	=	$_POST["Zipcode$num"];

			$Phone		=	$_POST["Phone$num"];

			$Email		=	$_POST["Email$num"];

			$numPeople	=	$_POST["People$num"];

			$Guest_Name	=	$_POST["Guest_Name$num"];

			$Checked	=	$_POST["Checked$num"];

			$Paid		=	$_POST["Paid$num"];



			$error		=	"";





			if (strlen($First_Name) < 1 || strlen($First_Name) > 40)

			{

				$error .=	"Please enter a first name between 5 and 40 characters <br />";

			}		



			if (strlen($Last_Name) < 5 || strlen($Last_Name) > 40)

			{

				$error .= "Please enter a last name between 5 and 40 characters <br />";

			}



			if (strlen($Address) < 10)

			{

				$error .= "Please enter a address longer than 10 characters <br />";

			}



			if ($Address == "")

			{

				if ($Address1 != "")

				{

					$error .= "Please enter something in the first address box <br />";

				}

			}



			if (strlen($City) < 5)

			{

				$error .= "Please enter a city longer city name <br />";

			}



			if (strlen($State) != 2)

			{

				$error .= "Please only enter the abbrivation for the state <br />";

			}



			if (!validateUSAZip($ZipCode))

			{

				$error .= "Please enter a valid zip code<br />";

			}



			if (!validatePhoneNo($Phone))

			{

				$error .= "Please enter your phone number (xxx-xxx-xxxx)<br />";

			}



			if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email))

			{

				$error .= "<br />Please enter a valid e-mail address";

			}



			if ($numPeople != 2)

			{

				if ($Guest_Name != "")

				{

					$error .= "<br />Please indicate 2 people attending";

				}//end of if ($Guest_Name != "")

			}//end of if ($numPeople != 2)



			if ($Checked = "x")

			{

				$Checked = "X";

			}



			if ($Paid = "x")

			{

				$Paid = "X";

			}





			if ($error)

			{

				echo "<div align='center' class='error'><h3>We have some issues with your submission</h3> $error<br /><br />Please go back to the <a href='modification.php'>modification page</a> to modify the entries.</div>";

			}//end of if ($error)

			else

			{

				//update table

				$SQL = "UPDATE  jos_signup SET ";

				$SQL .= "Date = '$date', ";

				$SQL .= "First_Name = '$First_Name', ";

				$SQL .= "Last_Name = '$Last_Name', ";

				$SQL .= "Address = '$Address', ";

				$SQL .= "Address1 = '$Address1', ";

				$SQL .= "City = '$City', ";

				$SQL .= "State = '$State', ";

				$SQL .= "Zipcode = '$ZipCode', ";

				$SQL .= "Phone = '$Phone', ";

				$SQL .= "Email = '$Email', ";

				$SQL .= "People = '$numPeople', ";

				$SQL .= "Guest_Name = '$Guest_Name', ";

				$SQL .= "Checked = '$Checked', ";

				$SQL .= "Paid = '$Paid'";

				$SQL .= " WHERE ID = '$id'";



				$r = mysqli_query($db,$SQL) or die(mysqli_error($db));

			 $numUpdated++;		

			}//end of else

		}//end of if($checkbox)

			$num++;

	}//end of while ($num < $count)

	echo "<br />";

	echo $SQL;

	echo " <div class='error'>You updated:  $numUpdated record(s)";

	echo "<br />";

	echo "Please go back to the <a href='getalldata.php'>overview page</a></div>";

	mysqli_close($db);



?>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/137954-solved-phpsql/#findComment-721352
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.