update database script stopped working

Hi Astoneciper, i’m using notepad++ but I’m new to this so I cannot easily see my error/s - can you put me out of my misery please?

Debugging is an important part of programming. Go through the code and match up your brackets.

Hi AstoneCipher, appreciate your advice… I am trying to debug, my code at the minute is
[php]<?php

include(’…/…/includes/mysqli_connect.php’);
// check if update ‘id’ has been passed
if(isset($_GET[‘u’])) {
}

// if form submitted
if (isset($_POST[“pro”])) {
// validate the form data
$date = $_POST[‘date’];
$project = $_POST[‘project’];
$client = $_POST[‘client’];
$hot = $_POST[‘hot’];
$cold = $_POST[‘cold’];
$value = $_POST[‘value’];
$category = $_POST[‘category’];
$order_no = $_POST[‘order_no’];
$del = $_POST[‘del’];
$estimate = $_POST[‘estimate’];
$salesman = $_POST[‘salesman’];
$design = $_POST[‘design’];
$retention = $_POST[‘retention’];
$payment = $_POST[‘payment’];
$site_adr_1 = $_POST[‘site_adr_1’];
$site_Contact = $_POST[‘site_contact’];
$execution = $_POST[‘execution’];
$spec = $_POST[‘spec’];
$cold_rolled = $_POST[‘cold_rolled’];
$hd_bolts = $_POST[‘hd_bolts’];
$site_fixings = $_POST[‘site_fixings’];
$bought_outs = $_POST[‘bought_outs’];
$mpi = $_POST[‘mpi’];
$butt = $_POST[‘butt’];
$pressings = $_POST[‘pressings’];
$rollings = $_POST[‘rollings’];
$paint = $_POST[‘paint’];
$treatment = $_POST[‘treatment’];
$identification = $_POST[‘identification’];
$fi_steel = $_POST[‘fi_steel’];
$fi_fittings = $_POST[‘fi_fittings’];
$notes = $_POST[‘notes’];
$live = $_POST[‘live’];
$draughtsman = $_POST[‘draughtsman’];
$lifting_st = $_POST[‘lifting_st’];
$rwc_review = $_POST[‘rwc_review’];
$client_id = $_POST[‘client_id’];
$client_proj_no = $_POST[‘client_proj_no’];
$dsn_Codes = $_POST[‘dsn_codes’];
$wps = $_POST[‘wps’];

// if ! valid
$errormessage = “”;
if (empty($project)) $errormessage .= "


×Close
Error! Project name is missing.
";
     //  Now POST values are loaded and validated. If there are no errors process the data...
     if ($errormessage=="");  } 

else {
echo $errormessage ; }

else {
// call database
$stmt = $mysqli->prepare(“UPDATE fms_tbl_projects set date = ?,project = ?,client = ?,hot = ?,cold = ?,value = ?,category = ?,order_no = ?,del = ?,estimate = ?,salesman = ?,design = ?,retention = ?,payment = ?,site_adr_1 = ?,site_Contact = ?,execution = ?,spec = ?,cold_rolled = ?,hd_bolts = ?,site_fixings = ?,bought_outs = ?,mpi = ?,butt = ?,pressings = ?,rollings = ?,paint = ?,treatment = ?,identification = ?,fi_steel = ?,fi_fittings = ?,notes = ?,live = ?,draughtsman = ?,lifting_st = ?,rwc_review = ?, client_id = ?, dsn_codes = ?, wps = ? WHERE client_proj_no = ?”);
$stmt->bind_param(‘ssssssssssssssssssssssssssssssssssssssss’, $date,$project,$client,$hot,$cold,$value,$category,$order_no,$del,$estimate,$salesman,$design,$retention,$payment,$site_adr_1,$site_Contact,$execution,$spec,$cold_rolled,$hd_bolts,$site_fixings,$bought_outs,$mpi,$butt,$pressings,$rollings,$paint,$treatment,$identification,$fi_steel,$fi_fittings,$notes,$live,$draughtsman,$lifting_st,$rwc_review, $client_id, $dsn_codes, $wps, $client_proj_no);
}

// if call successful
if($stmt->execute()) {
// redirect
echo “”; }

else {
// inform user
echo “"; }

else {
// Get stored form data.
// Display update form, pre-populated with the stored data
$res = $mysqli->query(“SELECT * FROM fms_tbl_projects WHERE client_proj_no=”.$_GET[‘u’]);
$row = $res->fetch_assoc(); }

?>[/php]

I’ve narrowed it down (or I think I have) to the following snippet
[php] // Now POST values are loaded and validated. If there are no errors process the data…
if ($errormessage==""); } [/php]

Also, in Notepad++, it shows a line between brackets and div’s, etc. Very easy to look down them to
find where a bracket is out of place…

I am losing the will, I’ve been trying to debug my error all day (its 4:30pm over here) I’ve changed my code again to learn the process, I’ve cross checked the syntax with no errors but the html page stops at the start of my code.

ErnieAlex you mentioned that notepad++ shows a line, I am not seeing this line?

All I can really say is turn error reporting on and start correcting them. That would be a good start.

Well, select VIEW, then SHOW-SYMBOL, then select SHOW-INDENT-GUIDE…

Then, when you create a section of code, press the TAB to INDENT them correctly. SO, if you have, let’s say
an IF clause, like this…
if (something) {
do some code
} else {
do something else
}
You would use TAB on the DO SOME CODE parts. This would show you a line from the IF to }else{ and to
the ending brace }… Easy to follow it that way, just look down the lines to see where it ends… Same for
DIV’s inside of HTML and if’s, for’s, while’s, etc in the code. If there is a “NESTED” IF clause, you indent the
entire IF clause that is inside the previous IF clause. This would looks loosely like this:
if (something) {
if (something else) {
do some code for the inside IF…
} else {
do some alternative other code for the insde IF…
}
continue with other code for the first outside IF…
} else {
do alternative code for the outside IF…
}
As you can see, especially in NOTEPAD++ as there would be lines to follow down, it is easy to read in this
manner. All “NESTED” functions are easy to find and to make sure they end correctly…

One big issue in PHP programming is not closing the functions correctly. Even experienced programmers
have this same issue. It is hard to see a missing or missing ending brace }… Might help you…

I use Webuilder IDE. It highlights the tag of the one missing. Cant miss it.

I was just trying to help him with his current editor… Have heard many here mention Webuilder IDE.
Is it free and what is the URL for it. (I do not want it for me, just that Dan or others might be interested…)

http://www.webuilderapp.com/

Thanks for everyone’s input, it is appreciated. I am trying to understand and learn this new (to me) method, I’ve gone back to try and understand the process correctly. Using Astoneciphers example… I have tweaked mine to suit but I still get a blank page but I assume it around the [php] if (empty($project)) { [/php] line. I am getting closer or further away???

[php] if(isset($_GET[‘u’])) {
}

if (isset($_POST[“pro”])) {
$date = $_POST[‘date’];
$project = $_POST[‘project’];
$client = $_POST[‘client’];
$hot = $_POST[‘hot’];
$cold = $_POST[‘cold’];
$value = $_POST[‘value’];
$category = $_POST[‘category’];
$order_no = $_POST[‘order_no’];
$del = $_POST[‘del’];
$estimate = $_POST[‘estimate’];
$salesman = $_POST[‘salesman’];
$design = $_POST[‘design’];
$retention = $_POST[‘retention’];
$payment = $_POST[‘payment’];
$site_adr_1 = $_POST[‘site_adr_1’];
$site_Contact = $_POST[‘site_contact’];
$execution = $_POST[‘execution’];
$spec = $_POST[‘spec’];
$cold_rolled = $_POST[‘cold_rolled’];
$hd_bolts = $_POST[‘hd_bolts’];
$site_fixings = $_POST[‘site_fixings’];
$bought_outs = $_POST[‘bought_outs’];
$mpi = $_POST[‘mpi’];
$butt = $_POST[‘butt’];
$pressings = $_POST[‘pressings’];
$rollings = $_POST[‘rollings’];
$paint = $_POST[‘paint’];
$treatment = $_POST[‘treatment’];
$identification = $_POST[‘identification’];
$fi_steel = $_POST[‘fi_steel’];
$fi_fittings = $_POST[‘fi_fittings’];
$notes = $_POST[‘notes’];
$live = $_POST[‘live’];
$draughtsman = $_POST[‘draughtsman’];
$lifting_st = $_POST[‘lifting_st’];
$rwc_review = $_POST[‘rwc_review’];
$client_id = $_POST[‘client_id’];
$client_proj_no = $_POST[‘client_proj_no’];
$dsn_Codes = $_POST[‘dsn_codes’];
$wps = $_POST[‘wps’];

	// if not valid return errors to form...
    if (empty($project)) { 
		echo "<div class='alert alert-success alert-dismissible' role='alert'>
		<button type='button' class='close' data-dismiss='alert'><span aria-hidden='true'>&times;</span><span class='sr-only'>Close</span></button>
		<strong>Error!</strong> Project name is missing.
		</div>";

	
	} else {
	// call database...
		$stmt = $mysqli->prepare("UPDATE fms_tbl_projects  set date = ?,project = ?,client = ?,hot = ?,cold = ?,value = ?,category = ?,order_no = ?,del = ?,estimate = ?,salesman = ?,design = ?,retention = ?,payment = ?,site_adr_1 = ?,site_Contact = ?,execution = ?,spec = ?,cold_rolled = ?,hd_bolts = ?,site_fixings = ?,bought_outs = ?,mpi = ?,butt = ?,pressings = ?,rollings = ?,paint = ?,treatment = ?,identification = ?,fi_steel = ?,fi_fittings = ?,notes = ?,live = ?,draughtsman = ?,lifting_st = ?,rwc_review = ?, client_id = ?, dsn_codes = ?, wps = ? WHERE client_proj_no = ?");
		$stmt->bind_param('ssssssssssssssssssssssssssssssssssssssss', $date,$project,$client,$hot,$cold,$value,$category,$order_no,$del,$estimate,$salesman,$design,$retention,$payment,$site_adr_1,$site_Contact,$execution,$spec,$cold_rolled,$hd_bolts,$site_fixings,$bought_outs,$mpi,$butt,$pressings,$rollings,$paint,$treatment,$identification,$fi_steel,$fi_fittings,$notes,$live,$draughtsman,$lifting_st,$rwc_review, $client_id, $dsn_codes, $wps, $client_proj_no);
	
	
	// if successful redirect user to index page...
	if($stmt->execute()) {
		echo "<script>location.href='index.php'</script>";


	} else {
		// if the database was not updated then inform user
		echo "<script>alert('".$stmt->error."')</script>";

	}

} else {
// get stored form data.
// display update form, pre-populated with the stored data.
$res = $mysqli->query(“SELECT * FROM fms_tbl_projects WHERE client_id= AND client_proj_no=”.$_GET[‘u’]);
$row = $res->fetch_assoc();

} [/php]

nearly there… :wink:

my code is currently this;-
[php]<?php

include('../../includes/mysqli_connect.php');

if (mysqli_connect_errno($db)) {
trigger_error('Database connection failed: '  . mysqli_connect_error(), E_USER_ERROR);

}

// check ‘id’ value is set
if(isset($_GET[‘u’])) {
}

// check all our variables are set
if (isset($_POST[“pro”]))
{
// assign the value of POST field to a variable
$date = $_POST[‘date’];
$project = $_POST[‘project’];
$client = $_POST[‘client’];
$hot = $_POST[‘hot’];
$cold = $_POST[‘cold’];
$value = $_POST[‘value’];
$category = $_POST[‘category’];
$order_no = $_POST[‘order_no’];
$del = $_POST[‘del’];
$estimate = $_POST[‘estimate’];
$salesman = $_POST[‘salesman’];
$design = $_POST[‘design’];
$retention = $_POST[‘retention’];
$payment = $_POST[‘payment’];
$site_adr_1 = $_POST[‘site_adr_1’];
$site_Contact = $_POST[‘site_contact’];
$execution = $_POST[‘execution’];
$spec = $_POST[‘spec’];
$cold_rolled = $_POST[‘cold_rolled’];
$hd_bolts = $_POST[‘hd_bolts’];
$site_fixings = $_POST[‘site_fixings’];
$bought_outs = $_POST[‘bought_outs’];
$mpi = $_POST[‘mpi’];
$butt = $_POST[‘butt’];
$pressings = $_POST[‘pressings’];
$rollings = $_POST[‘rollings’];
$paint = $_POST[‘paint’];
$treatment = $_POST[‘treatment’];
$identification = $_POST[‘identification’];
$fi_steel = $_POST[‘fi_steel’];
$fi_fittings = $_POST[‘fi_fittings’];
$notes = $_POST[‘notes’];
$live = $_POST[‘live’];
$draughtsman = $_POST[‘draughtsman’];
$lifting_st = $_POST[‘lifting_st’];
$rwc_review = $_POST[‘rwc_review’];
$client_id = $_POST[‘client_id’];
$client_proj_no = $_POST[‘client_proj_no’];
$dsn_Codes = $_POST[‘dsn_codes’];
$wps = $_POST[‘wps’];
}

// if not valid return errors to form...
     if (empty($project)) { 
		echo "<div class='alert alert-success alert-dismissible' role='alert'>
		<button type='button' class='close' data-dismiss='alert'><span aria-hidden='true'>&times;</span><span class='sr-only'>Close</span></button>
		<strong>Error!</strong> Project name is missing.
		</div>";

	
	} else {
	// call database...
		$stmt = $mysqli->prepare("UPDATE fms_tbl_projects  set date = ?,project = ?,client = ?,hot = ?,cold = ?,value = ?,category = ?,order_no = ?,del = ?,estimate = ?,salesman = ?,design = ?,retention = ?,payment = ?,site_adr_1 = ?,site_Contact = ?,execution = ?,spec = ?,cold_rolled = ?,hd_bolts = ?,site_fixings = ?,bought_outs = ?,mpi = ?,butt = ?,pressings = ?,rollings = ?,paint = ?,treatment = ?,identification = ?,fi_steel = ?,fi_fittings = ?,notes = ?,live = ?,draughtsman = ?,lifting_st = ?,rwc_review = ?, client_id = ?, dsn_codes = ?, wps = ? WHERE client_proj_no = ?");
		$stmt->bind_param('ssssssssssssssssssssssssssssssssssssssss', $date,$project,$client,$hot,$cold,$value,$category,$order_no,$del,$estimate,$salesman,$design,$retention,$payment,$site_adr_1,$site_Contact,$execution,$spec,$cold_rolled,$hd_bolts,$site_fixings,$bought_outs,$mpi,$butt,$pressings,$rollings,$paint,$treatment,$identification,$fi_steel,$fi_fittings,$notes,$live,$draughtsman,$lifting_st,$rwc_review, $client_id, $dsn_codes, $wps, $client_proj_no);
	
	
	// if successful redirect user to index page...
	if($stmt->execute()) {
		echo "<script>location.href='index.php'</script>";


	} else {
		// if the database was not updated then inform user
		echo "<script>alert('".$stmt->error."')</script>";

	}

}

// get stored form data.
// display update form, pre-populated with the stored data.
$res = $mysqli->query($db,“SELECT * FROM fms_tbl_projects WHERE client_id= AND client_proj_no=”.$_GET[‘u’]);
$row = $res->fetch_assoc();

?>[/php]

However it does not load properly and crashes half way through - if I remove the following lines it loads the page ok…
[php] // get stored form data.
// display update form, pre-populated with the stored data.
$res = $mysqli->query($db,“SELECT * FROM fms_tbl_projects WHERE client_id= AND client_proj_no=”.$_GET[‘u’]);
$row = $res->fetch_assoc();[/php]

my database query to connect (mysqli_connect.php) is:-
[php]<?php
define(‘DB_SERVER’, ‘xxxxx’);
define(‘DB_USERNAME’, ‘xxxxx’);
define(‘DB_PASSWORD’, ‘xxxxx’);
define(‘DB_DATABASE’, ‘xxxxx’);
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>[/php]

I dont see how the two lines $res & $row are crashing the script?

Well, Dan, you are comparing a field but leaving the compared value empty. Do not think that is valid.
In your query, you have WHERE client_id= AND Therefore, it is AND’ing NULL with the next part of the
query. Why are you testing for an empty client_id ???

Hi ErnieAlex, I am a ‘tool’… I was in the process of updating my statement but missed the crucial bit out. I’ve updated this but my script stills stops at this point.

I’ve updated the lines to;-
[php] $res = $mysqli->query(“SELECT * FROM fms_tbl_projects WHERE client_id=’{$_SESSION[‘client_id_of_user’]}’ AND client_proj_no=”.$_GET[‘u’]);
$row = $res->fetch_assoc();[/php]

‘client_id_of_user’ successfully works on my main index page to list all values so I know this element is correct

Not sure, but, is there a reason you are using the braces inside the query? You have a single quote inside
of a single quote. I think that is your problem. Try it this way…

[php]
$res = $mysqli->query(“SELECT * FROM fms_tbl_projects WHERE client_id=’” . $_SESSION[“client_id_of_user”] . “’ AND client_proj_no=” . $_GET[‘u’]);
$row = $res->fetch_assoc();
[/php]

Hi Ernie, I managed to get the databsae lookup working - I reverted to the php.net manual :slight_smile:

Now I have two issues with the script which are new errors…

1 / The empty value error displays regardless of whether the input box is empty or not. This is an update.php page so it pulls the existing information.

2 / If I amend any of the input values and attempt to update the database it does not work, I get no errors. The page loads until it runs my php script.

Here is my current code:-
[php]<?php

include('../../includes/mysqli_connect.php');

if (mysqli_connect_errno($db)) {
trigger_error('Database connection failed: '  . mysqli_connect_error(), E_USER_ERROR);

}

// check ‘id’ value is set
if(isset($_GET[‘u’])) {
}

// check all our variables are set
if (isset($_POST[“pro”]))
{
// assign the value of POST field to a variable
$date = $_POST[‘date’];
$project = $_POST[‘project’];
$client = $_POST[‘client’];
$hot = $_POST[‘hot’];
$cold = $_POST[‘cold’];
$value = $_POST[‘value’];
$category = $_POST[‘category’];
$order_no = $_POST[‘order_no’];
$del = $_POST[‘del’];
$estimate = $_POST[‘estimate’];
$salesman = $_POST[‘salesman’];
$design = $_POST[‘design’];
$retention = $_POST[‘retention’];
$payment = $_POST[‘payment’];
$site_adr_1 = $_POST[‘site_adr_1’];
$site_Contact = $_POST[‘site_contact’];
$execution = $_POST[‘execution’];
$spec = $_POST[‘spec’];
$cold_rolled = $_POST[‘cold_rolled’];
$hd_bolts = $_POST[‘hd_bolts’];
$site_fixings = $_POST[‘site_fixings’];
$bought_outs = $_POST[‘bought_outs’];
$mpi = $_POST[‘mpi’];
$butt = $_POST[‘butt’];
$pressings = $_POST[‘pressings’];
$rollings = $_POST[‘rollings’];
$paint = $_POST[‘paint’];
$treatment = $_POST[‘treatment’];
$identification = $_POST[‘identification’];
$fi_steel = $_POST[‘fi_steel’];
$fi_fittings = $_POST[‘fi_fittings’];
$notes = $_POST[‘notes’];
$live = $_POST[‘live’];
$draughtsman = $_POST[‘draughtsman’];
$lifting_st = $_POST[‘lifting_st’];
$rwc_review = $_POST[‘rwc_review’];
$client_id = $_POST[‘client_id’];
$client_proj_no = $_POST[‘client_proj_no’];
$dsn_Codes = $_POST[‘dsn_codes’];
$wps = $_POST[‘wps’];
}

// if not valid return errors to form...
     if (empty($project)) { 
		echo "<div class='alert alert-success alert-dismissible' role='alert'>
		<button type='button' class='close' data-dismiss='alert'><span aria-hidden='true'>&times;</span><span class='sr-only'>Close</span></button>
		<strong>Error!</strong> Project name is missing.
		</div>";

	
	} else {
	// call database...
		$stmt = $mysqli->prepare("UPDATE fms_tbl_projects  set date = ?,project = ?,client = ?,hot = ?,cold = ?,value = ?,category = ?,order_no = ?,del = ?,estimate = ?,salesman = ?,design = ?,retention = ?,payment = ?,site_adr_1 = ?,site_Contact = ?,execution = ?,spec = ?,cold_rolled = ?,hd_bolts = ?,site_fixings = ?,bought_outs = ?,mpi = ?,butt = ?,pressings = ?,rollings = ?,paint = ?,treatment = ?,identification = ?,fi_steel = ?,fi_fittings = ?,notes = ?,live = ?,draughtsman = ?,lifting_st = ?,rwc_review = ?, client_id = ?, dsn_codes = ?, wps = ? WHERE client_proj_no = ?");
		$stmt->bind_param('ssssssssssssssssssssssssssssssssssssssss', $date,$project,$client,$hot,$cold,$value,$category,$order_no,$del,$estimate,$salesman,$design,$retention,$payment,$site_adr_1,$site_Contact,$execution,$spec,$cold_rolled,$hd_bolts,$site_fixings,$bought_outs,$mpi,$butt,$pressings,$rollings,$paint,$treatment,$identification,$fi_steel,$fi_fittings,$notes,$live,$draughtsman,$lifting_st,$rwc_review, $client_id, $dsn_codes, $wps, $client_proj_no);
	
	
	// if successful redirect user to index page...
	if($stmt->execute()) {
		echo "<script>location.href='index.php'</script>";


	} else {
		// if the database was not updated then inform user
		echo "<script>alert('".$stmt->error."')</script>";

	}

}

// get stored form data.
// display update form, pre-populated with the stored data.
$query = “SELECT * FROM fms_tbl_projects WHERE client_id=’{$_SESSION[‘client_id_of_user’]}’ AND client_proj_no=”.$_GET[‘u’];
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);

?>[/php]

I’ve altered the database script and sucessfully altered the database, my only issue and it more from a user perspective is that the “error - project name empty” displays regardless of it loading a value from the database. If I were to remove the input box values and try to update the database it stops me which is good

current code is:-
[php]<?php

include('../../includes/mysqli_connect.php');

if (mysqli_connect_errno($db)) {
trigger_error('Database connection failed: '  . mysqli_connect_error(), E_USER_ERROR);

}

// check ‘id’ value is set
if(isset($_GET[‘u’])) {
}

// check all our variables are set
if (isset($_POST[“pro”]))
{
// assign the value of POST field to a variable
$date = $_POST[‘date’];
$project = $_POST[‘project’];
$client = $_POST[‘client’];
$hot = $_POST[‘hot’];
$cold = $_POST[‘cold’];
$value = $_POST[‘value’];
$category = $_POST[‘category’];
$order_no = $_POST[‘order_no’];
$del = $_POST[‘del’];
$estimate = $_POST[‘estimate’];
$salesman = $_POST[‘salesman’];
$design = $_POST[‘design’];
$retention = $_POST[‘retention’];
$payment = $_POST[‘payment’];
$site_adr_1 = $_POST[‘site_adr_1’];
$site_Contact = $_POST[‘site_contact’];
$execution = $_POST[‘execution’];
$spec = $_POST[‘spec’];
$cold_rolled = $_POST[‘cold_rolled’];
$hd_bolts = $_POST[‘hd_bolts’];
$site_fixings = $_POST[‘site_fixings’];
$bought_outs = $_POST[‘bought_outs’];
$mpi = $_POST[‘mpi’];
$butt = $_POST[‘butt’];
$pressings = $_POST[‘pressings’];
$rollings = $_POST[‘rollings’];
$paint = $_POST[‘paint’];
$treatment = $_POST[‘treatment’];
$identification = $_POST[‘identification’];
$fi_steel = $_POST[‘fi_steel’];
$fi_fittings = $_POST[‘fi_fittings’];
$notes = $_POST[‘notes’];
$live = $_POST[‘live’];
$draughtsman = $_POST[‘draughtsman’];
$lifting_st = $_POST[‘lifting_st’];
$rwc_review = $_POST[‘rwc_review’];
$client_id = $_POST[‘client_id’];
$client_proj_no = $_POST[‘client_proj_no’];
$dsn_Codes = $_POST[‘dsn_codes’];
$wps = $_POST[‘wps’];
}

// if not valid return errors to form...
    if (empty($project)) { 
		echo "<div class='alert alert-success alert-dismissible' role='alert'>
		<button type='button' class='close' data-dismiss='alert'><span aria-hidden='true'>&times;</span><span class='sr-only'>Close</span></button>
		<strong>Error!</strong> Project name is missing.
		</div>";

	
	} else {

	// call database...
		
		$sql = "UPDATE fms_tbl_projects SET 
		
			date 					= '$date',
			project 				= '$project',
			client 				= '$client',
			hot					= '$hot',
			cold					= '$cold',
			value					= '$value',
			category				= '$category',
			order_no				= '$order_no',
			del					= '$del',
			estimate				= '$estimate',
			salesman				= '$salesman',
			design					= '$design',
			retention				= '$retention',
			payment				= '$payment',
			site_adr_1				= '$site_adr_1',
			site_Contact			= '$site_contact',
			execution				= '$execution',
			spec					= '$spec',
			cold_rolled			= '$cold_rolled',
			hd_bolts				= '$hd_bolts',
			site_fixings			= '$site_fixings',
			bought_outs			= '$bought_outs',
			mpi					= '$mpi',
			butt					= '$butt',
			pressings				= '$pressings',
			rollings				= '$rollings',
			paint					= '$paint',
			treatment				= '$treatment',
			identification			= '$identification',
			fi_steel				= '$fi_steel',
			fi_fittings			= '$fi_fittings',
			notes					= '$notes',
			live					= '$live',
			draughtsman			= '$draughtsman',
			lifting_st				= '$lifting_st',
			rwc_review				= '$rwc_review',
			client_id				= '$client_id',
			client_proj_no 		= '$client_proj_no',
			dsn_Codes				= '$dsn_codes',
			wps					= '$wps' 
		
		WHERE client_proj_no =" .$_GET['u'];
		
	if ($db->query($sql) === TRUE) { // will return true if successful else it will return false
			
			echo "<script>location.href='index.php'</script>";
				}
	
			else {
			 	// if the database was not updated then inform user
				echo "<div class='alert alert-danger alert-dismissible' role='alert'>
		<button type='button' class='close' data-dismiss='alert'><span aria-hidden='true'>&times;</span><span class='sr-only'>Close</span></button>
		<strong>Error!</strong>" . $db->error "
		</div>";

		}

}

// get stored form data.
// display update form, pre-populated with the stored data.
$query = “SELECT * FROM fms_tbl_projects WHERE client_id=’{$_SESSION[‘client_id_of_user’]}’ AND client_proj_no=”.$_GET[‘u’];
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);

?>[/php]

How about posting your form. You make it difficult to help you only providing part of the code which is why we are at 3 pages of posts and still not handled.

You have twice as much php code than you need and it is clear you have a bad database design. Post ALL the relative code and an sql dump of your database if you want the best answers and advice.

This really shouldn’t have needed to go to 3 pages to get this handled.

Hi Kevin,

I know it has dragged on a bit so my apologies, I am new and trying to learn as I go.

I tried in the beginning to post all of my code but it was too long, not an excuse but perhaps I should have tried another method.

Presumably I can learn about database design via google?

We dont mind helping you. Have you taken a look at my PDO Bumpstart Database in my signature link? It is very clean and bug free code and sets up in a minute. It was purposely designed to help beginners learn PDO. If you start with that, your time will be well spent and I will be more than happy to explain what you don’t understand. Start a new thread for anything regarding that.

As far as database design itself, look up Database Normalization. It is pretty easy to understand and is very important to know.

A couple coding tips to live by:
Always use lower case variable names
Use descriptive variable names with words separated by underscores (order_quantity VS ordqty)
Dont create unnecessary variable names for your POST or GET data. Use it like so: {$_POST[‘my_descriptive_name’]}
SELECT the column names you want, not SELECT * (Unless you are using all the columns)
Use an IDE (Editor) that has syntax highlighting and shows missing tags, braces, etc. (I use Webuilder)

  • Edit: If you have a lot of code you can always attach a zip file. For me, it’s like telling a doctor you have pain and thats it. Much better to say, I have pain on the right side of my head where the blood is that started right after I was in the study of whether repeated blows to the head cause brain injury.
Sponsor our Newsletter | Privacy Policy | Terms of Service