Jump to content

Help with imput code please..


studygirl15

Recommended Posts

Ok. If you go to my site http://planez.orgfree.com , and you sign in. Username: helpmeplease Password: help

 

Then click on Infrastruction on the left tab..

 

as you can see... it like.. is SHOWING some code... im trying to get the form on the bottom to work...

 

can anyone please help me.. this website is purely a learning experience for me, and i have no prior experience or education in programming.

 

i wont paste teh code, becaue that page alone has over 2000 lines, and i dont want to make anyone mad, but if anyone can please offer to take a look at it for me, id so appreciate it.

 

my msn is danceisbeauty@hotmail.com

 

or if u think u can offer assistince just no here and u dont wana msn id love that too any help is appreciated

Link to comment
Share on other sites

You mean this -

Parse error: syntax error, unexpected '<' in /home/vhosts/planez.orgfree.com/infra.php on line 1216

 

That's just an error. If you can post line 1215-1216 here, I'm sure we can resolve that syntax error of yours. Don't worry, nothing leaked, except the line number. :D

Link to comment
Share on other sites

I think I fixed that error. Turned out I did the <?php.. and then I opened PHP again without closing it

 

I did a ?> before the new open, and now it works.

 

problem is now.. its not doing what.. its not told to do... your right that doesnt make sense really :D

 

 

 

 

my problem is... since im such a noob.. i dont know how ot "hookup, my code to the submit button."

 

 

In the form, I have ... the code is on my laptop, let me login here on my laptop, and i can paste the code on there to show you what i mean. 1 sec pls sir

Link to comment
Share on other sites

<?php$sql="INSERT INTO wings (CC1, GB1, Radar1, Runway1, Factory1, NP1, Residence1, PP1, Oil1)VALUES ($_POST[1], $_POST[2], $_POST[3], $_POST[4], $_POST[5], $_POST[6], $_POST[7], $_POST[8]);";  $result=mysql_query($sql)or die ("Error. Could not do SQL query!");?>

 

<form action="<?php echo $PHP_SELF; ?>" method="post">

<input style="font-size:8pt;" type=submit name=cons value=Construct onClick="Go(1,this.form);">  /  <input style="font-size:8pt;" type=button name=dest value=Destroy onClick="Go(0,this.form);"> buildings to highlighted sector

Link to comment
Share on other sites

wow it doesnt look like that... the copy paste is messing things up... is there a code thing on here...

 

 

<?php

 

 

$sql="INSERT INTO wings (CC1, GB1, Radar1, Runway1, Factory1, NP1, Residence1, PP1, Oil1)

VALUES ($_POST[1], $_POST[2], $_POST[3], $_POST[4], $_POST[5], $_POST[6], $_POST[7], $_POST[8]);"; 

 

$result=mysql_query($sql)or die ("Error. Could not do SQL query!");

 

 

 

 

 

 

?>

 

 

 

<form action="<?php echo $PHP_SELF; ?>" method="post">

 

 

 

 

 

<input style="font-size:8pt;" type=submit name=cons value=Construct onClick="Go(1,this.form);">

/

<input style="font-size:8pt;" type=button name=dest value=Destroy onClick="Go(0,this.form);"> buildings to highlighted sector

 

 

 

 

there we go!

 

 

Link to comment
Share on other sites

wow it doesnt look like that... the copy paste is messing things up... is there a code thing on here...

<?php

 

<form action="<?php echo $PHP_SELF; ?>" method="post">

Can't see the error since it's an IE thing and I'm using Linux.. which doesn't come with IE, but did you assing a value to that $PHP_SELF?

I think you might have wanted to use $_SERVER['PHP_SELF'] there.

 

As for the code bbcode, see my signature :)

Link to comment
Share on other sites

I am unsure if this will help you. Hope it does.

 

<form method="post">
<input type="text" name="example" />
<input type="submit" name="test" value="Submit" />
</form>

<?php
if (isset($_POST['test']))
{

// RUN CODE ON FORM SUBMIT. EXAMPLE BELOW.

$example = $_POST['example'];
echo $example;

}
?>

 

EDIT: Aye. Ken2k7 is correct, my mistake. $_SERVER['PHP_SELF']; is not required when posting to the same page.

Link to comment
Share on other sites

1. Please don't call me sir. Nothing against you. I just feel weird about it. I'm not even 21 :D

2. $PHP_SELF is deprecated. If you're submitting to the same page, you don't need the action attribute.

3. In your query, there are a few things wrong. I don't think $_POST[1] works. I think you have to call it by the name. For example, if your input field (I'll use the first one for example), has the name attribute set to "cons", then you use $_POST['cons'] for the value.

4. Don't put your $sql variable next to <?php that closely. Put a space between them.

 

Example of hooking a form with a submit button to PHP -

<form method="post">
Username: <input type="text" name="username" /><br />
Age: <input type="text" name="age" /><br />
<input type="submit" name="submit" value="Submit" />
</form>

<?php
// this checks if the submit button is clicked. When you submit that form above,
// PHP's $_POST has the submit key in its array with the value, which is "Submit"
if (!empty($_POST['submit'])) { // so if it's not empty, then get the other input fields
     $username = $_POST['username'];  // see how it matches the name of the input field?
     $age = $_POST['age'];
     
     // let's check if the data is empty
     if (empty($username)) {
          // error
         echo 'username is empty';
         exit; // quits the script
     }

     // same for age
     if (empty($age)) {
          echo 'age is empty';
          exit;
     }
     
     // now that we know the data aren't empty, let's continue.
     
     // so in a SQL, you want to first use mysql_real_escape_string() on the user input to prevent SQL injection.
     $username = mysql_real_escape_string($username);
     // generally, you don't have to use it on numbers, so we'll just cast $age as a number
     $age = intval($age);   // you could have done - $age = (int) $age; as well
     
     $sql = 'INSERT INTO table (username, age) VALUES ("$username", "$age")';
     // See how there is a quote around values? Well you need those.
     $query = mysql_query($sql) or die(mysql_error());
}

// the closing ?> php tag is optional. 

 

Hope that helps.

Link to comment
Share on other sites

<?php


$sql="INSERT INTO wings (CC1, GB1, Radar1, Runway1, Factory1, NP1, Residence1, PP1, Oil1)
VALUES ($_POST[1], $_POST[2], $_POST[3], $_POST[4], $_POST[5], $_POST[6], $_POST[7], $_POST[8]);";  

$result=mysql_query($sql)or die ("Error. Could not do SQL query!");






?>



<form method="post">





<input style="font-size:8pt;" type=submit name=cons value=Construct onClick="Go(1,this.form);"> 
/ 
<input style="font-size:8pt;" type=button name=dest value=Destroy onClick="Go(0,this.form);"> buildings to highlighted sector




<table border=1 bordercolor=#003399 cellspacing=0 width=95%>
<tr align=center bgcolor=#003399>
	<td><font size=1>Name</td>
	<td><font size=1>Hit<br>Point</td>
	<td><font size=1>Armor</td>
	<td><font size=1>Price<td wrap=><font size=1>Amount</td>
	<td><font size=1>Description</td>
	<td><font size=1>Dependency</td>
</tr>


<tr align=center>
<td><font size=1>Command Center</td>
<td><font size=1>2200</td>
<td><font size=1>25</td>
<td><font size=1>10000</td>
<td nowrap>
    <img border=0 src=up.gif onClick="UpDown(2,1);">

<input type=text name=1 size=3 maxlength=3 value=0></imput>

    <img border=0 src=down.gif onClick="UpDown(2,0);">
</td>
<td><font size=1>Defensive structures and aircraft controlled by computer can attack enemy</td>
<td><font size=1> </td>
</tr>











<tr align=center>
<td><font size=1>Government Bldg.</td>
<td><font size=1>1500</td>
<td><font size=1>20</td>
<td><font size=1>9000</td>
<td nowrap>
       <img border=0 src=up.gif onClick="UpDown(3,1);">


<input type=text name=2 size=3 maxlength=3 value=0></imput>




	<img border=0 src=down.gif onClick="UpDown(3,0);">
</td>
<td><font size=1>Collect tax from residence, 100 credits per residence</td>
<td><font size=1> </td>
</tr>









<tr align=center>
<td><font size=1>Radar Station</td>
<td><font size=1>500</td>
<td><font size=1>25</td>
<td><font size=1>3000</td>
<td nowrap>
	<img border=0 src=up.gif onClick="UpDown(4,1);">
	<input type=text name=3 size=3 maxlength=3 value=0></imput>
	<img border=0 src=down.gif onClick="UpDown(4,0);">
</td>
<td><font size=1>Your wing radar while in base</td>
<td><font size=1>Power Plant/Nuclear Power Plant</td>
</tr>


<tr align=center>
<td><font size=1>Runway</td>
<td><font size=1>350</td>
<td><font size=1>5</td>
<td><font size=1>1000</td>
<td nowrap>
	<img border=0 src=up.gif onClick="UpDown(5,1);">
	<input type=text name=4 size=3 maxlength=3 value=0></imput>
	<img border=0 src=down.gif onClick="UpDown(5,0);">
</td>
<td><font size=1>Needed for your aircraft to take off</td>
<td><font size=1></td>
</tr>


<tr align=center>
<td><font size=1>Factory</td>
<td><font size=1>800</td>
<td><font size=1>10</td>
<td><font size=1>1000</td>
<td nowrap>
	<img border=0 src=up.gif onClick="UpDown(6,1);">
	<input type=text name=5 size=3 maxlength=3 value=0></imput>
	<img border=0 src=down.gif onClick="UpDown(6,0);">
</td>
<td><font size=1>Needed to buy defensive structures;<br>Produce aircraft controlled by computer automatically</td>
<td><font size=1>Residence, Highway, Power Plant/Nuclear Power Plant</td>
</tr>


<tr align=center>
<td><font size=1>Nuclear Plant</td>
<td><font size=1>500</td>
<td><font size=1>15</td>
<td><font size=1>5000</td>
<td nowrap>
	<img border=0 src=up.gif onClick="UpDown(7,1);">
	<input type=text name=6 size=3 maxlength=3 value=0></imput>
	<img border=0 src=down.gif onClick="UpDown(7,0);">
</td>
<td><font size=1>Supplies power for factory and radar station</td>
<td><font size=1>Residence, Highway</td>
</tr>


<tr align=center>
<td><font size=1>Residence</td>
<td><font size=1>500</td>
<td><font size=1>4</td>
<td><font size=1>1500</td>
<td nowrap>
	<img border=0 src=up.gif onClick="UpDown(8,1);">
	<input type=text name=7 size=3 maxlength=3 value=0></imput>
	<img border=0 src=down.gif onClick="UpDown(8,0);">
</td>
<td><font size=1>Supplies workers for factory, oil refinery and (nuclear) power plant</td>
<td><font size=1></td>
</tr>


<tr align=center>
<td><font size=1>Power Plant</td>
<td><font size=1>700</td>
<td><font size=1>12</td>
<td><font size=1>1000</td>
<td nowrap>
	<img border=0 src=up.gif onClick="UpDown(9,1);">
	<input type=text name=8 size=3 maxlength=3 value=0></imput>
	<img border=0 src=down.gif onClick="UpDown(9,0);">
</td>
<td><font size=1>Supplies power for factory and radar station</td>
<td><font size=1>Residence, Oil Refinery, Highway</td>
</tr>


<tr align=center>
<td><font size=1>Oil Refinery</td>
<td><font size=1>700</td>
<td><font size=1>8</td>
<td><font size=1>1000</td>
<td nowrap>
	<img border=0 src=up.gif onClick="UpDown(10,1);">
	<input type=text name=9 size=3 maxlength=3 value=0></imput>
	<img border=0 src=down.gif onClick="UpDown(10,0);">
</td>
<td><font size=1>Produces fuel for power plant, enables cheaper fuel</td>
<td><font size=1>Residence, Highway</td>
</tr>

</p>

</body></html>[/color]

 

 

 

 

 

 

 

This is what the entire form looks like.

Link to comment
Share on other sites

3. In your query, there are a few things wrong. I don't think $_POST[1] works. I think you have to call it by the name. For example, if your input field (I'll use the first one for example), has the name attribute set to "cons", then you use $_POST['cons'] for the value.

 

 

I did... each text field is named a number... 1 2 3 4... so on... so thats why its post 1

Link to comment
Share on other sites

I think I just went blind...  8)

 

Please surround your code with


tags for proper formatting and syntax highlighting, you don't have to create your own  ;D

 

EDIT: Damnit eRott, I said the same thing you did now I have to change it, hmm let's see...

Link to comment
Share on other sites

Maq, how did you do that? :P I had been trying for 5 blasted minutes to type the BBCode without it actually turning into well... BBcode (if you know what I mean).

 

Use [nobbc][/nobbc] tags around the BBC you don't want parsed.

Link to comment
Share on other sites

ok i think im getting closer to the problem...

 

it says that.. its cant do the SQL query... the problem is... the SQL query tells it to instert the data into the database... that is only saposed to happen when i pressed the button... so why is is trying to do it right when the page loads up...

Link to comment
Share on other sites

You're right, your have your SQL execution because you even check to see if anything has been submitted.  You're also using a lot of javascript for some reason while you're still processing everything server side...

 

Anyway, try changing this portion:

 

$sql="INSERT INTO wings (CC1, GB1, Radar1, Runway1, Factory1, NP1, Residence1, PP1, Oil1)
VALUES ($_POST[1], $_POST[2], $_POST[3], $_POST[4], $_POST[5], $_POST[6], $_POST[7], $_POST[8]);";  

$result=mysql_query($sql)or die ("Error. Could not do SQL query!");

?>

</pre>
<form method="post">
<

 

to this:

 

if(isset($_POST['cons']))
{
   $sql="INSERT INTO wings (CC1, GB1, Radar1, Runway1, Factory1, NP1, Residence1, PP1, Oil1)
   VALUES ($_POST[1], $_POST[2], $_POST[3], $_POST[4], $_POST[5], $_POST[6], $_POST[7], $_POST[8]);";  
   $result=mysql_query($sql)or die ("Error. Could not do SQL query! " . mysql_error()); 
}

?>
</pre>
<form method="POST" action="<?php%20echo%20%24_SERVER%5B'PHP_SELF'%5D;%20?>">
   <

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.