conqueror Posted June 29, 2022 Share Posted June 29, 2022 Quote Link to comment https://forums.phpfreaks.com/topic/314975-parse-error-syntax-error-unexpected-age-t_variable/ Share on other sites More sharing options...
cyberRobot Posted June 29, 2022 Share Posted June 29, 2022 The error is caused by the missing semi-colons after the lines defining $username and $age. Quote Link to comment https://forums.phpfreaks.com/topic/314975-parse-error-syntax-error-unexpected-age-t_variable/#findComment-1597717 Share on other sites More sharing options...
ginerjm Posted June 29, 2022 Share Posted June 29, 2022 And in the future I recommend that if you want help with your code then give us the code, not an image of it. People like to work with code to help you debug it and we can't work with a picture. Quote Link to comment https://forums.phpfreaks.com/topic/314975-parse-error-syntax-error-unexpected-age-t_variable/#findComment-1597720 Share on other sites More sharing options...
benanamen Posted June 29, 2022 Share Posted June 29, 2022 OP will still get an undefined index error if the page is called directly after missing semi-colons added. Quote Link to comment https://forums.phpfreaks.com/topic/314975-parse-error-syntax-error-unexpected-age-t_variable/#findComment-1597723 Share on other sites More sharing options...
ginerjm Posted June 29, 2022 Share Posted June 29, 2022 (edited) As well as the typo in the connect line. If we could see the real "code" perhaps we could then even find more errors, hint, hint. Edited June 29, 2022 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/314975-parse-error-syntax-error-unexpected-age-t_variable/#findComment-1597725 Share on other sites More sharing options...
conqueror Posted June 29, 2022 Author Share Posted June 29, 2022 here is the code: <?php $username1=$_POST["text"] $age=$_POST["number"] $username="root"; $host="localhost"; $password=" "; $databasename="kemudb"; $conn=mysqli_connect($host, $username, $password, $databsename); $sql_read="SELECT * FROM infokemu"; $result=mysqli_query($conn & $sql_read); ?> <form method="POST" action=""> USERNAME: <br> <input type="text" name="username1"/> <br> AGE <br> <input type="number" name="age"/> <br> <input type="submit" value="submit"/> </form> Quote Link to comment https://forums.phpfreaks.com/topic/314975-parse-error-syntax-error-unexpected-age-t_variable/#findComment-1597728 Share on other sites More sharing options...
gw1500se Posted June 29, 2022 Share Posted June 29, 2022 Semicolons are still missing. In addition, don't use * in your query. Specify only those column you expect to use. Quote Link to comment https://forums.phpfreaks.com/topic/314975-parse-error-syntax-error-unexpected-age-t_variable/#findComment-1597729 Share on other sites More sharing options...
Barand Posted June 29, 2022 Share Posted June 29, 2022 I added one or two comments for you. <?php $username1=$_POST["text"] // ^^^^ there is no field named "text" $age=$_POST["number"] // ^^^^^^ there is no field named "number" $username="root"; $host="localhost"; $password=" "; $databasename="kemudb"; $conn=mysqli_connect($host, $username, $password, $databsename); // ^^ typo $sql_read="SELECT * FROM infokemu"; $result=mysqli_query($conn & $sql_read); // ^ WTF!? ?> <form method="POST" action=""> // ^^^^ as you are only getting data, your method should be GET, not POST USERNAME: <br> <input type="text" name="username1"/> <br> AGE <br> <input type="number" name="age"/> <br> <input type="submit" value="submit"/> </form> Lastly, what is the point of the query? You do nothing with the results (when you get any). Quote Link to comment https://forums.phpfreaks.com/topic/314975-parse-error-syntax-error-unexpected-age-t_variable/#findComment-1597730 Share on other sites More sharing options...
ginerjm Posted June 29, 2022 Share Posted June 29, 2022 Your code with some comments (not nearly enough of them though): $username1=$_POST["text"] //error X 2 $age=$_POST["number"] //error x 2 $username="root"; $host="localhost"; $password=" "; $databasename="kemudb"; $conn=mysqli_connect($host, $username, $password, $databsename); //error $sql_read="SELECT * FROM infokemu"; $result=mysqli_query($conn & $sql_read); //error ?> <form method="POST" action=""> USERNAME: <br> <input type="text" name="username1"/> <br> AGE <br> <input type="number" name="age"/> <br> <input type="submit" value="submit"/> </form> Your code will never run even once you clean up all of the errors I have marked. Where did you copy this from? Or did you write it using your apparently very limited knowledge of how to code php and html? I won't begin to explain because I'd rather you step back and do some reading and learning. That will give you a better experience than having me simply tell you what to alter. If you wrote this code then hopefully you can re-learn what you tried to learn and improve. If you copied it please never copy anything from that source again. Here's one thing to think about. When you run this script for the first time what do you think will happen? For one thing, there will not be any $_POST values since you haven't sent your html to the client yet. You should always check for the existence of some input before trying to access it. The next thing is - why do you run a query but you never do anything with the results, if any? Did you not give us 'all' of your code? The current structure of your script is kind of broken up. First you assign some values, then you make a connection and then you send out a form and then you end? Makes it hard to get people to help you when you don't paint a very pretty picture. Quote Link to comment https://forums.phpfreaks.com/topic/314975-parse-error-syntax-error-unexpected-age-t_variable/#findComment-1597731 Share on other sites More sharing options...
Barand Posted June 29, 2022 Share Posted June 29, 2022 One final comment - turn on PHP's and MySqli's error reporting. You and I aren't good enough to attempt development without them. Quote Link to comment https://forums.phpfreaks.com/topic/314975-parse-error-syntax-error-unexpected-age-t_variable/#findComment-1597732 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.