Forum Moderators: coopster

Message Too Old, No Replies

PHP submit form and display.

         

Karlinator

12:33 am on Sep 30, 2008 (gmt 0)

10+ Year Member



Well, I'm new to PHP and I'm looking to create a script which will allow me to select which row to change.

I'll explain a bit better.

I want a drop down menu with:
1 2 3 4
As the different options. Selecting option one will change the data in ID 1 in a MySQL, Selecting 2 will change the data in ID 2, etc.

I would then like a seperate PHP file to display only the data stored in each ID. As I want to be able to make my mIRC bots access this data directly.

Here's what I have so far, but I'm not sure if I'm on the right track.

This is my form.php

<form name="form1" method="post" action="connect.php">
<p>Select Script
<select name="bot" id="bot">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</p>
<p>
Data: <input name="data" type="text" id="data">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>

I also need a display.php and connect.php, however I'm unsure how to get them to work with the MySQL database.

I know the basis of the connection


$host = "localhost";
$user = "username";
$pass = "password";
$dbname = "database";

Could anyone please help me?

Thanks
~Karl

grallis

1:27 am on Sep 30, 2008 (gmt 0)

10+ Year Member



What are you using the bots for?

Karlinator

11:52 am on Sep 30, 2008 (gmt 0)

10+ Year Member



mIRC.

andrewsmd

12:28 pm on Sep 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have PEAR installed you can require once the db.php and then use this nice little script I have if you don't have the db.php just download it. Here is the connection script, I saved this file as connection.php but you can name it whatever you want.
<?php
require_once "DB.php";

//This function returns a connection to our database on the CS Server
function connectDB(){
$user = ""; //put your username here
$psswd = "";//put your password here
$host = "";//put your host here i.e. localhost if it's on your machine
$dbn = "";//put the name of your database here

$conn = DB::connect("mysql://{$user}:{$psswd}@{$host}/{$dbn}");
if (DB::isError($conn)){
print "Connect Failed" . "\n";
die($conn->getMessage() . "\n");
}
return $conn;
}
?>
//This function queries the database that it is passed as a connection
//with the query that it is passed
function queryDB($conn, $query){
$result = $conn->query($query);
if(DB::isError($result))
return 0;

return $result;
}
now if you saved it as connection.php require that in any file you want to connect to your database with. Then when you want to query your database you put this in. The reason this is nice because since your using more than one file if anything should change on your MySQL DB you can just edit the connection.php file and it works for all of your other files

$query = "Select Some_Column from Some_Table where Something = 'someText' order by 'Some_Column' ASC;";
//that query can be anything you want it to be I just gave you
//an example one

//now set result = to this
$result = queryDB(connectDB(), $query);

//now if you wanted to show all of the results
//you type this you can format this however you want
//this will just echo them you could put in html tags
//or css tags or anything of that nature
while($row = $result->fetchRow(DB_FETCHMODE_ASSOC)){
echo($row['Some_Column_Here'];
}

let me know if you need anymore help

Karlinator

12:37 pm on Sep 30, 2008 (gmt 0)

10+ Year Member



I don't have PEAR installed.

andrewsmd

1:21 pm on Sep 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PEAR is an extension for PHP. These days PEAR is included with PHP, but you need to install it yourself. I use PEAR on all my PHP developments.

Ok.. Installing PEAR isn’t bad, here is what you do:

Open a command line window (i.e. Start->Run->cmd)
Go to the PHP directory, in my case C:\php. Type go-pear.bat. Follow the instructions.
The PEAR extension get installed in C:\php\PEAR directory.
Once PEAR is installed, go to the php.ini file in your Apache2 directory. Find the
Code:

;include_path = ".;c:\\php\\includes"

Remove the semi-colon (to un-comment it), and then add C:\php\PEAR to it
Code:

include_path = ".;c:\\php\\includes;C:\\php\\PEAR"

Karlinator

2:06 pm on Sep 30, 2008 (gmt 0)

10+ Year Member



The problem is I'm using Linux shared hosting, so I'm unsure if I can install it or not.

andrewsmd

3:13 pm on Sep 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well who is hosting your php server. I would imagine if it is something like that, then PEAR is probably already installed.