Jump to content

Parse error: syntax error, unexpected '$age' (T_VARIABLE)


conqueror

Recommended Posts

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>

 

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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