0

I have been banging my head against the wall on this for about 2 hours now and I cannot figure out what im doing wrong. I am simply trying to update a MySQL database with new information. but when I click "Update Information" nothing is happening.

<div id="tabs-1"> 
<?php  

 //update main informaion

if(isset($_POST["toolnameupdate"])){

  $companyname1 = "";

  $toolname1 = "";

 include_once("../php_includes/db_connect.php");

 $companyname1 = $_POST['clientname'];

 $toolname1 = $_POST['webtoolname'];

 $sql = "UPDATE siteinformation SET clientname = $companyname1, srcname = $toolname1";

$query = mysqli_query($db_connect, $sql); 

error_reporting(E_ALL);

header('Location: user.php');
}
?>     
<form method="post" action="">
  <fieldset>
<legend><strong>Main Title Information</strong></legend>
<div id="prompt">Client Company Name:</div><div id="answer"><input type="text" name="clientname" id="clientname" value="<? echo $companyname; ?>"/></div>
<div id="prompt">Web Tool Name:</div><div id="answer"><input type="text" name="webtoolname" id="webtoolname" value="<? echo $toolname; ?>"/></div>
<div id="prompt"><input type="submit" id="toolnameupdate" name="toolnameupdate" value="Update Information" /></div><div id="answer">&nbsp;</div>
<div id="prompt">&nbsp;</div><div id="answer">&nbsp;</div>
</fieldset> 
</form>
  </div>  

Can anyone see where it is missing information?

Thanks

5
  • 2
    You're missing a <form> tag.... Commented Aug 2, 2013 at 22:36
  • 2
    Firstly.. sanitize your variables. Secondly.. I don't think using parenthesis in the $_POST superglobal is a legal move. Commented Aug 2, 2013 at 22:38
  • You don't have a WHERE condition in your update query, it's going to update ALL rows. Are you sure you don't mean INSERT? Also there's just so much wrong with this code that should have raised a few errors. error_reporting(E_ALL); will make sure you actually see them. Commented Aug 2, 2013 at 22:38
  • @Sammitch I do want it to update them all, there are only 2 rows and will never be more. code has been updated and is not throwing any errors. im really rusty at this, more of my own pet project really. Thanks though Commented Aug 2, 2013 at 22:53
  • @PHaeLiX error_reporting(E_ALL); sets the error reporting for subsequent calls. You should move it to the top of the file so you can see any database call errors. Also look at mysqli_error() after mysqli_query is called for errors with your SQL syntax. Commented Aug 3, 2013 at 1:26

2 Answers 2

5

I am not sure if this is the complete code. But form fields should be included in <form> tags.

<form method="post" action="">
<fieldset>
<legend><strong>Main Title Information</strong></legend>
<div id="prompt">Client Company Name:</div><div id="answer"><input type="text" name="clientname" id="clientname" value="<? echo $companyname; ?>"/></div>
<div id="prompt">Web Tool Name:</div><div id="answer"><input type="text" name="webtoolname" id="webtoolname" value="<? echo $toolname; ?>"/></div>
<div id="prompt"><input type="submit" id="toolnameupdate" name="toolnameupdate" value="Update Information" /></div><div id="answer">&nbsp;</div>
<div id="prompt">&nbsp;</div><div id="answer">&nbsp;</div>
</fieldset> 
</form>

also the correct syntax is $_POST['..'], and not with parenthesis.

and also move error_reporting(E_ALL); to the top of the file, otherwise it won't be too useful.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the help, form was there but I deleted it on save. I have also revised the $_POST statements. the form submits now, but the changes are not being added. revised code is below
thats good to hear. now you need to do some basic database debugging. like checking that your query is successfull when run using the phpmyadmin.
4

$_POST('clientname') should be $_POST['clientname']. And the same with the rest of the posts. Also read Aris's answer about the form tags.

After you revised your code you removed the quotes around the variables, they need to stay.

$sql = "UPDATE siteinformation SET clientname = '$companyname1', srcname = '$toolname1'";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.