|
 |
|
|
02-13-2005, 07:03 PM
|
Database Screwed Up...
|
Posts: 340
Name: Jon
Location: New York
|
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
|
|
|
|
02-13-2005, 11:52 PM
|
|
Posts: 31
|
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.
|
|
|
|
02-14-2005, 01:11 AM
|
|
Posts: 36
|
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..
|
|
|
|
02-14-2005, 07:30 AM
|
|
Posts: 340
Name: Jon
Location: New York
|
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
|
|
|
|
02-14-2005, 09:20 PM
|
|
Posts: 340
Name: Jon
Location: New York
|
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
|
|
|
|
02-14-2005, 11:17 PM
|
|
Posts: 36
|
|
|
|
|
02-15-2005, 04:14 PM
|
|
Posts: 340
Name: Jon
Location: New York
|
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
|
|
|
|
|
« Reply to Database Screwed Up...
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|