coco243 Posted May 3, 2013 Share Posted May 3, 2013 (edited) Hellow, I have the following issue if you please can help me. I have this index.php file: <html><body><h1>It works!</h1><form action="/PHP/update.php" method="post">Age: <input type="text" name="age"><input type="submit"></form><?php//connecting to database//$con=mysqli_connect("localhost","root","gogonea","my_db"); // conection checking//if (mysqli_connect_errno())//{// echo "conection failed ".mysqli_connect_error();//}//else//{//echo "Ghiata, conection established! <br>";//} function afi(){include("displaytable.php");}//afi(); //closing connection//mysqli_close($con);?><div><p>cucu</p><form name="displaytable" action="\PHP\displaytable.php" method="get"><input type="submit" value="Display Table"></form> </div></body></html> And this update.php file: <?php//connecting to database$con=mysqli_connect("localhost","root","gogonea","my_db"); //conection checkingif (mysqli_connect_errno()){ echo "conection failed ".mysqli_connect_error();}else{echo "Ghiata, conection established! <br>";} //Updating Tablemysqli_query($con,"UPDATE Persons SET Age=ageWHERE FirstName='Peter' AND LastName='Griffin'"); //closing connectionmysqli_close($con); ?> I can't update the age, taked from the form scripted in the index.php This is a test of how to take values from forms and transmit them to a database. If I wasn't exprimed clear please tell me to be more explicite if is the case. Thank you verry much Edited May 3, 2013 by damy Link to comment Share on other sites More sharing options...
kanchatchai Posted May 3, 2013 Share Posted May 3, 2013 use$_POST['age'] mysqli_query($con,"UPDATE Persons SET Age=".$_POST['age']." WHERE FirstName='Peter' AND LastName='Griffin'"); Link to comment Share on other sites More sharing options...
coco243 Posted May 3, 2013 Author Share Posted May 3, 2013 (edited) It's not working.When i display table the age value is the same as it was.I don't have experience, and I can't figure where is the problem. I have to modify something at the form script from index.php also? Edited May 3, 2013 by damy Link to comment Share on other sites More sharing options...
coco243 Posted May 4, 2013 Author Share Posted May 4, 2013 (edited) I had taked the information taken from that form ( age parameter ) <form action="/PHP/update.php" method="post">Age: <input type="text" name="age"><input type="submit"></form> And introduced and I had introduce it on a variable: $x=$_POST["fage"]; and dyspayed it here. echo $x; It works. Also I had verified if my updating STATMENT IS OK, and I had placed the number 20 at Age parameter, and when I had dysplayed the table, it was apearing the modification, so the UPDATE statment is OK. The next step was to pass the value of submit to variable x, and than to the UPDATE statament: mysqli_query($con,"UPDATE Persons SET Age=$xWHERE FirstName='Peter' AND LastName='Griffin'"); Didn't worked, why? Edited May 4, 2013 by damy Link to comment Share on other sites More sharing options...
Ingolme Posted May 4, 2013 Share Posted May 4, 2013 Did you check to see if mysqli_error() shows anything?Is "Age" an integer field? Link to comment Share on other sites More sharing options...
coco243 Posted May 4, 2013 Author Share Posted May 4, 2013 (edited) Did you check to see if mysqli_error() shows anything? How I do that? if (mysqli_error()) { echo "error";} Is "Age" an integer field? No, it is text field. Edited May 4, 2013 by damy Link to comment Share on other sites More sharing options...
Ingolme Posted May 4, 2013 Share Posted May 4, 2013 $query = mysqli_query($con,"UPDATE Persons SET Age=$x WHERE FirstName='Peter' AND LastName='Griffin'");if(!$query) { echo mysqli_error();} I think, if Age is a text field, that you should be putting the value of $x between quotation marks:SET Age='$x' Link to comment Share on other sites More sharing options...
coco243 Posted May 4, 2013 Author Share Posted May 4, 2013 Thank you very much Inglome, that it was.I had to put $x within ' signs. Thank you again. Link to comment Share on other sites More sharing options...
coco243 Posted May 4, 2013 Author Share Posted May 4, 2013 Now I see that it's working and without ' sign. I don't know why last time didn't worked. Hm.. Link to comment Share on other sites More sharing options...
coco243 Posted May 4, 2013 Author Share Posted May 4, 2013 And the indication of kanchatchai is working, I think I was putting ";" after SET=".$_POST['age']." or after SET=x, and what was following ";" wasn't taked for compiling. Thank you all for help. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now