Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Database Screwed Up...
Old 02-13-2005, 07:03 PM Database Screwed Up...
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
Hello,

I am creating a site to allow me to update/insert/delete clan member records from php. well i got the script to input data to the data base and it is all screwed up!
Symptoms:

First name = first name
last name = email
steamid = blank
clanname = blank
email = blank
joindate = 0000-00-00

as you can see when information is put in not all of it gets to the db. here is the script
PHP Code:
<?php

require_once ('dbconnect.php');

$success 1;

$f_name $_POST['f_name'];
$l_name $_POST['l_name'];
$steam_id $_POST['steam_id'];
$clannme $_POST['clan_name'];
$email $_POST['email'];
$joindate $_POST['join_date'];

$ins_str mysql_query("INSERT INTO memberinfo (id, f_name, l_name, Steam_ID, ClanName, JoinDate, email) VALUES('', '$f_name', '$l_name', '$steam_id', '$clanname', '$joindate', '$email')");

echo 
$ins_str;

if (
mysql_query ($ins_str)) {
    
$success 0;
    echo 
'Problem saving records to the database';
    echo  
mysql_error();
} else {
    echo 
'Record was saved successfully. Refreshing display...';
    
?><head><META HTTP-EQUIV="refresh" content="2;URL=index.php?p=veiwmem"></head><?php
}


mysql_close();
?>
i have checked & checked agian the relatives between the form & script & all are Green light to go (meaning okay) and the same thing is with my update info script
update info (part 1)
PHP Code:
 <?php
require_once('dbconnect.php');
$id=$_GET['id'];

$query=" SELECT * FROM memberinfo WHERE id='$id'";
$result mysql_query($query);
$num mysql_numrows($result);
mysql_close();

$i=0;
while (
$i $num) {
$first=mysql_result($result,$i,"f_name");
$last=mysql_result($result,$i,"l_name");
$clanname=mysql_result($result,$i,"clanname");
$Steam_ID=mysql_result($result,$i,"Steam_ID");
$join_date=mysql_result($result,$i,"join_date");
$email=mysql_result($result,$i,"email");
$auto_id=mysql_result($result,$i,"id");
?>

<form action="update-form.php" method="post">
<input type="hidden" name="ud_id" value="<? echo $id?>">
First Name: <input type="text" name="ud_f_name" value="<? echo $f_name?>"><br>
Last Name: <input type="text" name="ud_l_name" value="<? echo $l_name?>"><br>
Phone Number: <input type="text" name="ud_steam_id" value="<? echo $Steam_ID?>"><br>
Mobile Number: <input type="text" name="ud_clanname" value="<? echo $clanname?>"><br>
Fax Number: <input type="text" name="ud_join_date" value="<? echo $join_date?>"><br>
E-mail Address: <input type="text" name="ud_email" value="<? echo $email?>"><br>
<input type="Submit" value="Update">
</form>
<?php
++$i;
}
?>
part 2
PHP Code:
<?php
require_once ('dbconnect.php');
$ud_f_name $_POST['ud_f_name'];
$ud_l_name $_POST['ud_l_name'];
$ud_clanname $_POST['ud_clanname'];
$ud_SteamID $_POST['ud_Steam_ID'];
$ud_join_date $_POST['ud_join_date'];
$ud_email $_POST['ud_email'];
$ud_id $_POST['ud_id'];

$query="UPDATE memberinfo SET f_name='$ud_f_name', l_name='$ud_l_name', clanname='$ud_clanname', SteamID='$ud_steamid', JoinDate='$ud_join_date', email='$ud_email' WHERE id='$ud_id'";

mysql_query($query);

    echo 
'Record was saved successfully. Refreshing display...';
    
?><head><META HTTP-EQUIV="refresh" content="2;URL=index.php?p=veiwmem"></head><?php
    mysql_close
();
?>
the update is split accross 2 pages
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
 
Register now for full access!
Old 02-13-2005, 11:52 PM
Experienced Talker

Posts: 31
Trades: 0
I have a question in your first code snippet.

Why is $ins_str declared as a variable holding the mysql_query() and its commands, but yet in the next if-else statement, you put

if (mysql_query($ins_str))

meaning you put a mysql_query() inside a mysql_query(), which doesn't look right to me.
yaoherm50 is offline
Reply With Quote
View Public Profile
 
Old 02-14-2005, 01:11 AM
Experienced Talker

Posts: 36
Trades: 0
it should be:

PHP Code:
$ins_str "INSERT INTO memberinfo (id, f_name, l_name, Steam_ID, ClanName, JoinDate, email) VALUES('', '$f_name', '$l_name', '$steam_id', '$clanname', '$joindate', '$email')";

if (
mysql_query ($ins_str)) {
   echo 
"goodboy";
}else{
   echo 
"badboy";

gonna try to set up a pseudo code for the if statement so you see the workings of a if statement. (first try on pseudo code so bare with me)

if (mysql_query ($ins_str)) { // if all is well, execute the next lines

echo "goodboy"; // line to execute if all is well

}else{ // if the query didnt go right execute the next lines

echo "badboy"; // line to execute if things went bad
}


as it is now you generate a error if the query goes through and everything is fine. you are doing things backwards. Also you have some typos in your code, wich you should try to fix.

Also may i ask where you use the variable $success? just out of curiosity...

EDIT: typo's and a question

Last edited by Lazyleg; 02-14-2005 at 01:23 AM..
Lazyleg is offline
Reply With Quote
View Public Profile
 
Old 02-14-2005, 07:30 AM
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
i got the code directly from a php/mysql tutorial site and i attempted to modify it which it did work now it does to a point were the varibles in the db are all screwed up...

the $success = 1; i think that is to validate if the msql_query went through or not
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 02-14-2005, 09:20 PM
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
i am still tweaking it but i am still falling now it adds the info to the db but it is still screwed completly up. the echo is Connected Successfully Problem Saving Record to the Db.

Current Code
PHP Code:
<?php

require_once ('dbconnect.php');

$success 1;

$f_name $_POST['f_name'];
$l_name $_POST['l_name'];
$steam_id $_POST['steam_id'];
$clannme $_POST['clan_name'];
$email $_POST['email'];
$joindate $_POST['join_date'];

 
$ins_str "INSERT INTO memberinfo (id, f_name, l_name, Steam_ID, ClanName, JoinDate, email) VALUES('', '$f_name', '$l_name', '$steam_id', '$clanname', '$joindate', '$email')";

mysql_query $ins_str;

if (
mysql_query ($ins_str)) {
    
$success 0;
    echo 
'Problem saving records to the database';
    echo  
mysql_error();
} else {
    echo 
'Record was saved successfully. Refreshing display...';
    
?><head><META HTTP-EQUIV="refresh" content="2;URL=index.php?p=veiwmem"></head><?php
}


mysql_close();
?>
The headers do not worry they are called without headers allready sent errors
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 02-14-2005, 11:17 PM
Experienced Talker

Posts: 36
Trades: 0
Lazyleg is offline
Reply With Quote
View Public Profile
 
Old 02-15-2005, 04:14 PM
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
finally got tired of working on it so i download a program that is called PHPMaker and that set up the pages i needed for add/editing/removeing & veiwing mysql db
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Reply     « Reply to Database Screwed Up...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.83081 seconds with 12 queries