Log in

View Full Version : Need some verification



Titan85
12-26-2006, 09:42 PM
Hello, i am working on a script that will take info from a form and input it into a mysql database for later use. I am looking to make it so that I can search for the title or description and it will return the corresponding data. I know how to make forms and process them in PHP, but I am not sure on how to use MySQL to hold the data because I have only used .txt files in the past.

I believe the first step is to create the mysql columns like this:
CREATE TABLE `job_recorder` (
`id` mediumint(8) unsigned NOT NULL auto_increment,
`job_title` varchar(20) NOT NULL default '',
`client_email` varchar(20) NOT NULL default '',
`client_name` varchar(20) NOT NULL default '',
`description` varchar(20) NOT NULL default '',
`price` varchar(20) NOT NULL default '',
) ENGINE=MyISAM ; If anything in there is wrong, i would appreciate someone letting me know ;) .

The next step should be to insert the data into the database like this:
INSERT INTO `job_recorder` VALUES (1, '$job_title', '$client_email', '$client_name', '$description', '$price',
'');Correct?

And to call it up again I would do:
<?php
$query = mysql_query("SELECT * FROM `site_config`");
while ($get = mysql_fetch_array($query))
{
echo '<title>$get[job_title]</title>';
echo 'Email: $get[client_email]';
echo 'Name: $get[client_name]';
echo 'Description: $get[description]';
echo 'Price: $get[price]';
}
?> Correct?

I guess this kinda turned out to be just me needing verification on if my ideas are right or not. But i do have a few questions, if I run this more than once, will it insert a second entry so that I can call that one too? Also, how might I go about searching for a certain entry?

djr33
12-27-2006, 03:54 AM
Upon quick glance, looks like you're definitely doing the right general thing.
Note that your table names don't match.
At first, it's 'job_recorder', then, later 'site_config'. If they are supposed to be the same, change one.

Also, here's a good reference for this stuff. I found it helpful.
http://php-mysql-tutorial.com

Titan85
12-27-2006, 06:47 AM
Upon quick glance, looks like you're definitely doing the right general thing.
Note that your table names don't match.
At first, it's 'job_recorder', then, later 'site_config'. If they are supposed to be the same, change one.

Also, here's a good reference for this stuff. I found it helpful.
http://php-mysql-tutorial.comThanks for the help, and thanks for noticing the difference in names, i'll be sure to fix that ;)

Titan85
12-27-2006, 03:40 PM
well, i set the script up and ran it, but ran into a problem. When I try to display the data, i get: Email: $get[client_email]Name: $get[client_im]Description: $get[description]Price: $get[price]Conversation Link: $get[conversation_link]. Any idea why? Here is my code for displaying it:
<?php
include("config.php");
$query = mysql_query("SELECT * FROM `job_recorder`");
while ($get = mysql_fetch_array($query))
{
echo'
Title: $get[job_title]
<br />
Email: $get[client_email]
<br />
Name: $get[client_im]
<br />
Description: $get[description]
<br />
Price: $get[price]
<br />
Conversaton Link: $get[conversation_link]
<br />
';
}
?>

mwinter
12-28-2006, 02:26 AM
<?php
include("config.php");
$query = mysql_query("SELECT * FROM `job_recorder`");
while ($get = mysql_fetch_array($query))
{
echo'
Title: $get[job_title]
<br />
Email: $get[client_email]
<br />
Name: $get[client_im]
<br />
Description: $get[description]
<br />
Price: $get[price]
<br />
Conversaton Link: $get[conversation_link]
<br />
';
}
?>


You have the form of quotes backwards: single quotes don't expand variables.



<?php
include('config.php');

$query = mysql_query('SELECT * FROM `job_recorder`');
while ($get = mysql_fetch_array($query)) {
echo "Title: {$get['job_title']}<br>\r\n"
. "Email: {$get['client_email']}<br>\r\n"
. "Name: {$get['client_im']}<br>\r\n"
. "Description: {$get['description']}<br>\r\n"
. "Price: {$get['price']}<br>\r\n"
. "Conversation Link: {$get['conversation_link']<br>\r\n";
}
?>

I suggest you read the section on strings (http://uk.php.net/manual/en/language.types.string.php), as well as Why is $foo[bar] wrong? (http://uk.php.net/manual/en/language.types.array.php#language.types.array.foo-bar) in the PHP manual.

Mike


The forum breaks the last escape sequence in the code I posted, for some reason. It should, of course, be \r\n.

Titan85
12-28-2006, 04:34 PM
ok, i got it working with the new way you showed me, but now when i try to create tables in mysql, i get the error: "#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ENGINE=MyISAM' at line 9". Here is the code i am using:
CREATE TABLE `job_recorder` (
`job_title` varchar(20) NOT NULL default '',
`client_email` varchar(40) NOT NULL default '',
`client_im` varchar(20) NOT NULL default '',
`description` varchar(100) NOT NULL default '',
`conversation_link` varchar(70) NOT NULL default '',
`price` varchar(20) NOT NULL default '',
`date_started` varchar(20) NOT NULL default '',
) ENGINE=MyISAM ;I don't know what to do with the ENGINE=MyISAM since it worked before.