PHP noob question :P

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
SchweppesAle
Forum Newbie
Posts: 9
Joined: Thu Aug 14, 2008 11:40 pm

PHP noob question :P

Post by SchweppesAle »

Yea, so most of my experience thus far has been geared towards Java. I only just started working with "proper" html(CSS), PHP & MySQL. I'm trying to create an HTML form which forwards the information given to a php method via $_Post. here's the code:

Code: Select all

 
<?php include("Jobs.php"); ?>
DBConnect();
mysql_select_db("Jobs");
 
<form action="Jobs.php" method="post">
Name: <input type="text" name="Name" />
<br/>
Number: <input type="text" name="Number" />
<br/>
Resume: <input type = "text" name = "Resume" />
<br/>
<Font size = -1>Maximum of 500 characters</Font>
<br/>
<input type="submit" Value= "Submit Resume" ONCLICK = "<?php insert($_Post['Name'], $_Post['Number'], $_Post['Resume']) ?> " >
</form>
 
The insert and DBConnect method are included within Jobs.php. here's the code for that as well:

DBConnect method

Code: Select all

 
 
function DBConnect(){
 
    $user = "root";
    $password = "ucfreeb12";
        $con = mysql_connect('localhost', $user, $password)
        or die("User/Password invalid");
    echo ($con);
 
}
 
insert method

Code: Select all

 
 
function insert($Name, $Number, $Resume ){
mysql_query("INSERT INTO AvailableJobs 
(Name, Number, Resume) VALUES('$Name', '$Number', '$Resume') ") 
or die(mysql_error());  
 
echo("Data Inserted");
}
 
for some reason if I click on the submit button it doesn't return "Data Inserted". Any ideas?
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: PHP noob question :P

Post by desmi »

You forward those posts like this:

formpage:

Code: Select all

<form action="jobs.php" method="post">
<input type="text" name="input1">
<input type="submit" value="Submit">
</form>
jobs.php

Code: Select all

$inputValue = $_POST['input1'];
//more code
Alan01252
Forum Newbie
Posts: 12
Joined: Sun Aug 03, 2008 3:20 pm

Re: PHP noob question :P

Post by Alan01252 »

Just to elaborate on the above poster.

So in your case in jobs.php it would be

Code: Select all

 
 
 function insert($Name, $Number, $Resume )
{
$Name = $_POST['Name'];
$Number = $_POST['Number'];
$Resume = $_POST['Resume'];
 
 mysql_query("INSERT INTO AvailableJobs
 (Name, Number, Resume) VALUES('$Name', '$Number', '$Resume') ")
 or die(mysql_error());  
  
 echo("Data Inserted");
}
 
SchweppesAle
Forum Newbie
Posts: 9
Joined: Thu Aug 14, 2008 11:40 pm

Re: PHP noob question :P

Post by SchweppesAle »

hmmm...I think I understand-how would I execute the insert method upon placing it into the Jobs.php file. An easier solution for me would be to simply create Insert.php then place the appropriate algorithm-I'd like to make use of functions if possible though. Is there anyway to force the submit button into doing this as well?
SchweppesAle
Forum Newbie
Posts: 9
Joined: Thu Aug 14, 2008 11:40 pm

Re: PHP noob question :P

Post by SchweppesAle »

blah, I just split everything up. It works fine, I'd still like to know if there's a way to execute methods via some html button though

basically I pulled the Jobs.php file apart and modulated the application by creating seperate php files. I then included the Query.php file in my index.php file

Query.php

Code: Select all

 
<?php
 
function Query(){
include("Connect.php");
DBConnect();
mysql_select_db("Jobs");
 
//selects *(everything) from the AvailableJobs table
$result = mysql_query("Select * FROM AvailableJobs")
or die(mysql_error());
 
/*stores everything into an array called $row, then  prints out each column.
PHP can apparently store different datatypes into the same array which is unbelievably cool*/
echo "Querying AvailableJobs Table within Jobs Database";
echo "<p />";
    while($row = mysql_fetch_array($result)){
        echo $row['Name'];
        echo "<br />";
        echo $row['Number'];
        echo "<br />";
        echo $row['Resume'];
        echo "<p/>";
    }
}
 
?>
 
 
my only problem is getting this to execute.

<input type ="submit" Value = "Query" ONCLICK = "<?php Query()?>">

grrr, run the function :banghead:
Geteburg
Forum Commoner
Posts: 25
Joined: Tue Aug 12, 2008 1:57 pm

Re: PHP noob question :P

Post by Geteburg »

You can't! PHP is server-side language which means that its run on server and not on client side. ONCLICK and similar stuff can be used with client-side language like JavaScript.
SchweppesAle
Forum Newbie
Posts: 9
Joined: Thu Aug 14, 2008 11:40 pm

Re: PHP noob question :P

Post by SchweppesAle »

lol, yea i just found out the hard way. it's ok though, I just used a standard html link, suites my purposes fine 8)
Post Reply