Complete coding noob with a silly problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
magicmonkey
Forum Newbie
Posts: 5
Joined: Mon Feb 01, 2010 10:28 pm

Complete coding noob with a silly problem!

Post by magicmonkey »

right, this is probably going to be the most messy implimentation to ever cross these board but I'm afraid I'm a complete noob and it's showing!

What I've got at the moment is one page which has a for on it passing information to another page which runs the query to add infor into a MySQL database...

Index.html with the form:

Code: Select all

<FORM name="Survey" method=post action="include.php" onSubmit="return checkrequired(this)">
<tr>
<td colspan='3'>
 
<img src='images/spacer.png' /></td>
</tr>
<TR>
<TD width="260" align='center'>
<span class='questions'>Was a call logged?</span><br />
<SELECT  class='Jumpbox' name='requiredLogged'>
<OPTION selected></OPTION>
<OPTION VALUE='Yes'>Yes</OPTION>
<OPTION VALUE='No'>No</OPTION>
</SELECT></TD>
<TD width="127" align="center">
<span class='questions'>Was a call updated?</span><br />
<SELECT  class='Jumpbox' name='requiredUpdated'>
<OPTION selected></OPTION>
<OPTION VALUE='Yes'>Yes</OPTION>
<OPTION VALUE='No'>No</OPTION>
</SELECT></TD>
<TD width="205" align='center'>
<span class='questions'>Call Number</span><br />
<INPUT class='text' type=text name='Incident'></TD>
</TR><tr>
<td colspan='3'>
 
<img src='images/spacer.png' /></td>
</tr><TR>
<TD align='center'>
<span class='questions'>Who Took The Call</span><br /><br />
<SELECT  class='Jumpbox' name='requiredAnalyst'>
<OPTION selected></OPTION>
<?php 
 
include 'connect.php';
 
$sql="SELECT user FROM login
Order by user";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
 
 
?>
<option value ="<?php echo $data['user'] ?>"><?php echo $data['user'] ?></option>
<?php } ?>
</select>
<TD align='center' colspan='2'>
<span class='questions'>If 'Other' please specify:</span><br />
 
<TEXTAREA class='textarea' rows='3' name='AnalystOther'></TEXTAREA></TD>
</TR><tr>
<td colspan='3'>
<img src='images/spacer.png' /></td>
</tr><TR>
<TD align='center'>
<span class='questions'>Which Client Was The Call For?</span><br /><br />
<SELECT class='Jumpbox' name='requiredClient'>
<OPTION selected></OPTION>
<?php 
 
include 'connect.php';
 
$sql="SELECT Clientname FROM client
Order by Clientname";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
 
 
?>
<option value ="<?php echo $data['Clientname'] ?>"><?php echo $data['Clientname'] ?></option>
<?php } ?>
</SELECT></TD>
<TD align='center' colspan='2'>
<span class='questions'>If 'Other' Please Specify</span><br />
<TEXTAREA  class='textarea' rows='3' name='ClientComments'></TEXTAREA></TD>
</TR><tr>
<td colspan='3'>
<img src='images/spacer.png' /></td>
</tr><TR>
<TD align='center'>
<span class='questions'>Type of Call:</span><br /><br />
<select class='Jumpbox' name='requiredCallType'>
  <option selected></option>
<?php 
 
include 'connect.php';
 
$sql="SELECT CallType FROM CallType
Order by CallType";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
 
 
?>
<option value ="<?php echo $data['CallType'] ?>"><?php echo $data['CallType'] ?></option>
<?php } ?>
</select></TD>
<TD align='center' colspan='2'>
<span class='questions'>Provide Further Details if Possible:</span><br />
<TEXTAREA class='textarea' rows='3' name='FurtherDetails'></TEXTAREA></TD>
</TR><tr>
 
<tr>
<td colspan='3'>
<img src='images/spacer.png' /></td>
</tr><TR>
<TD colspan='3' align='center'>
<span class='questions'>Is there anything else you would like to add?</span><br />
<TEXTAREA class='textarea' rows='3' name='FurtherComments'></TEXTAREA></TD>
</TR>
<tr>
<td colspan='3'>
 
<img src='images/spacer.png' /></td>
</tr>
<TR>
<TD align='center'><INPUT type='Reset' value='Reset'></TD>
<TD align='center'  colspan='2'><INPUT type='submit' value='Send'><br /></TD>
</TR></form>
I've left out the rest of the page bot obviously it exists, just didn't think anyone would be interested in it!!

Here's the include.php file:

Code: Select all

<?
//Connect to database
include 'connect.php';
 
//deifne variables
$Logged=$_POST['requiredLogged'];
$Updated=$_POST['requiredUpdated'];
$Incident=$_POST['Incident'];
$Analyst=$_POST['requiredAnalyst'];
$AnalystOther=$_POST['AnalystOther'];
$Client=$_POST['requiredClient'];
$ClientComments=$_POST['ClientComments'];
$CallType=$_POST['requiredCallType'];
$FurtherDetails=$_POST['FurtherDetails'];
$FurtherComments=$_POST['FurtherComments'];
 
//Define Query
$query = "INSERT INTO data(Logged, Updated, Incident, Analyst, AnalystOther, Client, ClientComments, CallType, FurtherDetails, FurtherComments)
VALUES ( '$Logged', '$Updated', '$Incident', '$Analyst', '$AnalystOther', '$Client', '$ClientComments', '$CallType', '$FurtherDetails', '$FurtherComments')";
 
//Run queries and error reporting
if (!mysql_query($query))
 
  {
 
  die('Error: ' . mysql_error());
 
  }
?>
 
There's an HTML redirect at the bottom of this page to return people to the first page once the record has been entered (like I said, I'm a noob!)

So far, this all works, it does what it says on the tin as it were. What I'd like to do is provide a URL someone could have a link to which would pass data straight to the include.php file without the need to open the index page (the form is time consuming and it's a quick shortcut for users) The problem is, I have no idea how to do it!

I've tried what I believe is the standard PHP way of passing varaibles in the URL which was:

http://wncp3400/calls/calls/include.php ... Logged=Yes

and all that happens is I get a blank entry in the MySQL database. I've tried a few variations on the theme but I'm really just shooting in the dark with it. Could anyone lend a hand?
magicmonkey
Forum Newbie
Posts: 5
Joined: Mon Feb 01, 2010 10:28 pm

Re: Complete coding noob with a silly problem!

Post by magicmonkey »

doh!!! I've just changed the include.phpfile to use $_GET instead of $_POST, told you I was a nooooooob!!
magicmonkey
Forum Newbie
Posts: 5
Joined: Mon Feb 01, 2010 10:28 pm

Re: Complete coding noob with a silly problem!

Post by magicmonkey »

Ok, now I'm using the $_GET command I can't get the data from the form to go in, just the data from the URL, doh! Is there a way of getting both to work?
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Complete coding noob with a silly problem!

Post by flying_circus »

magicmonkey wrote:Ok, now I'm using the $_GET command I can't get the data from the form to go in, just the data from the URL, doh! Is there a way of getting both to work?
I have not had a chance to review your code, so this reply is in context from the quoted question above.

Yes, use both $_GET and $_POST. $_GET retreives data from the URL's querystring. $_POST retreives data submitted from a form post.
magicmonkey
Forum Newbie
Posts: 5
Joined: Mon Feb 01, 2010 10:28 pm

Re: Complete coding noob with a silly problem!

Post by magicmonkey »

flying_circus wrote:
magicmonkey wrote:Ok, now I'm using the $_GET command I can't get the data from the form to go in, just the data from the URL, doh! Is there a way of getting both to work?
I have not had a chance to review your code, so this reply is in context from the quoted question above.

Yes, use both $_GET and $_POST. $_GET retreives data from the URL's querystring. $_POST retreives data submitted from a form post.

I've tried that by doing that using this code:

Code: Select all

$Logged=$_GET['requiredLogged'];
$Updated=$_GET['requiredUpdated'];
$Incident=$_GET['Incident'];
$Analyst=$_GET['requiredAnalyst'];
$AnalystOther=$_GET['AnalystOther'];
$Client=$_GET['requiredClient'];
$ClientComments=$_GET['ClientComments'];
$CallType=$_GET['requiredCallType'];
$FurtherDetails=$_GET['FurtherDetails'];
$FurtherComments=$_GET['FurtherComments'];
$Logged=$_POST['requiredLogged'];
$Updated=$_POST['requiredUpdated'];
$Incident=$_POST['Incident'];
$Analyst=$_POST['requiredAnalyst'];
$AnalystOther=$_POST['AnalystOther'];
$Client=$_POST['requiredClient'];
$ClientComments=$_POST['ClientComments'];
$CallType=$_POST['requiredCallType'];
$FurtherDetails=$_POST['FurtherDetails'];
$FurtherComments=$_POST['FurtherComments'];
Unfortunately I've got a load of other work on at the moment as well so finding time to test is a big problem!! At the moment this is only submitting data from the URL. I presume this is because the $_GET command is before the $_POST command. Would simply changing these around fix the problem do you think?

ps. Thanks for the reply, much appreciated :D
magicmonkey
Forum Newbie
Posts: 5
Joined: Mon Feb 01, 2010 10:28 pm

Re: Complete coding noob with a silly problem!

Post by magicmonkey »

ok, now I've tried using $_POST first and I get the inverse problem, is there not a command which incorporates $_GET and $_POST? Or a work around I could use to get both working?

I suppose I could use a different include.php page with the $_GET command on it to use for passing information in the URL but that's even more messy than my usual blind attempts!
Post Reply