Jump to content

sofaman

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sofaman's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, I'm a newbie too, I think the code should look more like this, but some one will put us right if we are wrong !!! [code]$add_all = "INSERT INTO Equipment (ItemNo, Manufacturer, Model, SerialNo, Description) VALUES ('$ItemNo','$Manufacturer','$Model','$SerialNo','$Description')";[/code] BTW you also have a trailing } on line 25 ?? Try this: [code]<html> <body> // Set Mysql Variables <?php $host = 'localhost'; $user = 'root'; $pass = ''; $db = 'KenetInventory'; $table = 'Equipment'; // Set global variables to easier names $ItemNo = $_POST['ItemNo']; $Manufacturer = $_POST['Manufacturer']; $Model = $_POST['Model']; $SerialNO = $_POST['SerialNo']; $Description = $_POST['Description']; mysql_connect($host,$user,$pass) or die(mysql_error()); mysql_select_db(KenetInventory) or die(mysql_error()); $add_all = "INSERT INTO Equipment (ItemNo, Manufacturer, Model, SerialNo, Description) VALUES ('$ItemNo','$Manufacturer','$Model','$SerialNo','$Description')"; mysql_query($add_all) or die(mysql_error()); ?> </body> </html>[/code] Good luck and let me know how you get on
  2. [quote author=mjdamato link=topic=112598.msg457567#msg457567 date=1161802974] [b]sofaman[/], Did you try fixing the problems with the EOF usage as I explained? [/quote] I did try it, you was looking at an older code that was uploaded. Thanks for looking :D
  3. [code][quote author=redbullmarky link=topic=112598.msg457542#msg457542 date=1161800528] [code] $form_start="FORM METHOD=\"post\"ACTION= [/code] it doesnt have a closing quote, and doesnt really resemble HTML (no opening <, no space between the method and the action, no closing > and </form> anywhere to be seen, [/quote] Thank you for spotting that mistake with the opening < :( the closing </form> was cut out to show the if/else code was corrrect  ??? Ohh after all the code adjustments it's no longer the isset statement but line 77 [code]<TD COLSPAN="2">INPUT TYPE="submit"[/code] Here's the full code after a little more house keeping [code] <HTML> <HEAD> <STYLE> BODY {font-family:arial;} .error {font-weight:bold; color:#ff0000;} </STYLE> </HEAD> <BODY> <h2>Edit details:</h2> <?php // connect to database include 'db.php'; // has form been submitted? if ($_POST) { foreach ($_POST as $K => $V) {$v = trim($V) ;$$K = $v;} // Build UPDATE query $update = "UPDATE details SET user='$fn', model='$ln', engine='$en', bhp='$bn' WHERE Id=$id"; // execute query and check for success if (!mysqli_query($link, $update)) { $msg = "Error updating data"; } else { $msg = "Record Successfully updated:"; //write table row confirming data $table_row = "<TR> <TD>$fn</TD> <TD>$ln</TD> <TD>$en</TD> <TD>$bn</TD> </TR>"; } //if not posted, check that an id has been passed via the url } else { if (!isset($_GET['id'])) { $msg = "No user selected"; } else { $id = $_GET['id']; // Build and execute the query $select = "SELECT user, model, engine, bhp FROM details WHERE id=$id"; $result = mysqli_query($link, $select); // check that the record exits if (mysqli_num_rows($result)<1) { $msg = "No user with that ID found!"; } else { // set vars for the form code $form_start = "<FORM METHOD=\"post\" ACTION= \"" . $_SERVER['PHP_SELF'] . "\">"; $form_end = "<TR> <TD COLSPAN="2">INPUT TYPE="submit"     VALUE="submit changes" /></TD> <TD COLSPAN="2"><INPUT TYPE="reset"     VALUE="Cancel" /></TD> </TR>"; </form> // assign the results to an array while ($row = mysqli_fetch_array($result)) { $fn = $row['user']; $ln = $row['model']; $en = $row['engine']; $bn = $row['bhp']; write table row with form fields $table_row = "<TR> <TD><INPUT TYPE="text" NAME="fn" VALUE=$fn SIZE="127"/></TD> <TD><INPUT TYPE="text" NAME="ln"     VALUE=$ln SIZE="127"/></TD> <TD><INPUT TYPE="text" NAME="en"     VALUE=$en SIZE="127"/></TD> <TD><INPUT TYPE="text" NAME="bn" VALUE=$bn SIZE="4"/></TD> </TR>"; } // end if record exists' if } // end if ID given in url' if } // end if form posted' if } // close connection mysqli_close($link); // print error/success message echo(IsSet($msg)) ? "<div class=\"error\">$msg</div> : ""; ?> <!-- set up the table--> <TABLE BORDER="1" CELLPADDING="5"> <!-- Show start-of-frm code if form needed --> <? echo (IsSet($form_start)) ? $form_start : ""; ?> <INPUT TYPE="HIDDEN" NAME="id" VALUE="<? echo $id ?>" />   <tr>     <th>User Name</th>     <th>Model</th>     <th>Engine</th>     <th>BHP</th>   </tr> <!-- show appropriate table row code (none set if there errors) --> <? echo (IsSet($table_row)) ? $table_row : ""; ?> <!-- show end-of-form code if we are displaying the form --> <? echo (IsSet($form_end)) ? $form_end : "" ; ?> </TABLE> <br/> <a href="mod.php">Back to users list</a> </BODY> </HTML> ?> [/code] And a big thank you for your time :D [/code]
  4. In a bid to solve the if/else statements I've trimmed down the code to a bit, making sure I didn't delete any IF/Else or {}. I know the code is a little messy and I hate useing parts of other peoples codeing unless I know whats going on :( [code] <?php // connect to database include 'db.php'; // has form been submitted? if ($_POST) { // execute query and check for success if (!mysqli_query($link, $update)) { $msg = "Error updating data"; } else { $msg = "Record Successfully updated:"; } //if not posted, check that an id has been passed via the url } else { if (!isset($_GET['id'])) { $msg = "No user selected"; } else { $id = $_GET['id']; // check that the record exits if (mysqli_num_rows($result)<1) { $msg = "No user with that ID found!"; } else { // set vars for the form code $form_start="FORM METHOD=\"post\"ACTION= // assign the results to an array while ($row = mysqli_fetch_array($result)) { $fn = $row['user']; } } // end if record exists' if } // end if ID given in url' if } // end if form posted' if // close connection mysqli_close($link); [/code] To help, the basics about the code. On the HTML page previous to this one. A user logs in and is assigned an ID in the html code ww......co.uk/mod_user.php?id=1 (I know it's not  best way of doing it but it's a start for a novice and I'll do a more secure version when I learn how) This page takes the user id, creates a form from the database information. The user then alters the details in the form and submits it back into the database. I hope that helps a little as I'm pulling my hair out :( I bet when we/I find the error it's something really daft !!
  5. Thanks for helping :D I've re-aligned the code so it's more how [b]I[/b] was learned. It's in the link above. While you are helping, I'm going to re-write the code from scratch without the book. That should be fun but at least I will know whats going on with the code !!! I'd still love to know whats wrong with this code though !!
  6. Thanks for the advise, I've had a look at my IF statements and they seem fine :( I've uploaded the full code to a text file so not to waste space on here. [url=http://www.vxbits.co.uk/mod.txt]Click Here[/url] for full code
  7. Hello, I'm a newbie to PHP. I've created a database and can view and add information stored in it via PHP. I'm trying to modify the entries. I have the following code (mainly borrowed out the book I'm learning from) It's coming up with a parse error on line 49, if (!isset($_GET['id'])) { I've check every where I can think of (code and on here) and even change a few things but it always comes up with this error :( I'm using php5.0.2 and php desginer pro 2007 [code] // Build UPDATE query $update = "UPDATE details SET user='$fn', model='$ln', engine='$en', bhp='$bn' WHERE Id=$id"; // execute query and check for success if (!mysqli_query($link, $update)) { $msg = "Error updating data"; } else { $msg = "Record Successfully updated:"; //write table row confirming data $table_row = <<<EOR <TR>   <TD>$fn</TD>   <TD>$ln</TD>   <TD>$en</TD>   <TD>$bn</TD> </TR> EOR;   } //if not posted, check that an id has been passed via the url } else { if (!isset($_GET['id'])) {   $msg = "No user selected"; } else { $id = $_GET['id']; // Build and execute the query $select = "SELECT user, model,   engine, bhp FROM details WHERE Id=$id"; $result = mysqli_query($link, $select); [/code] Please help, full code can put posted or hosted as a text file if needed thank you Sofa
  8. Thank you so much they work a treat :D I've never programmed where I NEEDED to use uppercase. I must of missed the part in the book :( I think I will do the tutorials from this site next. Thanks again :D
  9. I'm new to php, I'm learning from a book at the minute. I'm running: apache web server 2.0.59 PHP 5.0.2 Mysql 5.0.24 (as a module not cgi) The same versions as what the book uses. I've installed a forum - no problems I've created a database useing the cmd line I can view the database in IE When I try to 'insert' into the database via IE I get the following with code: if ($_post) {   // create empty error variable   $msg = ""; I receive undefined variable _post so I tried : <? $browser = $_server['php_shelf']; echo "the sniffer says: $browser" ; ?> I get undefined variable _server I've search here and php.net, I've looked through php.ini but not found anything I think might work Please help cheers sofa
×
×
  • 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.