Jump to content

caps1277

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

caps1277's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. <?php $dbhost = 'host'; $dbuser = 'user'; $dbpass = 'pw'; $con = mysql_connect($dbhost, $dbuser, $dbpass) or die("Error " . mysql_error()); $dbname = 'db189965288'; mysql_select_db($dbname,$con)or die("Error " . mysql_error()); ?> i made the database in the control panel of my website... someone told me i have to put: cpusername_databasename or something like that to get it to work.  tried that, didn't work either.
  2. entering that code, this is what i get: [color=blue]Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)[/color]
  3. hey guys, i've been working on a guestbook and i got it to work fully on my computer under the localhost address.  I have just tried to upload it to my site and have gotten some complications.  I have created a database on my webspace and also a table underneath it.  here is my code: include 'connect.php'; [code=php:0] if (isset($_POST["submit"])) { foreach ($_POST as $key => $value) { mysql_real_escape_string($value); } $name = $_POST["name"]; $country = $_POST["country"]; $email = $_POST["email"]; $im = $_POST["im"]; $comment = $_POST["comment"]; $addtodb = "insert into $dbname (name,country,email,im,comment) values ('$name','$country','$email','$im','$comment')"; if (mysql_query($addtodb,$con)) { header('Location: view.php'); } else { echo "Sorry we could not add your message"; } } [/code] for some reason, it doesn't add it to the db, all i get is the echo statement.  any ideas?
  4. hey guys, i need to make a guestbook for my page but have no clue where to start.  i don't want to use an open source code guestbook, i need to make it from scratch.  can you guys help me out please?!? thanks in advance, caps
  5. hey man, first off i want to say thanks for helping me out with this problem, it's really appreciated. i can't seem to get the code to work.  i know you said in a previous post that the it would work if the file was written "KY, Kentucky", i checked and the file is written "Kentucky, KY".  i tried flopping some of the code around to accomidate this, but it still doesn't work for some reason.  any suggestions?
  6. i have no problem inserting lines, just getting them to delete or modifying them.
  7. http://www.the-silvas.com/cmis310.html that is a hardcoded html file of what the php page looks like. this is the code for the state_form.php <form action="state_manager.php" method="POST"> NEW RECORD <table> <tr> <td> Abbr: <input type="text" name="abbr"> </td><td> State: <input type="text" name="state_name"> </td> <td> <input type="submit" name="insert_state" value="Insert"> </td> </tr> </table> </form> <?php $row = 1; $handle = fopen("states.csv", "r"); ?> <form action="state_manager.php" method="GET"> MODIFY RECORDS <table> <? while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { ?> <tr> <td> Abbr: <input type="text" name="abbr" value="<?=$data[1]?>" readonly="readonly"> </td><td> State: <input type="text" name="state_name" value="<?=$data[0]?>"> </td> <td> <input type="submit" onClick="return delete()" name="delete_state" value="Delete"> <input type="submit" name="modify_state" value="Save"> </td> </tr> <? } ?> when the user clicks the delete button, it should delete that row of the file. the teacher gave me this information, but i don't know how to do it. [quote]once the user clicks the DELETE button, your state_manager.php should look at the Abbreviation $_POST[$abbr] (or whatever that field is called)... Find that element on your associative array that holds all the elements of the state.csv file.... When you find it, delete that element from the array (research ways to delete items from an array) Then, write the contents of the array back into the state.csv file redirect user back to the state_form.php[/quote] im guessing that this way can be used for modifying the state also?  (that is when the user clicks the save button.)
  8. hey guys, im new to this forum and new to php and was hoping someone out there can help me out. what i need to do is be able to delete or modify a specific line from the .csv file when the person clicks the delete or modify button next to the state and abbreviation (which is on state_form.php, the code is on state_manager.php). i have some of the code, and as you can see, it deletes the first row of the .csv file no matter what delete button i push. $filename = "states.csv"; // File which holds all data $rowToDelete = 1; // This is line need to be deleted $arrFp = file( $filename ); // Open the data file as an array $numLines = count( $arrFp ); // Count the elements in the array $fp = fopen( $filename, "w" ); // Open the file for writing for($i=0; $i<$numLines; $i++) // Overwrite the content except the line to be deleted {     if($i != ($rowToDelete-1) )     fwrite($fp, $arrFp[$i]); } fclose( $fp ); // Close the file i have tried to modify this code to get it to come up with the specific line, but i can't seem to come up with something that works.  i hope you guys can help me out.  thanks
×
×
  • 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.