|
-
Mar 18th, 2008, 08:03 PM
#1
Thread Starter
Hyperactive Member
Show me where to start?
Sorry to ask all the stupid questions but I am a VB .NET person thrown into a PhP project...
Here is my scenario...
This site is just a simple membership site. The user goes to a page and browses users by State or "All Users" and when they find someone they want to add they click "Add Me". Sounds simple... but I have very little PhP experience so I am having trouble figuring out when the button "Add Me" is clicked where PhP jumps to to write the information to the database.
The database table is called "Friends" with the following fields: RecordID, Member, Friend, FirstName, LastName.
I have posted the PhP page (please note I didnt write this page) Can someone put a "Comment saying Start Here" or whatever may be necessary to show me the starting point... if you can get further in detail even better!
Thanks in advance!!
HTML Code:
<?php require_once('../Connections/conn.php'); ?><?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
$colname_rsUsers = "-1";
if (isset($_POST['state'])) {
$colname_rsUsers = (get_magic_quotes_gpc()) ? $_POST['state'] : addslashes($_POST['state']);
}
mysql_select_db($database_conn, $conn);
$query_rsUsers = sprintf("SELECT `FirstName`, `LastName`, eMail, State FROM members WHERE `state` = %s", GetSQLValueString($colname_rsUsers, "text"));
if ((isset($_POST["search_all_x"]) || isset($_POST["search_all"]))) {
$query_rsUsers = sprintf("SELECT `FirstName`, `LastName`, eMail, State FROM members");
}
$rsUsers = mysql_query($query_rsUsers, $connStory) or die(mysql_error());
$row_rsUsers = mysql_fetch_assoc($rsUsers);
$totalRows_rsUsers = mysql_num_rows($rsUsers);
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>User Search</title>
<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body bgcolor="#003366" onLoad="MM_preloadImages('images/search_all_over.gif')">
<div align="left">
<table border="0" width="668" cellspacing="0" cellpadding="0" height="364" id="table1" bordercolor="#003366">
<tr>
<td align="left" valign="top" width="668">
<form method="POST" action="<?php echo $editFormAction; ?>" >
<p><b><font color="#FFFFFF">S</font></b><font color="#FFFFFF"><b>earch By State: </b>
<select name="state" style="font-weight: 700">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</font><input name="search" type="image" onMouseOver="this.src='images/submit_over.gif';" onMouseOut="this.src='images/submit_on.gif';" value="Submit" src="images/submit_on.gif" align="bottom">
<input name="search_all" type="image" onMouseOver="this.src='images/search_all_over.gif';" onMouseOut="this.src='images/search_all_on.gif';" value="Submit" src="images/search_all_on.gif" align="bottom"></p>
</form><table width="636">
<?php do { ?>
<tr><form method="POST" name="member" action="<?php echo $editFormAction; ?>">
<td width="164"><font color="#FFFFFF"><?php echo $row_rsUsers['FirstName']; ?>
<input type="hidden" name="first" value="<?php echo $row_rsUsers['FirstName']; ?>">
</font></td>
<td width="166"><font color="#FFFFFF"><?php echo $row_rsUsers['LastName']; ?>
<input type="hidden" name="last" value="<?php echo $row_rsUsers['LastName']; ?>">
</font></td>
<td width="144"><font color="#FFFFFF"><?php echo $row_rsUsers['eMail']; ?>
<input type="hidden" name="eMail" value="<?php echo $row_rsUsers['eMail']; ?>">
</font></td>
<td width="142" align="center" valign="middle">
<?php if ($row_rsUsers['eMail'] != "") {
echo '<input type="submit" name="member" value="Add Me!">';
}
?></td>
<input type="hidden" name="state" value="<?php echo $row_rsUsers['State']; ?>">
<input type="hidden" name="MM_insert" value="member">
</form>
</tr>
<?php } while ($row_rsUsers = mysql_fetch_assoc($rsUsers)); ?>
</table>
<p> </p></td>
</tr>
</table>
</div>
</body>
</html>
<?php
mysql_free_result($rsUsers);
?>
Last edited by Anjari; Mar 20th, 2008 at 01:53 PM.
-
Mar 20th, 2008, 01:57 PM
#2
Thread Starter
Hyperactive Member
Re: Show me where to start?
$editFormAction = $_SERVER['PHP_SELF'];
$colname_rsUsers = "-1";
if (isset($_POST['state'])) {
$colname_rsUsers = (get_magic_quotes_gpc()) ? $_POST['state'] : addslashes($_POST['state']);
}
mysql_select_db($database_conn, $conn);
$query_rsUsers = sprintf("SELECT `FirstName`, `LastName`, eMail, State FROM members WHERE `state` = %s", GetSQLValueString($colname_rsUsers, "text"));
if ((isset($_POST["search_all_x"]) || isset($_POST["search_all"]))) {
$query_rsUsers = sprintf("SELECT `FirstName`, `LastName`, eMail, State FROM members");
}
$rsUsers = mysql_query($query_rsUsers, $connStory) or die(mysql_error());
$row_rsUsers = mysql_fetch_assoc($rsUsers);
$totalRows_rsUsers = mysql_num_rows($rsUsers);
?>
I assume thats the code... any ideas why its not writing to my DB??
-
Mar 21st, 2008, 12:58 AM
#3
Hyperactive Member
Re: Show me where to start?
It seems like it is not writing to the DB because you are selecting data, not writing data to the DB.
To write to a new record to a DB you use insert.
http://w3schools.com/sql/sql_insert.asp
As for your code, I dont know... thats a lot of code to read... on top of that it seems your database design is very bad (but it might just be a misunderstanding).
http://en.wikipedia.org/wiki/Database_normalization
edit: also, to make your life easier. Turn on php error reporting (in php.ini somewhere) when on your development machine.
-
Mar 22nd, 2008, 12:35 AM
#4
Re: Show me where to start?
Also when posting PHP code, use the [php] [/php] tags to make it easier to read with Syntax highlighting
My usual boring signature: Something
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|