Jump to content

Jim R

Members
  • Posts

    988
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Jim R

  1. And since changing to the escape string, it won't Insert either.
  2. I'm getting the same error:
  3. Ok...I used the IF statement as you described it. It's Inserting just fine if doesn't find a match. If it does find a match, I'm getting an error. It's looking for a matching first name, last name and school, and if found, it's supposed to Update the information. Here is the error: Here is the code I'm using: <?php $con = mysql_connect("localhost","jwrbloom_","redcoach"); if (!$con) { die('Could not connect: ' . mysql_error()); } $nameFirst=$_POST['nameFirst']; $nameLast=$_POST['nameLast']; $email=$_POST['email']; $addressHome=$_POST['addressHome']; $stateHome=$_POST['stateHome']; $zipHome=$_POST['zipHome']; $phoneHome=$_POST['phoneHome']; $phoneMobile=$_POST['phoneMobile']; $school=$_POST['school']; $grade=$_POST['grade']; $coachSchool=$_POST['coachSchool']; $feet=$_POST['feet']; $inshces=$_POST['inches']; mysql_select_db("jwrbloom_wpMIB", $con); $result = mysql_query( "SELECT id FROM fallLeague10 WHERE nameFirst='$nameFirst' AND nameLast='$nameLast' AND school='$school' "); if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); // update existing row $result = mysql_query("UPDATE fallLeague10 SET confirm='y', email='$email', addressHome='$addressHome', stateHome='$stateHome', zipHome='$zipHome', phoneHome='$phoneHome', phoneMobile='$phoneMobile', coachSchool='$coachSchool', feet='$feet', inches='$inches' WHERE id='".$row['id']."'"); } else { $result="INSERT INTO fallLeague10(confirm,nameFirst,nameLast,email,addressHome,stateHome,zipHome,phoneHome,phoneMobile,school,grade,coachSchool,feet,inches) VALUES ('y','$_POST[nameFirst]','$_POST[nameLast]','$_POST[email]','$_POST[addressHome]','$_POST[stateHome]','$_POST[zipHome]','$_POST[phoneHome]','$_POST[phoneMobile]','$_POST[school]','$_POST[grade]','$_POST[coachSchool]','$_POST[feet]','$_POST[inches]')"; }
  4. Neil, When you look at the Select vs. what I would otherwise Insert I have showed what I'm trying to do. I'm trying to Update the rest of it into an already existing record. My issue is getting it do differentiate between when to Insert vs. when to Update. I know how to use Select, Insert and Update separately. I'm just trying to figure out the syntax of the IF, ELSE (ELSEIF). I've asked twice before about the syntax of the IF and establishing the right condition.
  5. Would this work: (I need to change the echo part of the IF statement into my UPDATE code) <?php $con = mysql_connect("localhost","jwrbloom_","redcoach"); if (!$con) { die('Could not connect: ' . mysql_error()); } $nameFirst=$_POST['nameFirst']; $nameLast=$_POST['nameLast']; $school=$_POST['school']; mysql_select_db("jwrbloom_wpMIB", $con); $result = mysql_query( "SELECT * FROM fallLeague10 WHERE nameFirst='$nameFirst' AND nameLast='$nameLast' AND school='$school' "); $aff_rows = mysql_affected_rows($result); if( $aff_rows === 1 ) { echo 'One row was updated.'; // Or do something else, whatever . . . } else { $sql="INSERT INTO fallLeague10(nameFirst,nameLast,email,addressHome,stateHome,zipHome,phoneHome,phoneMobile,school,grade,coachSchool,feet,inches) VALUES ('$_POST[nameFirst]','$_POST[nameLast]','$_POST[email]','$_POST[addressHome]','$_POST[stateHome]','$_POST[zipHome]','$_POST[phoneHome]','$_POST[phoneMobile]','$_POST[school]','$_POST[grade]','$_POST[coachSchool]','$_POST[feet]','$_POST[inches]')"; } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } header( 'Location: /fall-league/payment' ); mysql_close($con) ?>
  6. I have the SELECT part already, as well as the INSERT portion after an ELSEIF. My question gets to how do I set up the IF portion? I read what you posted above, but I'm not sure what applies to me or what is mostly general recommendation.
  7. I know, but the insert code was left over from last year's entries. Here is the correct version: <?php $con = mysql_connect("localhost","db_name","db_password"); if (!$con) { die('Could not connect: ' . mysql_error()); } $nameFirst=$_POST['nameFirst']; $nameLast=$_POST['nameLast']; $school=$_POST['school']; mysql_select_db("db_table_name", $con); $result = mysql_query( "SELECT * FROM fallLeague10 WHERE nameFirst='$nameFirst' AND nameLast='$nameLast' AND school='$school' "); $sql="INSERT INTO fallLeague10(nameFirst,nameLast,email,addressHome,stateHome,zipHome,phoneHome,phoneMobile,school,grade,coachSchool,feet,inches) VALUES ('$_POST[nameFirst]','$_POST[nameLast]','$_POST[email]','$_POST[addressHome]','$_POST[stateHome]','$_POST[zipHome]','$_POST[phoneHome]','$_POST[phoneMobile]','$_POST[school]','$_POST[grade]','$_POST[coachSchool]','$_POST[feet]','$_POST[inches]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } header( 'Location: /fall-league/payment' ); mysql_close($con) ?>
  8. Crap...I'm not. My fault. When I put that PHP page online, it will all be fallLeague10.
  9. Any help on what the IF statement should look like? What you have above isn't registering well in my head right now. Not sure about 'rows' and I'm not using ID's. Sometimes I have mental blocks when it comes to coding.
  10. Here is what I have so far, realizing I still need the IF and ELSEIF statements, as well as the UPDATE. <?php $con = mysql_connect("localhost","db_name","db_password"); if (!$con) { die('Could not connect: ' . mysql_error()); } $nameFirst=$_POST['nameFirst']; $nameLast=$_POST['nameLast']; $school=$_POST['school']; mysql_select_db("db_table_name", $con); $result = mysql_query( "SELECT * FROM fallLeague10 WHERE nameFirst='$nameFirst' AND nameLast='$nameLast' AND school='$school' "); // IF statement? //UPDATE code //ELSEIF $sql="INSERT INTO fallLeague09reg(nameFirst,nameLast,email,addressHome,stateHome,zipHome,phoneHome,phoneMobile,school,grade,coachSchool,feet,inches) VALUES ('$_POST[nameFirst]','$_POST[nameLast]','$_POST[email]','$_POST[addressHome]','$_POST[stateHome]','$_POST[zipHome]','$_POST[phoneHome]','$_POST[phoneMobile]','$_POST[school]','$_POST[grade]','$_POST[coachSchool]','$_POST[feet]','$_POST[inches]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } header( 'Location: /fall-league/payment' ); mysql_close($con) ?>
  11. So instead of SELECT id FROM users WHERE name='Neil' It should be???? ....WHERE nameFirst='$_POST['nameFirst']' && nameLast='$_POST['nameLast']' && school=$_POST['school'] I don't get how using the ID helps me, and I'm trying to match information from form not another table.
  12. After looking at this a little more, I would rather not use Replace. It will increase the number of rows I have with every entry. I like to keep track of how many individuals are actually in my database, so I can compare from year to year. If it gets right down to it, I could use it, but I'd prefer not. Neil, I think I can figure out the query syntax if I understand more of what you're talking about. If I SELECT to see if the record already exists, how do I create conditions? Are we talking about IF statements or WHERE statements within the query? My query would look like: SELECT * from TableA UPDATE SET (column information) WHERE TableA = $_POST['value']
  13. @BH, I'll look more into that for sure. @Neil, do I just run a Select * or just the fields I want to check (nameFirst, nameLast, school)? I guess this is the direction that confuses me.
  14. I'm pulling information from a form that INSERTS into my database. I think I have the UPDATE syntax down for when a User enters information that is already in the database. UPDATE....WHERE....FormA = ColumnA...AND...FormB = ColumnB. What I need is help with is if it's not updating an existing User's information, getting it to insert a new row. Do I set it up the same way as the update, just with INSERT...WHERE...FormA == ColumnA AND FormB == ColumnB?
  15. (I was typing my response as you were typing your second one, but at least I'm following your logic.) Is there MySQL/PHP command I should use, or am I basically using IF...THEN statements?
  16. Knowing the players very well, there won't be an instance where there is identical player names at different schools, let alone the same schools, so I would be safe there. From there, what you're saying is I'm checking the data already there, and if it finds identical information, I need to UPDATE, and if I don't, I need to INSERT?
  17. I haven't tried any code for this specifically, mostly because I'm not sure where to start. Here is the code I use for the form I have set up now, which enters all information into a second database. I'd like to check the database I have set up for invitees, and if there is already a record of that player, update his entry with the additional information asked for in the form. <form id="entryFall" action="/form/dbenter.php" method="post"> <table border="0" width="500"> <tbody> <tr> <td colspan="4"> <div><strong><span style="font-size: x-small;">Fall Varsity League</span></strong></div></td> </tr> <tr> <td colspan="4"> <div style="text-align: center;"><strong>Online Entry Form </strong> Address and phone information made available only to college coaches. If you have already registered and are trying to pay online, please click the Payment link above in the Fall League menu.</div></td> </tr> <tr> <td><strong>First Name*:</strong></td> <td colspan="3"><input maxlength="30" name="nameFirst" size="30" type="text" /></td> </tr> <tr> <td><strong>Last Name</strong>*:</td> <td colspan="3"><input maxlength="30" name="nameLast" size="30" type="text" /></td> </tr> <tr> <td><strong>Email*:</strong></td> <td colspan="3"><input maxlength="50" name="email" size="30" type="text" /></td> </tr> <tr> <td><strong>Address:</strong></td> <td colspan="3"><input maxlength="50" name="addressHome" size="30" type="text" /></td> </tr> <tr> <td><strong>State:</strong></td> <td colspan="3"><input maxlength="5" name="stateHome" size="2" type="text" /></td> </tr> <tr> <td><strong>Zip:</strong></td> <td colspan="3"><input maxlength="5" name="zipHome" size="6" type="text" /></td> </tr> <tr> <td><strong>Home Phone*:</strong></td> <td colspan="3"><input maxlength="13" name="phoneHome" size="13" type="text" /></td> </tr> <tr> <td><strong>Mobile Phone</strong>*:</td> <td colspan="3"><input maxlength="13" name="phoneMobile" size="13" type="text" /></td> </tr> <tr> <td><strong>High School*:</strong></td> <td colspan="3"><label></label> <input maxlength="30" name="school" size="30" type="text" /></td> </tr> <tr> <td><strong>Grade*:</strong></td> <td colspan="3"><input maxlength="2" name="grade" size="5" type="text" /></td> </tr> <tr> <td><strong>Varsity Coach*: </strong></td> <td colspan="3"><input maxlength="30" name="coachSchool" size="30" type="text" /></td> </tr> <tr> <td><strong>Feet*:</strong></td> <td width="10%"><input maxlength="1" name="feet" size="3" type="text" /></td> <td width="13%"><strong>Inches*:</strong></td> <td width="51%"><input maxlength="2" name="inches" size="3" type="text" /></td> </tr> <tr> <td></td> <td colspan="3"><input name="success" type="hidden" value="http://www.indybasketballevents.com/thankyou.php" /> * required</td> </tr> <tr> <td></td> <td colspan="3"></td> </tr> <tr> <td></td> <td colspan="3"><label for="Submit"></label> <input id="Submit" name="Submit" type="submit" value="Submit" /></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> </tr> </tbody></table> </form>
  18. Not sure how to even search for what I'm looking for, which is to say I'm really in need of guidance. I have a pre-populated database that I set up with about 260 names in it. It also has information like, height (basketball players) and high school. It's a list of kids I mean to invite to play in a league. From there, they will actually come to the league's site and register. I'd like for my form to check to see if they are already in the database, and if they are just add personal information, like email and phone number. If they are not, I'd like for the form to enter all of the information (name, school, etc).
  19. I searched, but I rarely can make much of other people's problems when it comes to databases and PHP. Here is what I'm trying to do: I have a datatable full of names of basketball players. I have a datatable that is going to store links to videos to basketball players. Here is the query I have: $query = 'SELECT pr.*,v.* FROM (wp_playerRank) as pr, (hhr_video) as v WHERE pr.nameFirst = v.name_first AND pr.nameLast = v.name_last ORDER BY v.id_vid DESC'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) There might be four or five video clips, as we start to compile this list over time. I want to echo information from the hhr_video table. I'm assuming with a FOREACH loop. Right?
  20. It worked. I didn't refresh my table. Here is the correct syntax: UPDATE wp_usermeta SET meta_key = REPLACE (meta_key,'wp_1_','wp_')
  21. UPDATE wp_usermeta SET meta_key = REPLACE (meta_key,"wp_1_","wp_") UPDATE wp_usermeta SET meta_key = REPLACE ('meta_key',"wp_1_","wp_") Either of those?
  22. Data inside the column. I'm trying to make values that start out with wp_1_ and have them just start wp_
  23. Still not catching how it works, just because everywhere I look it says something different. Here is what I tried: UPDATE REPLACE ('meta_key', 'wp_1_', 'wp_')
  24. The syntax is a little confusing. Am I using UPDATE, REPLACE or SELECT?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.