Current location: Hot Scripts Forums » Programming Languages » PHP » MySQL Questions


MySQL Questions

Reply
  #1 (permalink)  
Old 04-06-06, 11:40 AM
KeYBLeR KeYBLeR is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Question MySQL Questions

Hello, I'll say it right now, I really know nothing about MySQL.

Anyways, This is how I'm creating a mysql table, using a install script. (I think) I want to create a mysql database that the ID does not change, I think it has to do with this part, "unsigned NOT NULL auto_increment"

PHP Code:

$create "CREATE TABLE list (

id int(11) unsigned NOT NULL auto_increment,
name varchar(50) NOT NULL default '',
email varchar(50) NOT NULL default '',
PRIMARY KEY  (id)
) TYPE=MyISAM;"
;

mysql_query($create) or die ("Could not create tables because ".mysql_error());
echo(
"Installation Complete!<BR><a href=index.php>here</a></br>"); 
So, what I'm thinking is, anything I want to put into mysql database, I need to create each entry using this email varchar(50) NOT NULL default '', and then nextitem varchar(50) NOT NULL default '',

Also, whats, PRIMARY KEY (ID), I'm confused to what that is, and TYPE=MyISAM

Thanks for helping
Keith
Reply With Quote
  #2 (permalink)  
Old 04-07-06, 11:06 AM
IndyTim IndyTim is offline
Newbie Coder
 
Join Date: Aug 2003
Location: Indianapolis, Indiana USA
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Very basically, your primary key is a unique way of identifying each record. At each insertion (writting a new record), the primary key value will advance automatically by one.

This approach will allow you to have multiple occurrences of your text fields. It is also much more efficient to use a numeric primary key as it usually occupies less storage space within your tables vs say a text-type of field.

The final thing to consider as you go down the path of database development is that a numeric primary key will allow you to do good relational linking between tables as your world gets more complicated (hey it's fun .

Hope this answers your question.

IndyTim
__________________
Believe those who are seeking the truth; doubt those who find it.
-Andr Gide
Reply With Quote
  #3 (permalink)  
Old 04-07-06, 01:23 PM
dantol dantol is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
alternatively, if your database got messed up during unsuccessful installation, you can drop it and do a clean install again.

It will save you time and nerves.
__________________
Dantol.com
Reply With Quote
  #4 (permalink)  
Old 04-08-06, 11:31 AM
KeYBLeR KeYBLeR is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Question Having Trouble

Hello, I'm having trouble with the product_id value being put into the database, then being shown when viewing the database.

heres my code to install the script
PHP Code:

include("config_settings.php");

if(
$_GET['install'] == "go"){
$create "CREATE TABLE list (
product_id varchar(7) NOT NULL default '',
product_name varchar(50) NOT NULL default '',
product_description varchar(50) NOT NULL default '',
product_price varchar(50) NOT NULL default '',
product_weight varchar(50) NOT NULL default '',
PRIMARY KEY  (product_id)
) TYPE=MyISAM;"
;
mysql_query($create) or die ("Could not create tables because ".mysql_error());
echo(
"Installation Complete!<BR><a href=index.php>here</a></br>");

}else{
echo(
"
<form action=\"?install=go\" method=\"POST\">
<table width=\"400\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
<tr><td>&nbsp;</td><td><div align=\"right\"><input type=\"submit\" value=\"Install\" /></div></td></tr>
</table>
</form>
"
);

Heres the code for viewing and adding to the database,
PHP Code:

include ("config_settings.php");


if(
$_GET['product'] == "add"){
// START // Adding User To Database

$query "SELECT product_id FROM list WHERE product_id = '$product_id'";
    
$product_id $_POST['product_id'];
    
$result mysql_query($query);
    if(
mysql_num_rows($result) != 0) {
    echo(
"Number already exisit");
} else {
$sql "INSERT INTO `list` (`product_id`) VALUES ('')";
    
$result mysql_query($sql) or die ("Not working try again");
    if(
$result) {
    echo(
"Should be added!");
}
}

}elseif(
$_GET['product'] == "view"){
echo(
"<table align=left cellpadding=0 cellspacing=0><tr><td width=\"50px\" align=center><font class=menu><u>ID #</u></font></td><td width=\"300px\"><font class=menu><u>Name</u></font></td><td width=\"350px\"><font class=menu><u>eMail</u></font></td><td width=\"100px\"><font class=menu><u>Action</u></font></td></table><BR>");
$result mysql_query("SELECT * FROM list");
while(
$row mysql_fetch_array($result)) {
$product_id "$row[product_id]";
echo(
"<table align=left cellpadding=0 cellspacing=0><tr><td align=\"center\" width=\"50px\"><font class=textsmall>$row[product_id]</font></td><td width=\"300px\"><font class=textsmall>name</font></td><td width=\"350px\"><a href=\"?page=sendemail&sendemail=single&email=$email\"><font class=textsmall>email</font></a></td><td width=\"100px\"><font class=textsmall><a href=?page=members&members=delete&id=$row[product_id] onClick=\"return confirm('Are you sure to delete $email from the list?');\">Delete</a></font></td></tr></table><BR>");
}

}else{
echo(
"
<form action=\"?product=add\" method=\"POST\">
<input type=text name=product_id /><BR>
<input type=submit>
</form>
"
);

It does not carry the product_id.
So when I attempt to add a product_id, no value is given, on the second attempt, it says number already exist

Kinda confused on this one, Thanks Keith
Reply With Quote
  #5 (permalink)  
Old 04-10-06, 02:30 PM
KeYBLeR KeYBLeR is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Maybe I can make this simpler,

Does anyone have a basic MySQL template for, adding a few values into a database with HTML FORM INPUTS, + viewing the database with HTML.


Thanks Keith
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
mysql questions maddude PHP 2 08-17-05 06:27 PM
php MySQL and variable formats - questions. irfaan PHP 0 07-18-05 12:35 AM
Several questions for PHP and MySql starting in Windows XP artaco2000 PHP 4 10-14-04 12:25 PM
questions in mysql procedure scorpioy PHP 1 09-07-04 06:41 AM


All times are GMT -5. The time now is 07:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.